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;
}
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());
}
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);
}
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");
}
}
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;
}
Aggregations