Example usage for java.util IdentityHashMap put

List of usage examples for java.util IdentityHashMap put

Introduction

In this page you can find the example usage for java.util IdentityHashMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this identity hash map.

Usage

From source file:cdr.forms.FormController.java

private void scanDepositFile(DepositFile depositFile, IdentityHashMap<DepositFile, String> signatures) {
    if (depositFile != null && depositFile.getFile() != null) {
        ScanResult result = this.getClamScan().scan(depositFile.getFile());

        switch (result.getStatus()) {
        case PASSED:
            return;
        case FAILED:
            signatures.put(depositFile, result.getSignature());
            return;
        case ERROR:
            throw new Error("There was a problem running the virus scan.", result.getException());
        }/*from   www  .j a  va2  s. com*/
    }
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testContainsKey() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    assertFalse(hashMap.containsKey(KEY_TEST_CONTAINS_KEY));
    hashMap.put(KEY_TEST_CONTAINS_KEY, VALUE_TEST_CONTAINS_KEY);
    assertTrue(hashMap.containsKey(KEY_TEST_CONTAINS_KEY));
    assertFalse(hashMap.containsKey(VALUE_TEST_CONTAINS_DOES_NOT_EXIST));

    assertFalse(hashMap.containsKey(null));
    hashMap.put(null, VALUE_TEST_CONTAINS_KEY);
    assertTrue(hashMap.containsKey(null));
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

/**
 * Test that the implementation differs from a standard map in demanding
 * identity.//w  w w  . j  ava2  s  .  c  o  m
 */
public void testIdentity() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    Foo foo1 = new Foo();
    assertNull(hashMap.get(foo1));
    hashMap.put(foo1, VALUE_1);
    assertNotNull(hashMap.get(foo1));
    assertSame(VALUE_1, hashMap.get(foo1));

    Foo foo2 = new Foo();
    assertNull(hashMap.get(foo2));
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testIsEmpty() {
    IdentityHashMap srcMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(srcMap);

    IdentityHashMap dstMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(dstMap);

    dstMap.putAll(srcMap);/*ww w .  j av a2  s  .co  m*/
    assertTrue(dstMap.isEmpty());

    dstMap.put(KEY_KEY, VALUE_VAL);
    assertFalse(dstMap.isEmpty());

    dstMap.remove(KEY_KEY);
    assertTrue(dstMap.isEmpty());
    assertEquals(dstMap.size(), 0);
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testHashCode() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    // Check that hashCode changes
    int hashCode1 = hashMap.hashCode();
    hashMap.put(KEY_KEY, VALUE_VAL);
    int hashCode2 = hashMap.hashCode();

    assertTrue(hashCode1 != hashCode2);//ww w  .  ja va2  s  .  c om
}

From source file:org.carrot2.workbench.vis.FlashViewPage.java

/**
 * Create a mirror of a processing result with a smaller memory footprint
 * for visualizations./*from   w w  w . j a va 2  s .  c om*/
 */
private ProcessingResultMirror smallerMemFootprintMirror(ProcessingResult pr) {
    ProcessingResultMirror prm = new ProcessingResultMirror();
    prm.query = pr.getAttribute(AttributeNames.QUERY);
    prm.documents = Lists.newArrayList();
    IdentityHashMap<Document, Document> docMapping = Maps.newIdentityHashMap();
    for (Document doc : pr.getDocuments()) {
        String title = passData.contains(DocumentData.TITLE) ? doc.getTitle() : null;
        String snippet = passData.contains(DocumentData.SNIPPET) ? doc.getSummary() : null;
        Document docMirror = new Document(title, snippet, null, null, doc.getStringId());
        prm.documents.add(docMirror);
        docMapping.put(doc, docMirror);
    }
    prm.clusters = Lists.newArrayList();
    for (Cluster c : pr.getClusters()) {
        prm.clusters.add(mirrorOf(c, docMapping));
    }
    return prm;
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testContainsValue() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    assertFalse("check contains of empty map", hashMap.containsValue(VALUE_TEST_CONTAINS_KEY));
    hashMap.put(KEY_TEST_CONTAINS_VALUE, VALUE_TEST_CONTAINS_KEY);
    assertTrue("check contains of map with element", hashMap.containsValue(VALUE_TEST_CONTAINS_KEY));
    assertFalse("check contains of map other element",
            hashMap.containsValue(VALUE_TEST_CONTAINS_DOES_NOT_EXIST));

    if (useNullValue()) {
        assertFalse(hashMap.containsValue(null));
    }// w w w  . j av a 2  s .  co  m
    hashMap.put(KEY_TEST_CONTAINS_VALUE, null);
    assertTrue(hashMap.containsValue(null));
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

/**
 * Test method for 'java.util.IdentityHashMap.size()'.
 *//*from   ww w. j a v  a  2 s .c  o  m*/
public void testSize() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    // Test size behavior on put
    assertEquals(hashMap.size(), SIZE_ZERO);
    hashMap.put(KEY_1, VALUE_1);
    assertEquals(hashMap.size(), SIZE_ONE);
    hashMap.put(KEY_2, VALUE_2);
    assertEquals(hashMap.size(), SIZE_TWO);
    hashMap.put(KEY_3, VALUE_3);
    assertEquals(hashMap.size(), SIZE_THREE);

    // Test size behavior on remove
    hashMap.remove(KEY_1);
    assertEquals(hashMap.size(), SIZE_TWO);
    hashMap.remove(KEY_2);
    assertEquals(hashMap.size(), SIZE_ONE);
    hashMap.remove(KEY_3);
    assertEquals(hashMap.size(), SIZE_ZERO);

    // Test size behavior on putAll
    hashMap.put(KEY_1, VALUE_1);
    hashMap.put(KEY_2, VALUE_2);
    hashMap.put(KEY_3, VALUE_3);
    IdentityHashMap srcMap = new IdentityHashMap(hashMap);
    hashMap.putAll(srcMap);
    assertEquals(hashMap.size(), SIZE_THREE);

    // Test size behavior on clear
    hashMap.clear();
    assertEquals(hashMap.size(), SIZE_ZERO);
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

/**
 * Test that the implementation differs from a standard map in demanding
 * identity./*ww w. ja  v a 2  s  . c  o m*/
 */
public void testIdentityBasedEquality() {
    IdentityHashMap hashMap1 = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap1);

    IdentityHashMap hashMap2 = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap2);

    hashMap1.put(new Foo(), VALUE_1);
    hashMap2.put(new Foo(), VALUE_1);
    assertFalse(hashMap1.equals(hashMap2));
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

/**
 * Test that the implementation differs from a standard map in demanding
 * identity./*from w w w  . j  ava  2  s.  c om*/
 */
public void testIdentityBasedHashCode() {
    IdentityHashMap hashMap1 = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap1);

    IdentityHashMap hashMap2 = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap2);

    hashMap1.put(new Foo(), VALUE_1);
    hashMap2.put(new Foo(), VALUE_1);
    if (!TestUtils.isJvm()) {
        // Only reliable in Production Mode since Development Mode can have
        // identity hash collisions.
        assertFalse(hashMap1.hashCode() == hashMap2.hashCode());
    }
}