Package java.util

Examples of java.util.EnumMap$KeySet


    /**
     * @tests java.util.EnumMap#get(Object)
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_getLjava_lang_Object() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        assertNull("Get returned non-null for non mapped key", enumSizeMap //$NON-NLS-1$
                .get(Size.Big));
        enumSizeMap.put(Size.Big, 1);
        assertEquals("Get returned incorrect value for given key", 1, //$NON-NLS-1$
                enumSizeMap.get(Size.Big));
       
        assertNull("Get returned non-null for non mapped key", enumSizeMap //$NON-NLS-1$
                .get(Size.Small));
        assertNull("Get returned non-null for non existent key", enumSizeMap //$NON-NLS-1$
                .get(Color.Red));
        assertNull("Get returned non-null for non existent key", enumSizeMap //$NON-NLS-1$
                .get(new Integer(1)));
        assertNull("Get returned non-null for non existent key", enumSizeMap //$NON-NLS-1$
                .get(null));

        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        assertNull("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                .get(Color.Green));
        enumColorMap.put(Color.Green, 2);
        assertEquals("Get returned incorrect value for given key", 2, //$NON-NLS-1$
                enumColorMap.get(Color.Green));
        assertNull("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                .get(Color.Blue));
       
        enumColorMap.put(Color.Green, new Double(4));
        assertEquals("Get returned incorrect value for given key", //$NON-NLS-1$
                new Double(4), enumColorMap.get(Color.Green));
        enumColorMap.put(Color.Green, new Integer("3"));//$NON-NLS-1$
        assertEquals("Get returned incorrect value for given key", new Integer( //$NON-NLS-1$
                "3"), enumColorMap.get(Color.Green));//$NON-NLS-1$
        enumColorMap.put(Color.Green, null);
        assertNull("Can not handle null value", enumColorMap.get(Color.Green)); //$NON-NLS-1$
        Float f = new Float("3.4");//$NON-NLS-1$
        enumColorMap.put(Color.Green, f);
        assertSame("Get returned incorrect value for given key", f, //$NON-NLS-1$
                enumColorMap.get(Color.Green));
    }
View Full Code Here


    /**
     * @tests java.util.EnumMap#put(Object,Object)
     */
    @SuppressWarnings( { "unchecked", "boxing" })
    public void test_putLjava_lang_ObjectLjava_lang_Object() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        try {
            enumSizeMap.put(Color.Red, 2);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }
        assertNull("Return non-null for non mapped key", enumSizeMap.put( //$NON-NLS-1$
                Size.Small, 1));

        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        try {
            enumColorMap.put(Size.Big, 2);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }
        try {
            enumColorMap.put(null, 2);
            fail("Expected NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }
        assertNull("Return non-null for non mapped key", enumColorMap.put( //$NON-NLS-1$
                Color.Green, 2));
        assertEquals("Return wrong value", 2, enumColorMap.put(Color.Green, //$NON-NLS-1$
                new Double(4)));
        assertEquals("Return wrong value", new Double(4), enumColorMap.put( //$NON-NLS-1$
                Color.Green, new Integer("3")));//$NON-NLS-1$
        assertEquals("Return wrong value", new Integer("3"), enumColorMap.put( //$NON-NLS-1$//$NON-NLS-2$
                Color.Green, null));
        Float f = new Float("3.4");//$NON-NLS-1$
        assertNull("Return non-null for non mapped key", enumColorMap.put( //$NON-NLS-1$
                Color.Green, f));
        assertNull("Return non-null for non mapped key", enumColorMap.put( //$NON-NLS-1$
                Color.Blue, 2));
        assertEquals("Return wrong value", 2, enumColorMap.put(Color.Blue, //$NON-NLS-1$
                new Double(4)));
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#putAll(Map)
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_putAllLjava_util_Map() {
        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Green, 2);

        EnumMap enumSizeMap = new EnumMap(Size.class);
        enumColorMap.putAll(enumSizeMap);

        enumSizeMap.put(Size.Big, 1);
        try {
            enumColorMap.putAll(enumSizeMap);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }

        EnumMap enumColorMap1 = new EnumMap<Color, Double>(Color.class);
        enumColorMap1.put(Color.Blue, 3);
        enumColorMap.putAll(enumColorMap1);
        assertEquals("Get returned incorrect value for given key", 3, //$NON-NLS-1$
                enumColorMap.get(Color.Blue));
        assertEquals("Wrong Size", 2, enumColorMap.size()); //$NON-NLS-1$

View Full Code Here

    /**
     * @tests java.util.EnumMap#remove(Object)
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_removeLjava_lang_Object() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        assertNull("Remove of non-mapped key returned non-null", enumSizeMap //$NON-NLS-1$
                .remove(Size.Big));
        enumSizeMap.put(Size.Big, 3);
        enumSizeMap.put(Size.Middle, 2);

        assertNull("Get returned non-null for non mapped key", enumSizeMap //$NON-NLS-1$
                .get(Size.Small));
        assertEquals("Remove returned incorrect value", 3, enumSizeMap //$NON-NLS-1$
                .remove(Size.Big));
        assertNull("Get returned non-null for non mapped key", enumSizeMap //$NON-NLS-1$
                .get(Size.Big));
        assertNull("Remove of non-mapped key returned non-null", enumSizeMap //$NON-NLS-1$
                .remove(Size.Big));
        assertNull("Remove of non-existent key returned non-null", enumSizeMap //$NON-NLS-1$
                .remove(Color.Red));
        assertNull("Remove of non-existent key returned non-null", enumSizeMap //$NON-NLS-1$
                .remove(new Double(4)));
        assertNull("Remove of non-existent key returned non-null", enumSizeMap //$NON-NLS-1$
                .remove(null));

        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        assertNull("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                .get(Color.Green));
        enumColorMap.put(Color.Green, new Double(4));
        assertEquals("Remove returned incorrect value", new Double(4), //$NON-NLS-1$
                enumColorMap.remove(Color.Green));
        assertNull("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                .get(Color.Green));
        enumColorMap.put(Color.Green, null);
        assertNull("Can not handle null value", enumColorMap //$NON-NLS-1$
                .remove(Color.Green));
        assertNull("Get returned non-null for non mapped key", enumColorMap //$NON-NLS-1$
                .get(Color.Green));
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#size()
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_size() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        assertEquals("Wrong size", 0, enumSizeMap.size()); //$NON-NLS-1$
        enumSizeMap.put(Size.Small, 1);
        assertEquals("Wrong size", 1, enumSizeMap.size()); //$NON-NLS-1$
        enumSizeMap.put(Size.Small, 0);
        assertEquals("Wrong size", 1, enumSizeMap.size()); //$NON-NLS-1$
        try {
            enumSizeMap.put(Color.Red, 2);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }
        assertEquals("Wrong size", 1, enumSizeMap.size()); //$NON-NLS-1$
       
        enumSizeMap.put(Size.Middle, null);
        assertEquals("Wrong size", 2, enumSizeMap.size()); //$NON-NLS-1$
        enumSizeMap.remove(Size.Big);
        assertEquals("Wrong size", 2, enumSizeMap.size()); //$NON-NLS-1$
        enumSizeMap.remove(Size.Middle);
        assertEquals("Wrong size", 1, enumSizeMap.size()); //$NON-NLS-1$
        enumSizeMap.remove(Color.Green);
        assertEquals("Wrong size", 1, enumSizeMap.size()); //$NON-NLS-1$

        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Green, 2);
        assertEquals("Wrong size", 1, enumColorMap.size()); //$NON-NLS-1$
        enumColorMap.remove(Color.Green);
        assertEquals("Wrong size", 0, enumColorMap.size()); //$NON-NLS-1$

        EnumMap enumEmptyMap = new EnumMap<Empty, Double>(Empty.class);
        assertEquals("Wrong size", 0, enumEmptyMap.size()); //$NON-NLS-1$
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#values()
     */
    @SuppressWarnings( { "unchecked", "boxing" })
    public void test_values() {
        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Red, 1);
        enumColorMap.put(Color.Blue, null);
        Collection collection = enumColorMap.values();

        Collection collection1 = enumColorMap.values();
        assertSame("Should be same", collection1, collection); //$NON-NLS-1$
        try {
            collection.add(new Integer(1));
            fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
        } catch (UnsupportedOperationException e) {
            // Expected
        }

        assertTrue("Returned false for contained object", collection//$NON-NLS-1$
                .contains(1));
        assertTrue("Returned false for contained object", collection//$NON-NLS-1$
                .contains(null));
        assertFalse("Returned true for uncontained object", collection //$NON-NLS-1$
                .contains(2));

        assertTrue("Returned false when the object can be removed", collection //$NON-NLS-1$
                .remove(null));
        assertFalse("Returned true for uncontained object", collection //$NON-NLS-1$
                .contains(null));
        assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
                collection.remove(null));

        // The set is backed by the map so changes to one are reflected by the
        // other.
        enumColorMap.put(Color.Blue, 3);
        assertTrue("Returned false for contained object", collection//$NON-NLS-1$
                .contains(3));
        enumColorMap.remove(Color.Blue);
        assertFalse("Returned true for uncontained object", collection//$NON-NLS-1$
                .contains(3));

        assertEquals("Wrong size", 1, collection.size()); //$NON-NLS-1$
        collection.clear();
        assertEquals("Wrong size", 0, collection.size()); //$NON-NLS-1$

        enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Red, 1);
        enumColorMap.put(Color.Blue, null);
        collection = enumColorMap.values();
        Collection c = new ArrayList();
        c.add(new Integer(1));
        assertTrue("Should return true", collection.containsAll(c)); //$NON-NLS-1$
        c.add(new Double(3.4));
        assertFalse("Should return false", collection.containsAll(c)); //$NON-NLS-1$
        assertTrue("Should return true", collection.removeAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, collection.size()); //$NON-NLS-1$
        assertFalse("Should return false", collection.removeAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, collection.size()); //$NON-NLS-1$
        try {
            collection.addAll(c);
            fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
        } catch (UnsupportedOperationException e) {
            // Expected
        }

        enumColorMap.put(Color.Red, 1);
        assertEquals("Wrong size", 2, collection.size()); //$NON-NLS-1$
        assertTrue("Should return true", collection.retainAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, collection.size()); //$NON-NLS-1$
        assertFalse("Should return false", collection.retainAll(c)); //$NON-NLS-1$
        assertEquals(1, collection.size());
        Object[] array = collection.toArray();
        assertEquals("Wrong length", 1, array.length); //$NON-NLS-1$
        assertEquals("Wrong key", 1, array[0]); //$NON-NLS-1$

        enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Red, 1);
        enumColorMap.put(Color.Blue, null);
        collection = enumColorMap.values();

        assertEquals("Wrong size", 2, collection.size()); //$NON-NLS-1$
        assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
                collection.remove(new Integer("10"))); //$NON-NLS-1$

        Iterator iter = enumColorMap.values().iterator();
        Object value = iter.next();
        assertTrue("Returned false for contained object", collection //$NON-NLS-1$
                .contains(value));
        value = iter.next();
        assertTrue("Returned false for contained object", collection //$NON-NLS-1$
                .contains(value));

        enumColorMap.put(Color.Green, 1);
        enumColorMap.remove(Color.Blue);
        assertFalse("Returned true for uncontained object", collection //$NON-NLS-1$
                .contains(value));
        iter.remove();
        try {
            iter.remove();
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
            // Expected
        }
        assertFalse("Returned true for uncontained object", collection //$NON-NLS-1$
                .contains(value));

        iter = enumColorMap.values().iterator();
        value = iter.next();
        assertTrue("Returned false for contained object", collection //$NON-NLS-1$
                .contains(value));
        enumColorMap.put(Color.Green, 3);
        assertTrue("Returned false for contained object", collection //$NON-NLS-1$
                .contains(value));
        assertTrue("Returned false for contained object", collection //$NON-NLS-1$
                .remove(new Integer("1"))); //$NON-NLS-1$
        assertEquals("Wrong size", 1, collection.size()); //$NON-NLS-1$
        collection.clear();
        assertEquals("Wrong size", 0, collection.size()); //$NON-NLS-1$

        enumColorMap = new EnumMap<Color, Double>(Color.class);
        Integer integer1 = new Integer(1);
        enumColorMap.put(Color.Green, integer1);
        enumColorMap.put(Color.Blue, null);
        collection = enumColorMap.values();
        iter = enumColorMap.values().iterator();
        try {
            iter.remove();
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
            // Expected
View Full Code Here

     * @tests java.util.EnumMap#EnumMap(Class)
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_ConstructorLjava_lang_Class() {
        try {
            new EnumMap((Class) null);
            fail("Expected NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }
       
       
        try {
            new EnumMap(Size.Big.getClass());
            fail("Expected NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }

        try {
            new EnumMap(Integer.class);
            fail("Expected NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }

        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        assertNull("Return non-null for non mapped key", enumColorMap.put( //$NON-NLS-1$
                Color.Green, 2));
        assertEquals("Get returned incorrect value for given key", 2, //$NON-NLS-1$
                enumColorMap.get(Color.Green));

        EnumMap enumEmptyMap = new EnumMap<Empty, Double>(Empty.class);
        try {
            enumEmptyMap.put(Color.Red, 2);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }

        EnumMap enumSizeMap = new EnumMap(Size.class);
        assertNull("Return non-null for non mapped key", enumSizeMap.put( //$NON-NLS-1$
                Size.Big, 2));
        assertEquals("Get returned incorrect value for given key", 2, //$NON-NLS-1$
                enumSizeMap.get(Size.Big));
        try {
            enumSizeMap.put(Color.Red, 2);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }
       
        enumSizeMap = new EnumMap(Size.Middle.getClass());
        assertNull("Return non-null for non mapped key", enumSizeMap.put( //$NON-NLS-1$
                Size.Small, 1));
        assertEquals("Get returned incorrect value for given key", 1, //$NON-NLS-1$
                enumSizeMap.get(Size.Small));
        try {
            enumSizeMap.put(Color.Red, 2);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#EnumMap(EnumMap)
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_ConstructorLjava_util_EnumMap() {
        EnumMap enumMap;
        EnumMap enumColorMap = null;
        try {
            enumMap = new EnumMap(enumColorMap);
            fail("Expected NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }

        enumColorMap = new EnumMap<Color, Double>(Color.class);
        Double double1 = new Double(1);
        enumColorMap.put(Color.Green, 2);
        enumColorMap.put(Color.Blue, double1);
       
        enumMap = new EnumMap(enumColorMap);
        assertEquals("Constructor fails", 2, enumMap.get(Color.Green)); //$NON-NLS-1$
        assertSame("Constructor fails", double1, enumMap.get(Color.Blue)); //$NON-NLS-1$
        assertNull("Constructor fails", enumMap.get(Color.Red)); //$NON-NLS-1$
        enumMap.put(Color.Red, 1);
        assertEquals("Wrong value", 1, enumMap.get(Color.Red)); //$NON-NLS-1$
View Full Code Here

    /**
     * @tests java.util.EnumMap#EnumMap(Map)
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_ConstructorLjava_util_Map() {
        EnumMap enumMap;
        Map enumColorMap = null;
        try {
            enumMap = new EnumMap(enumColorMap);
            fail("Expected NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }
        enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumMap = new EnumMap(enumColorMap);
        enumColorMap.put(Color.Blue, 3);
        enumMap = new EnumMap(enumColorMap);

        HashMap hashColorMap = null;
        try {
            enumMap = new EnumMap(hashColorMap);
            fail("Expected NullPointerException");//$NON-NLS-1$
        } catch (NullPointerException e) {
            // Expected
        }

        hashColorMap = new HashMap();
        try {
            enumMap = new EnumMap(hashColorMap);
            fail("Expected IllegalArgumentException"); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // Expected
        }

        hashColorMap.put(Color.Green, 2);
        enumMap = new EnumMap(hashColorMap);
        assertEquals("Constructor fails", 2, enumMap.get(Color.Green)); //$NON-NLS-1$
        assertNull("Constructor fails", enumMap.get(Color.Red)); //$NON-NLS-1$
        enumMap.put(Color.Red, 1);
        assertEquals("Wrong value", 1, enumMap.get(Color.Red)); //$NON-NLS-1$
        hashColorMap.put(Size.Big, 3);
        try {
            enumMap = new EnumMap(hashColorMap);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }

        hashColorMap = new HashMap();
        hashColorMap.put(new Integer(1), 1);
        try {
            enumMap = new EnumMap(hashColorMap);
            fail("Expected ClassCastException"); //$NON-NLS-1$
        } catch (ClassCastException e) {
            // Expected
        }
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#clear()
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_clear() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Small, 1);
        enumSizeMap.clear();
        assertNull("Failed to clear all elements", enumSizeMap.get(Size.Small)); //$NON-NLS-1$
    }
View Full Code Here

TOP

Related Classes of java.util.EnumMap$KeySet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.