Java Code Examples for java.util.IdentityHashMap#keySet()

The following examples show how to use java.util.IdentityHashMap#keySet() . 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: ConstantExpressionIdentifier.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Get a list of expressions that mark boundaries into a constant space.
 * @param e
 * @return
 */
public static Set<LogicalExpression> getConstantExpressionSet(LogicalExpression e){
  IdentityHashMap<LogicalExpression, Object> map = new IdentityHashMap<>();
  ConstantExpressionIdentifier visitor = new ConstantExpressionIdentifier();


  if(e.accept(visitor, map) && map.isEmpty()){
    // if we receive a constant value here but the map is empty, this means the entire tree is a constant.
    // note, we can't use a singleton collection here because we need an identity set.
    map.put(e, true);
    return map.keySet();
  }else if(map.isEmpty()){
    // so we don't continue to carry around a map, we let it go here and simply return an empty set.
    return Collections.emptySet();
  }else{
    return map.keySet();
  }
}
 
Example 2
Source File: ConstantExpressionIdentifier.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Get a list of expressions that mark boundaries into a constant space.
 * @param e
 * @return
 */
public static Set<LogicalExpression> getConstantExpressionSet(LogicalExpression e){
  IdentityHashMap<LogicalExpression, Object> map = new IdentityHashMap<>();
  ConstantExpressionIdentifier visitor = new ConstantExpressionIdentifier();


  if(e.accept(visitor, map) && map.isEmpty()){
    // if we receive a constant value here but the map is empty, this means the entire tree is a constant.
    // note, we can't use a singleton collection here because we need an identity set.
    map.put(e, true);
    return map.keySet();
  }else if(map.isEmpty()){
    // so we don't continue to carry around a map, we let it go here and simply return an empty set.
    return Collections.emptySet();
  }else{
    return map.keySet();
  }
}
 
Example 3
Source File: SpanNode2AnnotationContainer.java    From vespa with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: SmaliClassDetailLoader.java    From PATDroid with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an apk file and extract all classes, methods, fields and optionally instructions
 */
public void loadAll(Scope scope) {
    IdentityHashMap<MethodInfo, MethodImplementation> collector = new IdentityHashMap<MethodInfo, MethodImplementation>();
    for (DexFile dexFile: dexFiles) {
        for (final ClassDef classDef : dexFile.getClasses()) {
            ClassInfo ci = Dalvik.findOrCreateClass(scope, classDef.getType());
            ClassDetail detail = translateClassDef(ci, classDef, collector);
            setDetail(ci, detail);
        }
    }
    if (translateInstructions) {
        for (MethodInfo mi: collector.keySet()) {
            final MethodImplementation impl = collector.get(mi);
            // Decode instructions
            if (impl != null) {
                new MethodImplementationTranslator(scope).translate(mi, impl);
            }
        }
    }
}
 
Example 5
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * java.util.IdentityHashMap#keySet()
 */
public void test_keySet_retainAll() {
    IdentityHashMap map = new IdentityHashMap();
    for (int i = 0; i < 1000; i++) {
        map.put(new Integer(i), new Integer(i));
    }
    Set set = map.keySet();

    // retain all the elements
    boolean result = set.retainAll(set);
    assertTrue("retain all should return false", !result);
    assertEquals("did not retain all", 1000, set.size());

    // send empty set to retainAll
    result = set.retainAll(new TreeSet());
    assertTrue("retain all should return true", result);
    assertEquals("did not remove all elements in the map", 0, map.size());
    assertTrue("did not remove all elements in the keyset", set.isEmpty());

    Iterator it = set.iterator();
    assertTrue("keySet iterator still has elements", !it.hasNext());
}
 
Example 6
Source File: HealthServiceImpl.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@GuardedBy("watchLock")
private void notifyWatchers(String service, @Nullable ServingStatus status) {
  HealthCheckResponse response = getResponseForWatch(status);
  IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean> serviceWatchers =
      watchers.get(service);
  if (serviceWatchers != null) {
    for (StreamObserver<HealthCheckResponse> responseObserver : serviceWatchers.keySet()) {
      responseObserver.onNext(response);
    }
  }
}
 
