Example usage for java.util IdentityHashMap clone

List of usage examples for java.util IdentityHashMap clone

Introduction

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

Prototype

public Object clone() 

Source Link

Document

Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.

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);/* w  ww. j  av  a 2 s  .  c  o  m*/
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // clone the map
    IdentityHashMap ihmapclone = (IdentityHashMap) objMap.clone();

    System.out.println("Cloned map content: " + ihmapclone);

}

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

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

    hashMap.put(KEY_KEY, VALUE_VAL);//from   w w w. j a  va  2  s  .  c o  m

    IdentityHashMap copyMap = (IdentityHashMap) hashMap.clone();

    assertTrue(hashMap.equals(copyMap));
    hashMap.put(VALUE_VAL, KEY_KEY);
    assertFalse(hashMap.equals(copyMap));
}

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

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

    // Check empty clone behavior
    IdentityHashMap dstMap = (IdentityHashMap) srcMap.clone();
    assertNotNull(dstMap);/* ww  w  .  j a  va2  s . c o  m*/
    assertEquals(dstMap.size(), srcMap.size());
    // assertTrue(dstMap.values().toArray().equals(srcMap.values().toArray()));
    assertTrue(dstMap.keySet().equals(srcMap.keySet()));
    assertTrue(dstMap.entrySet().equals(srcMap.entrySet()));

    // Check non-empty clone behavior
    srcMap.put(KEY_1, VALUE_1);
    srcMap.put(KEY_2, VALUE_2);
    srcMap.put(KEY_3, VALUE_3);
    dstMap = (IdentityHashMap) srcMap.clone();
    assertNotNull(dstMap);
    assertEquals(dstMap.size(), srcMap.size());

    assertTrue(dstMap.keySet().equals(srcMap.keySet()));

    assertTrue(dstMap.entrySet().equals(srcMap.entrySet()));
}