java.util.IdentityHashMap#containsKey ( )源码实例Demo

下面列出了java.util.IdentityHashMap#containsKey ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: reladomo   文件: MappedOperation.java
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;
}
 
/**
 * 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;
}
 
源代码3 项目: baleen   文件: Selector.java
/**
 * 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);
}
 
源代码4 项目: jadira   文件: AbstractCloneStrategy.java
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);
			}
		}
	}
 
源代码5 项目: astor   文件: Selector.java
/**
 * 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);
}
 
源代码6 项目: astor   文件: Selector.java
/**
 * 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);
}
 
源代码7 项目: astor   文件: Selector.java
/**
 * 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);
}
 
源代码8 项目: XPagesExtensionLibrary   文件: ExtLibResources.java
@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);
}
 
源代码9 项目: dubbo-2.6.5   文件: JavaBeanSerializeUtil.java
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;
    }
}
 
源代码10 项目: netbeans   文件: FileEventLog.java
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);
}
 
源代码11 项目: dubbox-hystrix   文件: JavaBeanSerializeUtil.java
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;
    }
}
 
源代码12 项目: dubbo3   文件: JavaBeanSerializeUtil.java
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;
    }
}
 
源代码13 项目: K-Sonic   文件: ConcatenatingMediaSource.java
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;
}
 
源代码14 项目: dubbox   文件: JavaBeanSerializeUtil.java
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;
    }
}
 
源代码15 项目: dubbox   文件: JavaBeanSerializeUtil.java
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;
    }
}
 
源代码16 项目: WorldPainter   文件: MemoryUtils.java
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;
        }
    }
 
源代码17 项目: lucene-solr   文件: FacetProcessor.java
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);
}
 
源代码18 项目: lucene-solr   文件: StatsField.java
/**
 * 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);
}
 
/**
 * 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;
}
 
源代码20 项目: jadira   文件: UnsafeOperations.java
/**
 * 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;
}