Search in sources :

Example 56 with IdentityHashMap

use of java.util.IdentityHashMap in project geode by apache.

the class InternalDataSerializer method initializeWellKnownSerializers.

private static void initializeWellKnownSerializers() {
    // ArrayBlockingQueue does not have zero-arg constructor
    // LinkedBlockingQueue does have zero-arg constructor but no way to get capacity
    classesToSerializers.put("java.lang.String", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            try {
                writeString((String) o, out);
            } catch (UTFDataFormatException ex) {
                // See bug 30428
                String s = "While writing a String of length " + ((String) o).length();
                UTFDataFormatException ex2 = new UTFDataFormatException(s);
                ex2.initCause(ex);
                throw ex2;
            }
            return true;
        }
    });
    classesToSerializers.put("java.net.InetAddress", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            InetAddress address = (InetAddress) o;
            out.writeByte(INET_ADDRESS);
            writeInetAddress(address, out);
            return true;
        }
    });
    classesToSerializers.put("java.net.Inet4Address", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            InetAddress address = (InetAddress) o;
            out.writeByte(INET_ADDRESS);
            writeInetAddress(address, out);
            return true;
        }
    });
    classesToSerializers.put("java.net.Inet6Address", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            InetAddress address = (InetAddress) o;
            out.writeByte(INET_ADDRESS);
            writeInetAddress(address, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Class", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Class c = (Class) o;
            if (c.isPrimitive()) {
                writePrimitiveClass(c, out);
            } else {
                out.writeByte(CLASS);
                writeClass(c, out);
            }
            return true;
        }
    });
    classesToSerializers.put("java.lang.Boolean", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Boolean value = (Boolean) o;
            out.writeByte(BOOLEAN);
            writeBoolean(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Character", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Character value = (Character) o;
            out.writeByte(CHARACTER);
            writeCharacter(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Byte", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Byte value = (Byte) o;
            out.writeByte(BYTE);
            writeByte(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Short", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Short value = (Short) o;
            out.writeByte(SHORT);
            writeShort(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Integer", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Integer value = (Integer) o;
            out.writeByte(INTEGER);
            writeInteger(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Long", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Long value = (Long) o;
            out.writeByte(LONG);
            writeLong(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Float", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Float value = (Float) o;
            out.writeByte(FLOAT);
            writeFloat(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Double", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Double value = (Double) o;
            out.writeByte(DOUBLE);
            writeDouble(value, out);
            return true;
        }
    });
    // boolean[]
    classesToSerializers.put(// boolean[]
    "[Z", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(BOOLEAN_ARRAY);
            writeBooleanArray((boolean[]) o, out);
            return true;
        }
    });
    // byte[]
    classesToSerializers.put(// byte[]
    "[B", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            byte[] array = (byte[]) o;
            out.writeByte(BYTE_ARRAY);
            writeByteArray(array, out);
            return true;
        }
    });
    // char[]
    classesToSerializers.put(// char[]
    "[C", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(CHAR_ARRAY);
            writeCharArray((char[]) o, out);
            return true;
        }
    });
    // double[]
    classesToSerializers.put(// double[]
    "[D", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            double[] array = (double[]) o;
            out.writeByte(DOUBLE_ARRAY);
            writeDoubleArray(array, out);
            return true;
        }
    });
    // float[]
    classesToSerializers.put(// float[]
    "[F", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            float[] array = (float[]) o;
            out.writeByte(FLOAT_ARRAY);
            writeFloatArray(array, out);
            return true;
        }
    });
    // int[]
    classesToSerializers.put(// int[]
    "[I", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            int[] array = (int[]) o;
            out.writeByte(INT_ARRAY);
            writeIntArray(array, out);
            return true;
        }
    });
    // long[]
    classesToSerializers.put(// long[]
    "[J", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            long[] array = (long[]) o;
            out.writeByte(LONG_ARRAY);
            writeLongArray(array, out);
            return true;
        }
    });
    // short[]
    classesToSerializers.put(// short[]
    "[S", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            short[] array = (short[]) o;
            out.writeByte(SHORT_ARRAY);
            writeShortArray(array, out);
            return true;
        }
    });
    // String[]
    classesToSerializers.put(// String[]
    "[Ljava.lang.String;", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            String[] array = (String[]) o;
            out.writeByte(STRING_ARRAY);
            writeStringArray(array, out);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.NANOSECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_NANOSECONDS);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.MICROSECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_MICROSECONDS);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.MILLISECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_MILLISECONDS);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.SECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_SECONDS);
            return true;
        }
    });
    classesToSerializers.put("java.util.Date", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Date date = (Date) o;
            out.writeByte(DATE);
            writeDate(date, out);
            return true;
        }
    });
    classesToSerializers.put("java.io.File", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            File file = (File) o;
            out.writeByte(FILE);
            writeFile(file, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.ArrayList", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            ArrayList list = (ArrayList) o;
            out.writeByte(ARRAY_LIST);
            writeArrayList(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.LinkedList", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            LinkedList list = (LinkedList) o;
            out.writeByte(LINKED_LIST);
            writeLinkedList(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Vector", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(VECTOR);
            writeVector((Vector) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Stack", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(STACK);
            writeStack((Stack) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.HashSet", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            HashSet list = (HashSet) o;
            out.writeByte(HASH_SET);
            writeHashSet(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.LinkedHashSet", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(LINKED_HASH_SET);
            writeLinkedHashSet((LinkedHashSet) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.HashMap", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            HashMap list = (HashMap) o;
            out.writeByte(HASH_MAP);
            writeHashMap(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.IdentityHashMap", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(IDENTITY_HASH_MAP);
            writeIdentityHashMap((IdentityHashMap) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Hashtable", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(HASH_TABLE);
            writeHashtable((Hashtable) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Properties", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Properties props = (Properties) o;
            out.writeByte(PROPERTIES);
            writeProperties(props, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.TreeMap", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TREE_MAP);
            writeTreeMap((TreeMap) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.TreeSet", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TREE_SET);
            writeTreeSet((TreeSet) o, out);
            return true;
        }
    });
    if (is662SerializationEnabled()) {
        classesToSerializers.put("java.math.BigInteger", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(BIG_INTEGER);
                writeBigInteger((BigInteger) o, out);
                return true;
            }
        });
        classesToSerializers.put("java.math.BigDecimal", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(BIG_DECIMAL);
                writeBigDecimal((BigDecimal) o, out);
                return true;
            }
        });
        classesToSerializers.put("java.util.UUID", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(UUID);
                writeUUID((UUID) o, out);
                return true;
            }
        });
        classesToSerializers.put("java.sql.Timestamp", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(TIMESTAMP);
                writeTimestamp((Timestamp) o, out);
                return true;
            }
        });
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataOutput(java.io.DataOutput) CopyOnWriteHashMap(org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) TreeSet(java.util.TreeSet) UUID(java.util.UUID) Vector(java.util.Vector) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) Hashtable(java.util.Hashtable) IOException(java.io.IOException) GemFireIOException(org.apache.geode.GemFireIOException) TreeMap(java.util.TreeMap) Date(java.util.Date) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal) Stack(java.util.Stack) BigInteger(java.math.BigInteger) UTFDataFormatException(java.io.UTFDataFormatException) BigInteger(java.math.BigInteger) ObjectStreamClass(java.io.ObjectStreamClass) InetAddress(java.net.InetAddress) File(java.io.File)

Example 57 with IdentityHashMap

use of java.util.IdentityHashMap in project geode by apache.

the class TXCommitMessage method send.

void send(TXLockId lockId) {
    if (isEmpty()) {
        if (logger.isDebugEnabled()) {
            logger.debug("empty transaction - nothing to distribute");
        }
        return;
    }
    Assert.assertTrue(this.txState != null, "Send must have transaction state.");
    this.lockId = (TXLockIdImpl) lockId;
    updateLockMembers();
    // Map of RegionCommitList keys to Sets of
    IdentityHashMap distMap = new IdentityHashMap();
    // receivers
    HashSet ackReceivers = null;
    {
        Iterator it = this.msgMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry me = (Map.Entry) it.next();
            RegionCommitList rcl = (RegionCommitList) me.getValue();
            if (rcl.getNeedsAck()) {
                if (ackReceivers == null) {
                    ackReceivers = new HashSet();
                }
                ackReceivers.add(me.getKey());
            }
            HashSet receivers = (HashSet) distMap.get(rcl);
            if (receivers == null) {
                receivers = new HashSet();
                distMap.put(rcl, receivers);
            }
            receivers.add(me.getKey());
        }
    }
    CommitReplyProcessor processor = null;
    {
        if (ackReceivers != null) {
            processor = new CommitReplyProcessor(this.dm, ackReceivers, msgMap);
            if (ackReceivers.size() > 1) {
                this.farSiders = ackReceivers;
            }
            processor.enableSevereAlertProcessing();
        }
        {
            Iterator it = distMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                RegionCommitList rcl = (RegionCommitList) me.getKey();
                HashSet recipients = (HashSet) me.getValue();
                // now remove from the recipients any guys that the dm no
                // longer knows about
                recipients.retainAll(this.dm.getDistributionManagerIds());
                if (!recipients.isEmpty()) {
                    if (this.txState.internalDuringIndividualSend != null) {
                        // Run in test mode, splitting out individaual recipients,
                        // so we can control who gets what
                        Iterator indivRecip = recipients.iterator();
                        while (indivRecip.hasNext()) {
                            this.txState.internalDuringIndividualSend.run();
                            setRecipientsSendData(Collections.singleton(indivRecip.next()), processor, rcl);
                        }
                    } else {
                        // Run in normal mode sending to mulitiple recipients in
                        // one shot
                        setRecipientsSendData(recipients, processor, rcl);
                    }
                }
            }
        }
        if (this.txState.internalAfterIndividualSend != null) {
            this.txState.internalAfterIndividualSend.run();
        }
    }
    if (processor != null) {
        // Send the CommitProcessMessage
        final CommitProcessMessage cpMsg;
        if (this.lockId != null) {
            cpMsg = new CommitProcessForLockIdMessage(this.lockId);
        } else {
            cpMsg = new CommitProcessForTXIdMessage(this.txIdent);
        }
        if (this.txState.internalDuringIndividualCommitProcess != null) {
            // Run in test mode
            Iterator<InternalDistributedMember> indivRecip = ackReceivers.iterator();
            while (indivRecip.hasNext()) {
                this.txState.internalDuringIndividualCommitProcess.run();
                cpMsg.setRecipients(Collections.<InternalDistributedMember>singleton(indivRecip.next()));
                this.dm.putOutgoing(cpMsg);
                cpMsg.resetRecipients();
            }
        } else {
            // Run in normal mode
            cpMsg.setRecipients(ackReceivers);
            this.dm.putOutgoing(cpMsg);
        }
        if (this.txState.internalAfterIndividualCommitProcess != null) {
            // Testing callback
            this.txState.internalAfterIndividualCommitProcess.run();
        }
        // for() loop removed for bug 36983 - you can't loop on waitForReplies()
        dm.getCancelCriterion().checkCancelInProgress(null);
        processor.waitForCommitCompletion();
        this.dm.getStats().incCommitWaits();
    }
    if (this.hasReliableRegions) {
        checkDistributionReliability(distMap, processor);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 58 with IdentityHashMap

use of java.util.IdentityHashMap in project geode by apache.

the class TXCommitMessage method checkDistributionReliability.

/**
   * Checks reliable regions and throws CommitDistributionException if any required roles may not
   * have received the commit message.
   *
   * @param distMap map of RegionCommitList keys to Sets of receivers
   * @param processor the reply processor
   * @throws CommitDistributionException if any required roles may not have received the commit
   *         message
   */
private void checkDistributionReliability(Map distMap, CommitReplyProcessor processor) {
    // key=RegionCommit, value=Set of recipients
    Map regionToRecipients = new IdentityHashMap();
    // build up the keys in regionToRecipients and add all receivers
    for (Iterator distIter = distMap.entrySet().iterator(); distIter.hasNext(); ) {
        Map.Entry me = (Map.Entry) distIter.next();
        RegionCommitList rcl = (RegionCommitList) me.getKey();
        Set recipients = (Set) me.getValue();
        for (Iterator rclIter = rcl.iterator(); rclIter.hasNext(); ) {
            RegionCommit rc = (RegionCommit) rclIter.next();
            // skip region if no required roles
            if (!rc.r.requiresReliabilityCheck()) {
                continue;
            }
            Set recipientsForRegion = (Set) regionToRecipients.get(rc);
            if (recipientsForRegion == null) {
                recipientsForRegion = new HashSet();
                regionToRecipients.put(rc, recipientsForRegion);
            }
            // get the receiver Set for rcl and perform addAll
            if (recipients != null) {
                recipientsForRegion.addAll(recipients);
            }
        }
    }
    Set cacheClosedMembers = (processor == null) ? Collections.emptySet() : processor.getCacheClosedMembers();
    Set departedMembers = (processor == null) ? Collections.emptySet() : processor.getDepartedMembers();
    // check reliability on each region
    Set regionDistributionExceptions = Collections.emptySet();
    Set failedRegionNames = Collections.emptySet();
    for (Iterator iter = regionToRecipients.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry me = (Map.Entry) iter.next();
        final RegionCommit rc = (RegionCommit) me.getKey();
        final Set successfulRecipients = new HashSet(msgMap.keySet());
        successfulRecipients.removeAll(departedMembers);
        // remove members who destroyed that region or closed their cache
        Set regionDestroyedMembers = (processor == null) ? Collections.emptySet() : processor.getRegionDestroyedMembers(rc.r.getFullPath());
        successfulRecipients.removeAll(cacheClosedMembers);
        successfulRecipients.removeAll(regionDestroyedMembers);
        try {
            rc.r.handleReliableDistribution(successfulRecipients);
        } catch (RegionDistributionException e) {
            if (regionDistributionExceptions == Collections.emptySet()) {
                regionDistributionExceptions = new HashSet();
                failedRegionNames = new HashSet();
            }
            regionDistributionExceptions.add(e);
            failedRegionNames.add(rc.r.getFullPath());
        }
    }
    if (!regionDistributionExceptions.isEmpty()) {
        throw new CommitDistributionException(LocalizedStrings.TXCommitMessage_THESE_REGIONS_EXPERIENCED_RELIABILITY_FAILURE_DURING_DISTRIBUTION_OF_THE_OPERATION_0.toLocalizedString(failedRegionNames), regionDistributionExceptions);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) Iterator(java.util.Iterator) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 59 with IdentityHashMap

use of java.util.IdentityHashMap in project geode by apache.

the class Buffers method acquireBuffer.

static ByteBuffer acquireBuffer(int size, DMStats stats, boolean send) {
    ByteBuffer result;
    if (TCPConduit.useDirectBuffers) {
        // keys are used like a
        IdentityHashMap<BBSoftReference, BBSoftReference> alreadySeen = null;
        // set
        BBSoftReference ref = (BBSoftReference) bufferQueue.poll();
        while (ref != null) {
            ByteBuffer bb = ref.getBB();
            if (bb == null) {
                // it was garbage collected
                int refSize = ref.consumeSize();
                if (refSize > 0) {
                    if (ref.getSend()) {
                        // fix bug 46773
                        stats.incSenderBufferSize(-refSize, true);
                    } else {
                        stats.incReceiverBufferSize(-refSize, true);
                    }
                }
            } else if (bb.capacity() >= size) {
                bb.rewind();
                bb.limit(size);
                return bb;
            } else {
                // wasn't big enough so put it back in the queue
                Assert.assertTrue(bufferQueue.offer(ref));
                if (alreadySeen == null) {
                    alreadySeen = new IdentityHashMap<BBSoftReference, BBSoftReference>();
                }
                if (alreadySeen.put(ref, ref) != null) {
                    // So it is time to give up and allocate a new buffer.
                    break;
                }
            }
            ref = (BBSoftReference) bufferQueue.poll();
        }
        result = ByteBuffer.allocateDirect(size);
    } else {
        // if we are using heap buffers then don't bother with keeping them around
        result = ByteBuffer.allocate(size);
    }
    if (send) {
        stats.incSenderBufferSize(size, TCPConduit.useDirectBuffers);
    } else {
        stats.incReceiverBufferSize(size, TCPConduit.useDirectBuffers);
    }
    return result;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ByteBuffer(java.nio.ByteBuffer)

Example 60 with IdentityHashMap

use of java.util.IdentityHashMap in project suite by stupidsing.

the class CompileGeneralizerImpl method generalizer.

@Override
public Generalize_ generalizer(Node node) {
    VariableMapper<Reference> mapper = cc.mapper();
    Generalizer generalizer = new Generalizer();
    Generalize_ generalize = cc.cloner(generalizer.generalize(node))::apply;
    Map<Reference, Atom> indices = new IdentityHashMap<>();
    for (Atom variableName : generalizer.getVariableNames()) indices.put(generalizer.getVariable(variableName), variableName);
    vm = mapper.mapKeys(indices::get);
    return generalize;
}
Also used : Generalizer(suite.lp.doer.Generalizer) Reference(suite.node.Reference) IdentityHashMap(java.util.IdentityHashMap) Atom(suite.node.Atom)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)142 Map (java.util.Map)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)18 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 List (java.util.List)11 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 IOException (java.io.IOException)6