Example usage for java.util IdentityHashMap hashCode

List of usage examples for java.util IdentityHashMap hashCode

Introduction

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

Prototype

public int hashCode() 

Source Link

Document

Returns the hash code value for this map.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//from   w  ww  .java2  s .  c o  m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    System.out.println(objMap.hashCode());
}

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);// w  ww  .j a va  2 s  .  com
    int hashCode2 = hashMap.hashCode();

    assertTrue(hashCode1 != hashCode2);
}

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  a  v a  2s  .  c  o m*/
 */
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());
    }
}