Search in sources :

Example 86 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class IdentityHashMapTest method test_entrySet_removeAll.

/**
	 * @tests java.util.IdentityHashMap#entrySet()
	 * @tests java.util.IdentityHashMap#remove(java.lang.Object)
	 */
public void test_entrySet_removeAll() {
    IdentityHashMap map = new IdentityHashMap();
    for (int i = 0; i < 1000; i++) {
        map.put(new Integer(i), new Integer(i));
    }
    Set set = map.entrySet();
    set.removeAll(set);
    assertEquals("did not remove all elements in the map", 0, map.size());
    assertTrue("did not remove all elements in the entryset", set.isEmpty());
    Iterator it = set.iterator();
    assertTrue("entrySet iterator still has elements", !it.hasNext());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator)

Example 87 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class IdentityHashMapTest method test_null_Keys_and_Values.

/**
	 * @tests java.util.IdentityHashMap#containsKey(java.lang.Object)
	 * @tests java.util.IdentityHashMap#containsValue(java.lang.Object)
	 * @tests java.util.IdentityHashMap#put(java.lang.Object, java.lang.Object)
	 * @tests java.util.IdentityHashMap#get(java.lang.Object)
	 */
public void test_null_Keys_and_Values() {
    // tests with null keys and values
    IdentityHashMap map = new IdentityHashMap();
    Object result;
    // null key and null value
    result = map.put(null, null);
    assertTrue("testA can not find null key", map.containsKey(null));
    assertTrue("testA can not find null value", map.containsValue(null));
    assertNull("testA can not get null value for null key", map.get(null));
    assertNull("testA put returned wrong value", result);
    // null value
    String value = "a value";
    result = map.put(null, value);
    assertTrue("testB can not find null key", map.containsKey(null));
    assertTrue("testB can not find a value with null key", map.containsValue(value));
    assertTrue("testB can not get value for null key", map.get(null) == value);
    assertNull("testB put returned wrong value", result);
    // a null key
    String key = "a key";
    result = map.put(key, null);
    assertTrue("testC can not find a key with null value", map.containsKey(key));
    assertTrue("testC can not find null value", map.containsValue(null));
    assertNull("testC can not get null value for key", map.get(key));
    assertNull("testC put returned wrong value", result);
    // another null key
    String anothervalue = "another value";
    result = map.put(null, anothervalue);
    assertTrue("testD can not find null key", map.containsKey(null));
    assertTrue("testD can not find a value with null key", map.containsValue(anothervalue));
    assertTrue("testD can not get value for null key", map.get(null) == anothervalue);
    assertTrue("testD put returned wrong value", result == value);
    // remove a null key
    result = map.remove(null);
    assertTrue("testE remove returned wrong value", result == anothervalue);
    assertTrue("testE should not find null key", !map.containsKey(null));
    assertTrue("testE should not find a value with null key", !map.containsValue(anothervalue));
    assertNull("testE should not get value for null key", map.get(null));
}
Also used : IdentityHashMap(java.util.IdentityHashMap)

Example 88 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class IdentityHashMapTest method test_sets.

/**
	 * @tests java.util.IdentityHashMap#entrySet()
	 * @tests java.util.IdentityHashMap#keySet()
	 * @tests 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()));
    }
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator) Collection(java.util.Collection) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 89 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class AbstractMapTest method test_keySet.

/**
     * java.util.AbstractMap#keySet()
     */
public void test_keySet() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.keySet(), map1.keySet());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.keySet(), map2.keySet());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.keySet(), map6.keySet());
    AbstractMap map7 = new WeakHashMap();
    assertSame("WeakHashMap", map7.keySet(), map7.keySet());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Example 90 with IdentityHashMap

use of java.util.IdentityHashMap in project randomizedtesting by randomizedtesting.

the class TextReport method emitBufferedEvents.

private void emitBufferedEvents(AggregatedSuiteResultEvent e) throws IOException {
    final IdentityHashMap<TestFinishedEvent, AggregatedTestResultEvent> eventMap = new IdentityHashMap<>();
    for (AggregatedTestResultEvent tre : e.getTests()) {
        eventMap.put(tre.getTestFinishedEvent(), tre);
    }
    final boolean emitOutput = (outputMode != OutputMode.NEVER) && ((outputMode == OutputMode.ALWAYS && !isPassthrough()) || (outputMode == OutputMode.ONERROR && !e.isSuccessful()));
    for (IEvent event : e.getEventStream()) {
        switch(event.getType()) {
            case APPEND_STDOUT:
                if (emitOutput)
                    ((IStreamEvent) event).copyTo(outStream);
                break;
            case APPEND_STDERR:
                if (emitOutput)
                    ((IStreamEvent) event).copyTo(errStream);
                break;
            case TEST_FINISHED:
                assert eventMap.containsKey(event);
                final AggregatedTestResultEvent aggregated = eventMap.get(event);
                if (displayStatus.get(aggregated.getStatus())) {
                    flushOutput();
                    emitStatusLine(aggregated, aggregated.getStatus(), aggregated.getExecutionTime());
                }
            default:
                break;
        }
    }
    if (emitOutput) {
        flushOutput();
    }
}
Also used : AggregatedTestResultEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent) IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) TestFinishedEvent(com.carrotsearch.ant.tasks.junit4.events.TestFinishedEvent) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)142 Map (java.util.Map)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)18 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 List (java.util.List)11 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 IOException (java.io.IOException)6