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

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

源代码1 项目: gemfirexd-oss   文件: DataSerializer.java
/**
 * Writes a <code>IdentityHashMap</code> to a <code>DataOutput</code>.  Note
 * that even though <code>map</code> may be an instance of a
 * subclass of <code>IdentityHashMap</code>, <code>readIdentityHashMap</code> will
 * always return an instance of <code>IdentityHashMap</code>, <B>not</B> an
 * instance of the subclass.  To preserve the class type of
 * <code>map</code>, {@link #writeObject(Object, DataOutput)} should be used for data
 * serialization.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see #readIdentityHashMap
 */
public static void writeIdentityHashMap(IdentityHashMap<?,?> map, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  int size;
  if (map == null) {
    size = -1;
  } else {
    size = map.size();
  }
  InternalDataSerializer.writeArrayLength(size, out);
  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing IdentityHashMap with " + size + " elements: " + map);
  }
  if (size > 0) {
    for (Map.Entry<?,?> entry: map.entrySet()){
      writeObject(entry.getKey(), out);
      writeObject(entry.getValue(), out);
    }
  }
}
 
源代码2 项目: vespa   文件: SpanNode2AnnotationContainer.java
@Override
@SuppressWarnings("unchecked")
Iterator<Annotation> iteratorRecursive(SpanNode node) {
    IdentityHashMap<SpanNode, SpanNode> nodes = new IdentityHashMap<SpanNode, SpanNode>();
    nodes.put(node, node);
    {
        Iterator<SpanNode> childrenIt = node.childIteratorRecursive();
        while (childrenIt.hasNext()) {
            SpanNode child = childrenIt.next();
            nodes.put(child, child);
        }
    }
    List<Collection<Annotation>> annotationLists = new ArrayList<Collection<Annotation>>(nodes.size());
    for (SpanNode includedNode : nodes.keySet()) {
        Collection<Annotation> includedAnnotations = spanNode2Annotation.get(includedNode);
        if (includedAnnotations != null) {
            annotationLists.add(includedAnnotations);
        }
    }
    return new AnnotationCollectionIterator(annotationLists);
}
 
源代码3 项目: gemfirexd-oss   文件: DataSerializer.java
/**
 * Writes a <code>IdentityHashMap</code> to a <code>DataOutput</code>.  Note
 * that even though <code>map</code> may be an instance of a
 * subclass of <code>IdentityHashMap</code>, <code>readIdentityHashMap</code> will
 * always return an instance of <code>IdentityHashMap</code>, <B>not</B> an
 * instance of the subclass.  To preserve the class type of
 * <code>map</code>, {@link #writeObject(Object, DataOutput)} should be used for data
 * serialization.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see #readIdentityHashMap
 */
public static void writeIdentityHashMap(IdentityHashMap<?,?> map, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  int size;
  if (map == null) {
    size = -1;
  } else {
    size = map.size();
  }
  InternalDataSerializer.writeArrayLength(size, out);
  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing IdentityHashMap with " + size + " elements: " + map);
  }
  if (size > 0) {
    for (Map.Entry<?,?> entry: map.entrySet()){
      writeObject(entry.getKey(), out);
      writeObject(entry.getValue(), out);
    }
  }
}
 
源代码4 项目: grpc-nebula-java   文件: HealthServiceImpl.java
@VisibleForTesting
int numWatchersForTest(String service) {
  synchronized (watchLock) {
    IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean> serviceWatchers =
        watchers.get(service);
    if (serviceWatchers == null) {
      return 0;
    }
    return serviceWatchers.size();
  }
}
 
源代码5 项目: dragonwell8_jdk   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码6 项目: CrossMobile   文件: IdentityHashSet.java
@Override
@SuppressWarnings("unchecked")
public boolean retainAll(Collection<?> elements) {
    IdentityHashMap<E, Object> newMap = new IdentityHashMap<E, Object>();

    for (Object element : elements) {
        if (map.containsKey(element))
            newMap.put((E) element, null);
    }

    boolean anyChanges = newMap.size() != map.size();

    map = newMap;
    return anyChanges;
}
 
源代码7 项目: TencentKona-8   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码8 项目: jdk8u60   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码9 项目: openjdk-jdk8u   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码11 项目: openjdk-jdk9   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码12 项目: jdk8u-jdk   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码13 项目: hottub   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码14 项目: jdk8u_jdk   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码15 项目: jdk8u-jdk   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码16 项目: jdk8u-dev-jdk   文件: Capacity.java
/**
 * Given the expected size, computes such a number N of items that
 * inserting (N+1) items will trigger resizing of the internal storage
 */
static int threshold(int size) throws Throwable {
    IdentityHashMap<Object,Object> m = new IdentityHashMap<>(size);
    int initialCapacity = capacity(m);
    while (capacity(m) == initialCapacity)
        growUsingPut(m, 1);
    return m.size() - 1;
}
 
源代码17 项目: grpc-java   文件: HealthServiceImpl.java
@VisibleForTesting
int numWatchersForTest(String service) {
  synchronized (watchLock) {
    IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean> serviceWatchers =
        watchers.get(service);
    if (serviceWatchers == null) {
      return 0;
    }
    return serviceWatchers.size();
  }
}
 
源代码18 项目: openjdk-jdk9   文件: OptimalCapacity.java
/**
 * Checks adequacy of the expected maximum size of a static field
 * of type {@code IdentityHashMap}.
 *
 * Having
 * <pre>
 * class XClass {
 *     static IdentityHashMap theMap = new IdentityHashMap(M);
 * }
 * </pre>
 *
 * you should call from the test
 *
 * <pre>
 * OptimalCapacity.ofIdentityHashMap(XClass.class, "theMap", M);
 * </pre>
 */
public static void ofIdentityHashMap(Class<?> clazz, String fieldName,
        int expectedMaxSize)
{
    try {
        Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        Object obj = field.get(null);
        if (!IdentityHashMap.class.equals(obj.getClass())) {
            throw new RuntimeException("'" + field +
                "' expected to be of type IdentityHashMap");
        }
        IdentityHashMap<?,?> map = (IdentityHashMap<?,?>)obj;

        // Check that size of map is what was expected
        if (map.size() != expectedMaxSize) {
            throw new RuntimeException("Size of '" + field +
                "' is " + map.size() +
                ", which differs from expected " + expectedMaxSize);
        }

        // Check that the map allocated only necessary amount of memory
        IdentityHashMap<Object, Object> tmp = new IdentityHashMap<>(map);
        if (internalArraySize(map) != internalArraySize(tmp)) {
            throw new RuntimeException("Final capacity of '" + field +
                "' is " + internalArraySize(map) +
                ", which exceeds necessary minimum " + internalArraySize(tmp));
        }

        // Check that map was initially properly sized
        tmp = new IdentityHashMap<>(expectedMaxSize);
        tmp.put(new Object(), new Object()); // trigger storage init
        if (internalArraySize(map) != internalArraySize(tmp)) {
            throw new RuntimeException("Requested number of elements in '" + field +
                "' was " + expectedMaxSize +
                ", which resulted in final capacity " + internalArraySize(tmp) +
                ", which differs from necessary minimum " + internalArraySize(map));
        }
    } catch (ReflectiveOperationException roe) {
        throw new RuntimeException(roe);
    }
}
 
源代码19 项目: 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);
}
 
源代码20 项目: 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);
}