Example 7
Source File: SimTupleset.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a modifiable copy of the list of all i-th atom from all tuples in
 * some arbitrary order (0 is first atom, 1 is second atom...)
 *
 * @throws ErrorAPI if this tupleset contains at least one tuple whose length is
 *             less than or equal to i
 */
public List<SimAtom> getAllAtoms(int column) throws ErrorAPI {
    if (empty())
        return new ArrayList<SimAtom>(0);
    if (column < 0 || column >= arity())
        throw new ErrorAPI("This tupleset does not have an \"" + column + "th\" column.");
    IdentityHashMap<SimAtom,Boolean> ans = new IdentityHashMap<SimAtom,Boolean>();
    for (SimTuple x : this)
        ans.put(x.get(column), Boolean.TRUE);
    return new ArrayList<SimAtom>(ans.keySet());
}
 
Example 8
Source File: WireRepair.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
Collection<ArrayList<Wire>> getMergeSets() {
	IdentityHashMap<ArrayList<Wire>, Boolean> lists;
	lists = new IdentityHashMap<ArrayList<Wire>, Boolean>();
	for (ArrayList<Wire> list : map.values()) {
		lists.put(list, Boolean.TRUE);
	}
	return lists.keySet();
}
 
Example 9
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IdentityHashMap#clone()
 */
public void test_clone() {
    // Test for method java.lang.Object java.util.IdentityHashMap.clone()
    IdentityHashMap hm2 = (IdentityHashMap) hm.clone();
    assertTrue("Clone answered equivalent IdentityHashMap", hm2 != hm);
    for (int counter = 0; counter < hmSize; counter++)
        assertTrue("Clone answered unequal IdentityHashMap", hm
                .get(objArray2[counter]) == hm2.get(objArray2[counter]));

    IdentityHashMap map = new IdentityHashMap();
    map.put("key", "value");
    // get the keySet() and values() on the original Map
    Set keys = map.keySet();
    Collection values = map.values();
    assertEquals("values() does not work",
            "value", values.iterator().next());
    assertEquals("keySet() does not work",
            "key", keys.iterator().next());
    AbstractMap map2 = (AbstractMap) map.clone();
    map2.put("key", "value2");
    Collection values2 = map2.values();
    assertTrue("values() is identical", values2 != values);
    // values() and keySet() on the cloned() map should be different
    assertEquals("values() was not cloned",
            "value2", values2.iterator().next());
    map2.clear();
    map2.put("key2", "value3");
    Set key2 = map2.keySet();
    assertTrue("keySet() is identical", key2 != keys);
    assertEquals("keySet() was not cloned",
            "key2", key2.iterator().next());
}
 
Example 10
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IdentityHashMap#entrySet()
 * java.util.IdentityHashMap#keySet()
 * java.util.IdentityHashMap#values()
 */
public void test_sets() {
    // tests with null keys and values
    IdentityHashMap map = new IdentityHashMap();

    // null key and null value
    map.put("key", "value");
    map.put(null, null);
    map.put("a key", null);
    map.put("another key", null);

    Set keyset = map.keySet();
    Collection valueset = map.values();
    Set entries = map.entrySet();
    Iterator it = entries.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        assertTrue("EntrySetIterator can not find entry ", entries
                .contains(entry));

        assertTrue("entry key not found in map", map.containsKey(entry
                .getKey()));
        assertTrue("entry value not found in map", map.containsValue(entry
                .getValue()));

        assertTrue("entry key not found in the keyset", keyset
                .contains(entry.getKey()));
        assertTrue("entry value not found in the valueset", valueset
                .contains(entry.getValue()));
    }
}
 
Example 11
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IdentityHashMap#keySet()
 * java.util.IdentityHashMap#clear()
 */
