Code example for IdentityHashMap

Methods: equalsput

0
 
    /** 
     * java.util.IdentityHashMap#equals(java.lang.Object) 
     */ 
    public void test_equalsLjava_lang_Object() { 
        IdentityHashMap mapOne = new IdentityHashMap();
        IdentityHashMap mapTwo = new IdentityHashMap();
        IdentityHashMap mapThree = new IdentityHashMap();
        IdentityHashMap mapFour = new IdentityHashMap();
 
        String one = "one";
        String alsoOne = new String(one); // use the new operator to ensure a
        // new reference is constructed 
        String two = "two";
        String alsoTwo = new String(two); // use the new operator to ensure a
        // new reference is constructed 
 
        mapOne.put(one, two);
        mapFour.put(one, two);
 
        // these two are not equal to the above two 
        mapTwo.put(alsoOne, two);
        mapThree.put(one, alsoTwo);
 
        assertEquals("failure of equality of IdentityHashMaps", mapOne, mapFour);
        assertTrue("failure of non-equality of IdentityHashMaps one and two",
                !mapOne.equals(mapTwo));
        assertTrue("failure of non-equality of IdentityHashMaps one and three",
                !mapOne.equals(mapThree));
        assertTrue("failure of non-equality of IdentityHashMaps two and three",
                !mapTwo.equals(mapThree));
 
        HashMap hashMapTwo = new HashMap();
        HashMap hashMapThree = new HashMap();
        hashMapTwo.put(alsoOne, two);
        hashMapThree.put(one, alsoTwo);
 
        assertTrue(
                "failure of non-equality of IdentityHashMaps one and Hashmap two", 
                !mapOne.equals(hashMapTwo));
        assertTrue(
                "failure of non-equality of IdentityHashMaps one and Hashmap three", 
                !mapOne.equals(hashMapThree));
    } 
 
    /** 
     * java.util.IdentityHashMap#values() 
     */