Search in sources :

Example 6 with IdentityHashMap

use of java.util.IdentityHashMap in project dubbo by alibaba.

the class PojoUtils method createMap.

private static Map createMap(Map src) {
    Class<? extends Map> cl = src.getClass();
    Map result = null;
    if (HashMap.class == cl) {
        result = new HashMap();
    } else if (Hashtable.class == cl) {
        result = new Hashtable();
    } else if (IdentityHashMap.class == cl) {
        result = new IdentityHashMap();
    } else if (LinkedHashMap.class == cl) {
        result = new LinkedHashMap();
    } else if (Properties.class == cl) {
        result = new Properties();
    } else if (TreeMap.class == cl) {
        result = new TreeMap();
    } else if (WeakHashMap.class == cl) {
        return new WeakHashMap();
    } else if (ConcurrentHashMap.class == cl) {
        result = new ConcurrentHashMap();
    } else if (ConcurrentSkipListMap.class == cl) {
        result = new ConcurrentSkipListMap();
    } else {
        try {
            result = cl.newInstance();
        } catch (Exception e) {
        /* ignore */
        }
        if (result == null) {
            try {
                Constructor<?> constructor = cl.getConstructor(Map.class);
                result = (Map) constructor.newInstance(Collections.EMPTY_MAP);
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
    if (result == null) {
        result = new HashMap<Object, Object>();
    }
    return result;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) Properties(java.util.Properties) TreeMap(java.util.TreeMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) TreeMap(java.util.TreeMap) WeakHashMap(java.util.WeakHashMap)

Example 7 with IdentityHashMap

use of java.util.IdentityHashMap in project fastjson by alibaba.

the class ConcurrentHashMapDeserializerTest method test_className1.

@SuppressWarnings("rawtypes")
public void test_className1() throws Exception {
    IdentityHashMap map = (IdentityHashMap) JSON.parse("{\"@type\":\"java.util.IdentityHashMap\"}");
    Assert.assertEquals(0, map.size());
}
Also used : IdentityHashMap(java.util.IdentityHashMap)

Example 8 with IdentityHashMap

use of java.util.IdentityHashMap in project jsoup by jhy.

the class Selector method select.

/**
     * Find elements matching selector.
     *
     * @param query CSS selector
     * @param roots root elements to descend into
     * @return matching elements, empty if none
     */
public static Elements select(String query, Iterable<Element> roots) {
    Validate.notEmpty(query);
    Validate.notNull(roots);
    Evaluator evaluator = QueryParser.parse(query);
    ArrayList<Element> elements = new ArrayList<Element>();
    IdentityHashMap<Element, Boolean> seenElements = new IdentityHashMap<Element, Boolean>();
    for (Element root : roots) {
        final Elements found = select(evaluator, root);
        for (Element el : found) {
            if (!seenElements.containsKey(el)) {
                elements.add(el);
                seenElements.put(el, Boolean.TRUE);
            }
        }
    }
    return new Elements(elements);
}
Also used : Element(org.jsoup.nodes.Element) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList)

Example 9 with IdentityHashMap

use of java.util.IdentityHashMap in project rest.li by linkedin.

the class SimpleLoadBalancer method getRings.

@Override
public <K> MapKeyResult<Ring<URI>, K> getRings(URI serviceUri, Iterable<K> keys) throws ServiceUnavailableException {
    ServiceProperties service = listenToServiceAndCluster(serviceUri);
    String serviceName = service.getServiceName();
    String clusterName = service.getClusterName();
    ClusterProperties cluster = getClusterProperties(serviceName, clusterName);
    LoadBalancerStateItem<UriProperties> uriItem = getUriItem(serviceName, clusterName, cluster);
    UriProperties uris = uriItem.getProperty();
    List<LoadBalancerState.SchemeStrategyPair> orderedStrategies = _state.getStrategiesForService(serviceName, service.getPrioritizedSchemes());
    if (!orderedStrategies.isEmpty()) {
        LoadBalancerState.SchemeStrategyPair pair = orderedStrategies.get(0);
        PartitionAccessor accessor = getPartitionAccessor(serviceName, clusterName);
        // first distribute keys to partitions
        Map<Integer, Set<K>> partitionSet = new HashMap<Integer, Set<K>>();
        List<MapKeyResult.UnmappedKey<K>> unmappedKeys = new ArrayList<MapKeyResult.UnmappedKey<K>>();
        for (final K key : keys) {
            int partitionId;
            try {
                partitionId = accessor.getPartitionId(key.toString());
            } catch (PartitionAccessException e) {
                unmappedKeys.add(new MapKeyResult.UnmappedKey<K>(key, MapKeyResult.ErrorType.FAIL_TO_FIND_PARTITION));
                continue;
            }
            Set<K> set = partitionSet.get(partitionId);
            if (set == null) {
                set = new HashSet<K>();
                partitionSet.put(partitionId, set);
            }
            set.add(key);
        }
        // then we find the ring for each partition and create a map of Ring<URI> to Set<K>
        final Map<Ring<URI>, Collection<K>> ringMap = new IdentityHashMap<Ring<URI>, Collection<K>>(partitionSet.size() * 2);
        for (Map.Entry<Integer, Set<K>> entry : partitionSet.entrySet()) {
            int partitionId = entry.getKey();
            List<TrackerClient> clients = getPotentialClients(serviceName, service, uris, pair.getScheme(), partitionId);
            Ring<URI> ring = pair.getStrategy().getRing(uriItem.getVersion(), partitionId, clients);
            // make sure the same ring is not used in other partition
            Object oldValue = ringMap.put(ring, entry.getValue());
            assert (oldValue == null);
        }
        return new MapKeyResult<Ring<URI>, K>(ringMap, unmappedKeys);
    } else {
        throw new ServiceUnavailableException(serviceName, "Unable to find a load balancer strategy");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) URI(java.net.URI) LoadBalancerState(com.linkedin.d2.balancer.LoadBalancerState) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) MapKeyResult(com.linkedin.d2.balancer.util.MapKeyResult) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) PartitionAccessor(com.linkedin.d2.balancer.util.partitions.PartitionAccessor) Ring(com.linkedin.d2.balancer.util.hashing.Ring) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) Collection(java.util.Collection) PartitionAccessException(com.linkedin.d2.balancer.util.partitions.PartitionAccessException) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 10 with IdentityHashMap

