Code example for TreeMap

Methods: comparator, firstKey, lastKey

0
     */ 
    public void test_ConstructorLjava_util_Map() { 
        // Test for method java.util.TreeMap(java.util.Map) 
        TreeMap myTreeMap = new TreeMap(new HashMap(tm));
        assertTrue("Map is incorrect size", myTreeMap.size() == objArray.length);
        for (Object element : objArray) {
            assertTrue("Map has incorrect mappings", myTreeMap.get(
                    element.toString()).equals(element));
        } 
    } 
 
    /** 
     * @tests java.util.TreeMap#TreeMap(java.util.SortedMap) 
     */ 
    public void test_ConstructorLjava_util_SortedMap() { 
        // Test for method java.util.TreeMap(java.util.SortedMap) 
        Comparator comp = new ReversedComparator();
        TreeMap reversedTreeMap = new TreeMap(comp);
        reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
        reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
        TreeMap anotherTreeMap = new TreeMap(reversedTreeMap);