List of usage examples for java.util IdentityHashMap containsKey
public boolean containsKey(Object key)
From source file:Main.java
public static void main(String[] argv) throws Exception { IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>(); Object o1 = new Integer(123); Object o2 = new Integer(123); objMap.put(o1, "first"); objMap.put(o2, "from java2s.com"); Object v1 = objMap.get(o1);//w ww . j a va 2s . com System.out.println(v1); Object v2 = objMap.get(o2); System.out.println(v2); // check if key 3 exists boolean isavailable = objMap.containsKey(o1); System.out.println(isavailable); }
From source file:com.qrmedia.commons.persistence.hibernate.clone.wiring.AbstractPropertyModifyingCommand.java
public void execute(IdentityHashMap<Object, Object> entityClones) { if (!entityClones.containsKey(originalEntity)) { throw new AssertionError("No clone for " + originalEntity + " available?!"); }/*from w ww .ja va2 s . c om*/ wireUpProperty(target, propertyName, entityClones.get(originalEntity)); }
From source file:com.flipkart.flux.client.runtime.LocalContext.java
public String generateEventName(Event event) { final IdentityHashMap<Event, String> eventNamesMap = this.eventNames.get(); if (!eventNamesMap.containsKey(event)) { eventNamesMap.put(event, generateName(event)); }//from ww w . j av a 2s . c o m return eventNamesMap.get(event); }
From source file:com.parse.ParseTraverser.java
/** * Internal implementation of traverse./* w w w. j a va2s . c o m*/ */ private void traverseInternal(Object root, boolean yieldRoot, IdentityHashMap<Object, Object> seen) { if (root == null || seen.containsKey(root)) { return; } if (yieldRoot) { if (!visit(root)) { return; } } seen.put(root, root); if (root instanceof JSONObject) { JSONObject json = (JSONObject) root; Iterator<String> keys = json.keys(); while (keys.hasNext()) { String key = keys.next(); try { traverseInternal(json.get(key), true, seen); } catch (JSONException e) { // This should never happen. throw new RuntimeException(e); } } } else if (root instanceof JSONArray) { JSONArray array = (JSONArray) root; for (int i = 0; i < array.length(); ++i) { try { traverseInternal(array.get(i), true, seen); } catch (JSONException e) { // This should never happen. throw new RuntimeException(e); } } } else if (root instanceof Map) { Map<?, ?> map = (Map<?, ?>) root; for (Object value : map.values()) { traverseInternal(value, true, seen); } } else if (root instanceof List) { List<?> list = (List<?>) root; for (Object value : list) { traverseInternal(value, true, seen); } } else if (root instanceof ParseObject) { if (traverseParseObjects) { ParseObject object = (ParseObject) root; for (String key : object.keySet()) { traverseInternal(object.get(key), true, seen); } } } else if (root instanceof ParseACL) { ParseACL acl = (ParseACL) root; ParseUser user = acl.getUnresolvedUser(); if (user != null && user.isCurrentUser()) { traverseInternal(user, true, seen); } } }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
/** * Helper method that can clone an Attribute Value * * @param val the AttributeValue to copy * @param sourceDestinationMap used to avoid loops by keeping track of references * @return a copy of val//from w w w .ja va 2 s . c o m */ public static AttributeValue clone(AttributeValue val, IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) { if (val == null) { return null; } if (sourceDestinationMap.containsKey(val)) { return sourceDestinationMap.get(val); } AttributeValue clonedVal = new AttributeValue(); sourceDestinationMap.put(val, clonedVal); if (val.getN() != null) { clonedVal.setN(val.getN()); } else if (val.getS() != null) { clonedVal.setS(val.getS()); } else if (val.getB() != null) { clonedVal.setB(val.getB()); } else if (val.getNS() != null) { clonedVal.setNS(val.getNS()); } else if (val.getSS() != null) { clonedVal.setSS(val.getSS()); } else if (val.getBS() != null) { clonedVal.setBS(val.getBS()); } else if (val.getBOOL() != null) { clonedVal.setBOOL(val.getBOOL()); } else if (val.getNULL() != null) { clonedVal.setNULL(val.getNULL()); } else if (val.getL() != null) { List<AttributeValue> list = new ArrayList<>(val.getL().size()); for (AttributeValue listItemValue : val.getL()) { if (!sourceDestinationMap.containsKey(listItemValue)) { sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap)); } list.add(sourceDestinationMap.get(listItemValue)); } clonedVal.setL(list); } else if (val.getM() != null) { Map<String, AttributeValue> map = new HashMap<>(val.getM().size()); for (Entry<String, AttributeValue> pair : val.getM().entrySet()) { if (!sourceDestinationMap.containsKey(pair.getValue())) { sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap)); } map.put(pair.getKey(), sourceDestinationMap.get(pair.getValue())); } clonedVal.setM(map); } return clonedVal; }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
/** * Helper method that clones an item// w w w. j a v a 2s . c o m * * @param item the item to clone * @return a clone of item. */ public static Map<String, AttributeValue> cloneItem(Map<String, AttributeValue> item) { if (item == null) { return null; } Map<String, AttributeValue> clonedItem = Maps.newHashMap(); IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap = new IdentityHashMap<>(); for (Entry<String, AttributeValue> entry : item.entrySet()) { if (!sourceDestinationMap.containsKey(entry.getValue())) { sourceDestinationMap.put(entry.getValue(), clone(entry.getValue(), sourceDestinationMap)); } clonedItem.put(entry.getKey(), sourceDestinationMap.get(entry.getValue())); } return clonedItem; }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Gets the bean size.//from w w w .ja va2 s. c o m * * @param bean the bean * @param clazz the clazz * @param m the m * @param classNameMatcher the class name matcher * @param fieldNameMatcher the field name matcher * @return the bean size */ public static int getBeanSize(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m, Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) { if (m.containsKey(bean) == true) { return 0; } m.put(bean, null); return getBeanSizeIntern(bean, clazz, m, classNameMatcher, fieldNameMatcher); }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Gets the bean size.//from w w w .j a v a2 s . co m * * @param bean the bean * @param m the m * @param classNameMatcher the class name matcher * @param fieldNameMatcher the field name matcher * @return the bean size */ public static int getBeanSize(Object bean, IdentityHashMap<Object, Object> m, Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) { if (bean == null) { return 0; } if (m.containsKey(bean) == true) { return 0; } try { Class<?> clazz = bean.getClass(); return getBeanSize(bean, clazz, m, classNameMatcher, fieldNameMatcher); } catch (NoClassDefFoundError ex) { return 0; } }
From source file:net.datenwerke.sandbox.SandboxLoader.java
private SandboxLoader initSubLoader(IdentityHashMap<SandboxContext, SandboxLoader> loaderMap, SandboxContext context) {//from w ww . j a v a2 s.c o m if (loaderMap.containsKey(context)) return loaderMap.get(context); SandboxLoader subLoader = new SandboxLoader(this, securityManager); subLoader.init(context); loaderMap.put(context, subLoader); return subLoader; }
From source file:ome.services.util.ServiceHandler.java
/** * public for testing purposes.//from w w w . j av a 2 s .c o m */ public String getResultsString(Object o, IdentityHashMap<Object, String> cache) { if (o == null) { return "null"; } if (cache == null) { cache = new IdentityHashMap<Object, String>(); } else { if (cache.containsKey(o)) { return (String) cache.get(o); } } if (o instanceof Collection) { int count = 0; StringBuilder sb = new StringBuilder(128); sb.append("("); Collection c = (Collection) o; for (Object obj : (c)) { if (count > 0) { sb.append(", "); } if (count > 2) { sb.append("... "); sb.append(c.size() - 3); sb.append(" more"); break; } sb.append(obj); count++; } sb.append(")"); return sb.toString(); } else if (o instanceof Map) { Map map = (Map) o; int count = 0; StringBuilder sb = new StringBuilder(); sb.append("{"); for (Object k : map.keySet()) { if (count > 0) { sb.append(", "); } if (count > 2) { sb.append("... "); sb.append(map.size() - 3); sb.append(" more"); break; } sb.append(k); sb.append("="); cache.put(o, o.getClass().getName() + ":" + System.identityHashCode(o)); sb.append(getResultsString(map.get(k), cache)); count++; } sb.append("}"); return sb.toString(); } else if (o.getClass().isArray()) { int length = Array.getLength(o); if (length == 0) { return "[]"; } StringBuilder sb = new StringBuilder(128); sb.append("["); for (int i = 0; i < length; i++) { if (i != 0) { sb.append(", "); } if (i > 2) { sb.append("... "); sb.append(i - 2); sb.append(" more"); break; } sb.append(Array.get(o, i)); } sb.append("]"); return sb.toString(); } else { return o.toString(); } }