use of java.util.IdentityHashMap in project rest.li by linkedin.

the class TemplateSpecGenerator method generateUnion.

private UnionTemplateSpec generateUnion(UnionDataSchema schema, UnionTemplateSpec unionClass) {
    final Map<CustomInfoSpec, Object> customInfoMap = new IdentityHashMap<CustomInfoSpec, Object>(schema.getTypes().size() * 2);
    for (DataSchema memberType : schema.getTypes()) {
        final UnionTemplateSpec.Member newMember = new UnionTemplateSpec.Member();
        unionClass.getMembers().add(newMember);
        newMember.setSchema(memberType);
        if (memberType.getDereferencedType() != DataSchema.Type.NULL) {
            newMember.setClassTemplateSpec(processSchema(memberType, unionClass, memberType.getUnionMemberKey()));
            newMember.setDataClass(determineDataClass(memberType, unionClass, memberType.getUnionMemberKey()));
            final CustomInfoSpec customInfo = getImmediateCustomInfo(memberType);
            if (customInfo != null) {
                if (!customInfoMap.containsKey(customInfo)) {
                    customInfoMap.put(customInfo, null);
                }
                newMember.setCustomInfo(customInfo);
            }
        }
    }
    return unionClass;
}
Also used : FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ComplexDataSchema(com.linkedin.data.schema.ComplexDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) CustomInfoSpec(com.linkedin.pegasus.generator.spec.CustomInfoSpec) IdentityHashMap(java.util.IdentityHashMap) UnionTemplateSpec(com.linkedin.pegasus.generator.spec.UnionTemplateSpec)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)131 Map (java.util.Map)43 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)19 LinkedHashMap (java.util.LinkedHashMap)17 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 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 Entry (java.util.Map.Entry)5