Java Code Examples for java.util.IdentityHashMap#containsKey()
The following examples show how to use
java.util.IdentityHashMap#containsKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtLibResources.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") // $NON-NLS-1$ public static void addEncodeResource(UIViewRootEx rootEx, Resource resource) { if(ExtLibUtil.isXPages852()) { // The XPages runtime add all the resources and does a check when it starts to // generate all the resources at the very end. // For performance reasons, and until the XPages runtime optimizes this, we ensure // that the same resource (the exact same object - identity comparison) is not // added multiple times. // Already optimized in post 852 IdentityHashMap<Resource, Boolean> m = (IdentityHashMap<Resource, Boolean>)rootEx.getEncodeProperty("extlib.EncodeResource"); // $NON-NLS-1$ if(m==null) { m = new IdentityHashMap<Resource, Boolean>(); } else { if(m.containsKey(resource)) { return; } } m.put(resource, Boolean.TRUE); } rootEx.addEncodeResource(resource); }
Example 2
Source File: Selector.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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<>(); IdentityHashMap<Element, Boolean> seenElements = new IdentityHashMap<>(); // dedupe elements by identity, not equality 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); }
Example 3
Source File: Selector.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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<>(); IdentityHashMap<Element, Boolean> seenElements = new IdentityHashMap<>(); // dedupe elements by identity, not equality 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); }
Example 4
Source File: MappedOperation.java From reladomo with Apache License 2.0 | 6 votes |
public static List intersectLists(List list, List mappedList) { if (list.size() > mappedList.size()) { List temp = list; list = mappedList; mappedList = temp; } IdentityHashMap map = new IdentityHashMap(list.size() * 2); for (int i = 0; i < list.size(); i++) { map.put(list.get(i), DUMMY); } MithraFastList result = new MithraFastList(list.size()); for (int i = 0; i < mappedList.size(); i++) { Object key = mappedList.get(i); if (map.containsKey(key)) { result.add(key); } } return result; }
Example 5
Source File: Selector.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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>(); // dedupe elements by identity, not equality 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); }
Example 6
Source File: AbstractCloneStrategy.java From jadira with Apache License 2.0 | 6 votes |
private void doInitialiseFor(Class<?> clazz, IdentityHashMap<Class<?>, Boolean> seenClasses) { getClassModel(clazz); seenClasses.put(clazz, Boolean.TRUE); Field[] fields = ClassUtils.collectInstanceFields(clazz); for (Field f : fields) { Class<?> type = f.getType(); if (seenClasses.containsKey(type)) { continue; } if (type.isPrimitive()) { continue; } else if (type.isArray() && !(type.getComponentType().isPrimitive())) { doInitialiseFor(type.getComponentType(), seenClasses); seenClasses.put(type.getComponentType(), Boolean.TRUE); } else if (!type.isArray() && !type.isPrimitive() && !type.isEnum() && !type.isInterface() && !ClassUtils.isWrapper(type) && !ClassUtils.isJdkImmutable(type)) { doInitialiseFor(type, seenClasses); seenClasses.put(type, Boolean.TRUE); } } }
Example 7
Source File: Selector.java From baleen with Apache License 2.0 | 6 votes |
/** * Find nodes matching selector. * * @param query CSS selector * @param roots root nodes to descend into * @return matching nodes, empty if none */ public static <T> Nodes<T> select(String query, Iterable<Node<T>> roots) { Validate.notEmpty(query); Validate.notNull(roots); Evaluator<T> evaluator = QueryParser.parse(query); ArrayList<Node<T>> nodes = new ArrayList<>(); IdentityHashMap<Node<T>, Boolean> seenNodes = new IdentityHashMap<>(); // dedupe nodes by identity, not equality for (Node<T> root : roots) { final Nodes<T> found = select(evaluator, root); for (Node<T> el : found) { if (!seenNodes.containsKey(el)) { nodes.add(el); seenNodes.put(el, Boolean.TRUE); } } } return new Nodes<>(nodes); }
Example 8
Source File: DynamoDbDelegate.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
/** * Helper method that clones an item * * @param item the item to clone * @return a clone of item. */ public static Map<String, AttributeValue> cloneItem(final Map<String, AttributeValue> item) { if (item == null) { return null; } final Map<String, AttributeValue> clonedItem = Maps.newHashMap(); final 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; }
Example 9
Source File: FileEventLog.java From netbeans with Apache License 2.0 | 5 votes |
private void commit () { final List<Work> first = new LinkedList<Work>(); final List<Work> rest = new LinkedList<Work>(); final IdentityHashMap<Work,Work> seenDelete = new IdentityHashMap<Work, Work>(); final Map<URL,Map<String,Pair<FileEventLog.FileOp,Work>>> myChanges = getChanges(false); if (myChanges != null) { for (Map<String,Pair<FileOp,Work>> changesInRoot : myChanges.values()) { for (Pair<FileOp,Work> desc : changesInRoot.values()) { if (desc.first() == FileOp.DELETE) { if (!seenDelete.containsKey(desc.second())) { first.add(desc.second()); seenDelete.put(desc.second(), desc.second()); } } else { rest.add(desc.second()); } } } } final RepositoryUpdater ru = RepositoryUpdater.getDefault(); if (LOG.isLoggable(Level.FINER)) { LOG.finer("SCHEDULING: " + first); //NOI18N } ru.scheduleWork(first); if (LOG.isLoggable(Level.FINER)) { LOG.finer("SCHEDULING: " + rest); //NOI18N } ru.scheduleWork(rest); }
Example 10
Source File: JavaBeanSerializeUtil.java From dubbox with Apache License 2.0 | 5 votes |
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) { if (cache.containsKey(obj)) { return cache.get(obj); } else if (obj instanceof JavaBeanDescriptor) { return (JavaBeanDescriptor)obj; } else { JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass()); cache.put(obj, result); serializeInternal(result, obj, accessor, cache); return result; } }
Example 11
Source File: JavaBeanSerializeUtil.java From dubbox with Apache License 2.0 | 5 votes |
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) { if (cache.containsKey(obj)) { return cache.get(obj); } else if (obj instanceof JavaBeanDescriptor) { return (JavaBeanDescriptor)obj; } else { JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass()); cache.put(obj, result); serializeInternal(result, obj, accessor, cache); return result; } }
Example 12
Source File: ConcatenatingMediaSource.java From K-Sonic with MIT License | 5 votes |
private static boolean[] buildDuplicateFlags(MediaSource[] mediaSources) { boolean[] duplicateFlags = new boolean[mediaSources.length]; IdentityHashMap<MediaSource, Void> sources = new IdentityHashMap<>(mediaSources.length); for (int i = 0; i < mediaSources.length; i++) { MediaSource source = mediaSources[i]; if (!sources.containsKey(source)) { sources.put(source, null); } else { duplicateFlags[i] = true; } } return duplicateFlags; }
Example 13
Source File: JavaBeanSerializeUtil.java From dubbo3 with Apache License 2.0 | 5 votes |
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) { if (cache.containsKey(obj)) { return cache.get(obj); } else if (obj instanceof JavaBeanDescriptor) { return (JavaBeanDescriptor) obj; } else { JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass()); cache.put(obj, result); serializeInternal(result, obj, accessor, cache); return result; } }
Example 14
Source File: JavaBeanSerializeUtil.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) { if (cache.containsKey(obj)) { return cache.get(obj); } else if (obj instanceof JavaBeanDescriptor) { return (JavaBeanDescriptor)obj; } else { JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass()); cache.put(obj, result); serializeInternal(result, obj, accessor, cache); return result; } }
Example 15
Source File: JavaBeanSerializeUtil.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) { if (cache.containsKey(obj)) { return cache.get(obj); } else if (obj instanceof JavaBeanDescriptor) { return (JavaBeanDescriptor) obj; } else { JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass()); cache.put(obj, result); serializeInternal(result, obj, accessor, cache); return result; } }
Example 16
Source File: DynamoDbDelegate.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 4 votes |
/** * 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 */ public static AttributeValue clone(final AttributeValue val, final IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) { if (val == null) { return null; } if (sourceDestinationMap.containsKey(val)) { return sourceDestinationMap.get(val); } final 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) { final 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) { final 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; }
Example 17
Source File: StatsField.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Computes a base {@link DocSet} for the current request to be used * when computing global stats for the local index. * * This is typically the same as the main DocSet for the {@link ResponseBuilder} * unless {@link CommonParams#TAG tag}ged filter queries have been excluded using * the {@link CommonParams#EXCLUDE ex} local param */ public DocSet computeBaseDocSet() throws IOException { DocSet docs = rb.getResults().docSet; Map<?,?> tagMap = (Map<?,?>) rb.req.getContext().get("tags"); if (excludeTagList.isEmpty() || null == tagMap) { // either the exclude list is empty, or there // aren't any tagged filters to exclude anyway. return docs; } IdentityHashMap<Query,Boolean> excludeSet = new IdentityHashMap<Query,Boolean>(); for (String excludeTag : excludeTagList) { Object olst = tagMap.get(excludeTag); // tagMap has entries of List<String,List<QParser>>, but subject to change in the future if (!(olst instanceof Collection)) continue; for (Object o : (Collection<?>)olst) { if (!(o instanceof QParser)) continue; QParser qp = (QParser)o; try { excludeSet.put(qp.getQuery(), Boolean.TRUE); } catch (SyntaxError e) { // this shouldn't be possible since the request should have already // failed when attempting to execute the query, but just in case... throw new SolrException(ErrorCode.BAD_REQUEST, "Excluded query can't be parsed: " + originalParam + " due to: " + e.getMessage(), e); } } } if (excludeSet.size() == 0) return docs; List<Query> qlist = new ArrayList<Query>(); // add the base query if (!excludeSet.containsKey(rb.getQuery())) { qlist.add(rb.getQuery()); } // add the filters if (rb.getFilters() != null) { for (Query q : rb.getFilters()) { if (!excludeSet.containsKey(q)) { qlist.add(q); } } } // get the new base docset for this facet return searcher.getDocSet(qlist); }
Example 18
Source File: FacetProcessor.java From lucene-solr with Apache License 2.0 | 4 votes |
private void handleFilterExclusions() throws IOException { List<String> excludeTags = freq.domain.excludeTags; if (excludeTags == null || excludeTags.size() == 0) { return; } @SuppressWarnings({"rawtypes"}) Map tagMap = (Map) fcontext.req.getContext().get("tags"); if (tagMap == null) { // no filters were tagged return; } IdentityHashMap<Query,Boolean> excludeSet = new IdentityHashMap<>(); for (String excludeTag : excludeTags) { Object olst = tagMap.get(excludeTag); // tagMap has entries of List<String,List<QParser>>, but subject to change in the future if (!(olst instanceof Collection)) continue; for (Object o : (Collection<?>)olst) { if (!(o instanceof QParser)) continue; QParser qp = (QParser)o; try { excludeSet.put(qp.getQuery(), Boolean.TRUE); } catch (SyntaxError syntaxError) { // This should not happen since we should only be retrieving a previously parsed query throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, syntaxError); } } } if (excludeSet.size() == 0) return; List<Query> qlist = new ArrayList<>(); // TODO: somehow remove responsebuilder dependency ResponseBuilder rb = SolrRequestInfo.getRequestInfo().getResponseBuilder(); // add the base query if (!excludeSet.containsKey(rb.getQuery())) { qlist.add(rb.getQuery()); } // add the filters if (rb.getFilters() != null) { for (Query q : rb.getFilters()) { if (!excludeSet.containsKey(q)) { qlist.add(q); } } } // now walk back up the context tree // TODO: we lose parent exclusions... for (FacetContext curr = fcontext; curr != null; curr = curr.parent) { if (curr.filter != null) { qlist.add( curr.filter ); } } // recompute the base domain fcontext.base = fcontext.searcher.getDocSet(qlist); }
Example 19
Source File: MemoryUtils.java From WorldPainter with GNU General Public License v3.0 | 4 votes |
private static int getSize(Object object, IdentityHashMap<Object, Void> processedObjects, Set<Class<?>> stopAt/*, String trail*/) { if (processedObjects.containsKey(object)) { // This object has already been counted return 0; } else { // Record that this object has been counted processedObjects.put(object, null); Class<?> type = object.getClass(); if ((stopAt != null) && (! stopAt.isEmpty())) { for (Class<?> stopClass: stopAt) { if (stopClass.isAssignableFrom(type)) { return 0; } } } int objectSize = 8; // Housekeeping if (type.isArray()) { objectSize += 4; // Array length Class<?> arrayType = type.getComponentType(); if (arrayType.isPrimitive()) { if (arrayType == boolean.class) { objectSize += ((boolean[]) object).length; } else if (arrayType == byte.class) { objectSize += ((byte[]) object).length; } else if (arrayType == char.class) { objectSize += ((char[]) object).length * 2; } else if (arrayType == short.class) { objectSize += ((short[]) object).length * 2; } else if (arrayType == int.class) { objectSize += ((int[]) object).length * 4; } else if (arrayType == float.class) { objectSize += ((float[]) object).length * 4; } else if (arrayType == long.class) { objectSize += ((long[]) object).length * 8; } else { objectSize += ((double[]) object).length * 8; } } else { Object[] array = (Object[]) object; objectSize = array.length * 4; // References for (Object anArray : array) { if (anArray != null) { objectSize += getSize(anArray, processedObjects, stopAt/*, trail + '[' + i + ']'*/); } } } } else if (type.isPrimitive()) { objectSize += PRIMITIVE_TYPE_SIZES.get(type); } else { Class<?> myType = type; while (myType != null) { Field[] fields = myType.getDeclaredFields(); for (Field field: fields) { if (Modifier.isStatic(field.getModifiers())) { continue; } Class<?> fieldType = field.getType(); if (fieldType.isPrimitive()) { objectSize += PRIMITIVE_TYPE_SIZES.get(fieldType); } else { objectSize += 4; // Reference field.setAccessible(true); // Will fail if a security manager is installed! try { Object value = field.get(object); if (value != null) { objectSize += getSize(value, processedObjects, stopAt/*, trail + '.' + field.getName()*/); } } catch (IllegalAccessException e) { throw new MDCCapturingRuntimeException("Access denied trying to read field " + field.getName() + " of type " + myType.getName(), e); } } } myType = myType.getSuperclass(); } } if ((objectSize % 8) != 0) { objectSize = ((objectSize >> 3) + 1) << 3; } // System.out.println(trail + " (" + type.getSimpleName() + "): " + objectSize); return objectSize; } }
Example 20
Source File: UnsafeOperations.java From jadira with Apache License 2.0 | 4 votes |
/** * Performs a deep copy of the array. With a deep copy all references from the array are also copied. * The identity of referenced objects is preserved, so, for example, if the object graph contains two * references to the same object, the cloned object will preserve this structure. * @param arrayOriginal The array to perform a deep copy for. * @param visited An identity map of references to reuse - this is further populated as the copy progresses. * The key is the original object reference - the value is the copied instance for that original. * @return A deep copy of the original array. */ public final Object deepCopyArray(Object arrayOriginal, IdentityHashMap<Object, Object> visited) { if (visited.containsKey(arrayOriginal)) { return visited.get(arrayOriginal); } final Class<?> componentType = arrayOriginal.getClass().getComponentType(); Object result = null; if (componentType.isPrimitive()) { if (java.lang.Boolean.TYPE == componentType) { result = Arrays.copyOf((boolean[]) arrayOriginal, ((boolean[]) arrayOriginal).length); } else if (java.lang.Byte.TYPE == componentType) { result = Arrays.copyOf((byte[]) arrayOriginal, ((byte[]) arrayOriginal).length); } else if (java.lang.Character.TYPE == componentType) { result = Arrays.copyOf((char[]) arrayOriginal, ((char[]) arrayOriginal).length); } else if (java.lang.Short.TYPE == componentType) { result = Arrays.copyOf((short[]) arrayOriginal, ((short[]) arrayOriginal).length); } else if (java.lang.Integer.TYPE == componentType) { result = Arrays.copyOf((int[]) arrayOriginal, ((int[]) arrayOriginal).length); } else if (java.lang.Long.TYPE == componentType) { result = Arrays.copyOf((long[]) arrayOriginal, ((long[]) arrayOriginal).length); } else if (java.lang.Float.TYPE == componentType) { result = Arrays.copyOf((float[]) arrayOriginal, ((float[]) arrayOriginal).length); } else if (java.lang.Double.TYPE == componentType) { result = Arrays.copyOf((double[]) arrayOriginal, ((double[]) arrayOriginal).length); } } if (result == null) { Object[] arrayCopy = Arrays.copyOf((Object[]) arrayOriginal, ((Object[]) arrayOriginal).length); if (arrayCopy.length > 0) { if (componentType.isArray()) { for (int i = 0; i < arrayCopy.length; i++) { arrayCopy[i] = deepCopyArray(arrayCopy[i], visited); } } else { for (int i = 0; i < arrayCopy.length; i++) { Object component = deepCopy(arrayCopy[i], visited); arrayCopy[i] = component; } } } result = arrayCopy; } visited.put(arrayOriginal, result); return result; }