Code example for HashMap

Methods: get, put, size

0
        assert v4.compareTo(v1) == expected; // we're comparing IDs (same) and then creators
        assert v4.compareToIDs(v1) == 0;     // we're only comparing IDs
    } 
 
    public void testHashCode() { 
        Map<ViewId,Integer> map=new HashMap<ViewId,Integer>();
        map.put(v1, 1);
        assert map.size() == 1;
 
        map.put(v2, 2);
        assert map.size() == 2;
 
        map.put(v3, 3);
        assert map.size() == 2; // replaces v1
 
        map.put(v4, 4);
        System.out.println("map = " + map);
        assert map.size() == 3; // v1 and v3 are the same
 
        assert map.get(v1) == 3;
        assert map.get(v2) == 2;
        assert map.get(v3) == 3;
        assert map.get(v4) == 4;
    } 
    
}