public void test_keySet_clear() {
    IdentityHashMap map = new IdentityHashMap();
    for (int i = 0; i < 1000; i++) {
        map.put(new Integer(i), new Integer(i));
    }
    Set set = map.keySet();
    set.clear();

    assertEquals("did not remove all elements in the map", 0, map.size());
    assertTrue("did not remove all elements in the keyset", set.isEmpty());

    Iterator it = set.iterator();
    assertTrue("keySet iterator still has elements", !it.hasNext());
}
 
Example 12
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IdentityHashMap#keySet()
 * java.util.IdentityHashMap#remove(java.lang.Object)
 */
public void test_keySet_removeAll() {
    IdentityHashMap map = new IdentityHashMap();
    for (int i = 0; i < 1000; i++) {
        map.put(new Integer(i), new Integer(i));
    }
    Set set = map.keySet();
    set.removeAll(set);

    assertEquals("did not remove all elements in the map", 0, map.size());
    assertTrue("did not remove all elements in the keyset", set.isEmpty());

    Iterator it = set.iterator();
    assertTrue("keySet iterator still has elements", !it.hasNext());
}
 
Example 13
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IdentityHashMap#keySet()
 * java.util.IdentityHashMap#remove(java.lang.Object)
 */
public void test_keyset_remove() {
    IdentityHashMap map = new IdentityHashMap();

    Integer key = new Integer(21);

    map.put(new Integer(1), null);
    map.put(new Integer(11), null);
    map.put(key, null);
    map.put(new Integer(31), null);
    map.put(new Integer(41), null);
    map.put(new Integer(51), null);
    map.put(new Integer(61), null);
    map.put(new Integer(71), null);
    map.put(new Integer(81), null);
    map.put(new Integer(91), null);

    Set set = map.keySet();

    Set newset = new HashSet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Object element = it.next();
        if (element == key) {
            it.remove();
        } else
            newset.add(element);
    }
    int size = newset.size();
    assertTrue("keyset and newset don't have same size",
            newset.size() == size);
    assertTrue("element is in newset ", !newset.contains(key));
    assertTrue("element not removed from keyset", !set.contains(key));
    assertTrue("element not removed from map", !map.containsKey(key));

    assertTrue("newset and keyset do not have same elements 1", newset
            .equals(set));
    assertTrue("newset and keyset do not have same elements 2", set
            .equals(newset));
}
 
Example 14
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_spliterator_keySet() {
    IdentityHashMap<String, String> hashMap = new IdentityHashMap<>();
    hashMap.put("a", "1");
    hashMap.put("b", "2");
    hashMap.put("c", "3");
    hashMap.put("d", "4");
    hashMap.put("e", "5");
    hashMap.put("f", "6");
    hashMap.put("g", "7");
    hashMap.put("h", "8");
    hashMap.put("i", "9");
    hashMap.put("j", "10");
    hashMap.put("k", "11");
    hashMap.put("l", "12");
    hashMap.put("m", "13");
    hashMap.put("n", "14");
    hashMap.put("o", "15");
    hashMap.put("p", "16");

    Set<String> keys = hashMap.keySet();
    ArrayList<String> expectedKeys = new ArrayList<>(keys);

    SpliteratorTester.runBasicIterationTests(keys.spliterator(), expectedKeys);
    SpliteratorTester.runBasicSplitTests(keys, expectedKeys);
    SpliteratorTester.testSpliteratorNPE(keys.spliterator());
    SpliteratorTester.assertSupportsTrySplit(keys);
}
 
Example 15
Source File: HealthServiceImpl.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@GuardedBy("watchLock")
private void notifyWatchers(String service, @Nullable ServingStatus status) {
  HealthCheckResponse response = getResponseForWatch(status);
  IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean> serviceWatchers =
      watchers.get(service);
  if (serviceWatchers != null) {
    for (StreamObserver<HealthCheckResponse> responseObserver : serviceWatchers.keySet()) {
      responseObserver.onNext(response);
    }
  }
}