Package java.util

Examples of java.util.EnumMap$KeySet


    /**
     * @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 serialization/deserialization.
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void testSerializationSelf() throws Exception {
        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Blue, 3);
        SerializationTest.verifySelf(enumColorMap);
    }
View Full Code Here

    /**
     * @tests serialization/deserialization compatibility with RI.
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void testSerializationCompatibility() throws Exception {
        EnumMap enumColorMap = new EnumMap<Color, Double>(Color.class);
        enumColorMap.put(Color.Red, 1);
        enumColorMap.put(Color.Blue, 3);
        SerializationTest.verifyGolden(this, enumColorMap);
    }
View Full Code Here

                        case ID_CC_ENUM_MAP: {
                            int idx = instanceCache.size();
                            instanceCache.add(null);
                            final ClassDescriptor nestedDescriptor = doReadClassDescriptor(readUnsignedByte(), true);
                            final Class<? extends Enum> elementType = nestedDescriptor.getType().asSubclass(Enum.class);
                            return replace(readMapData(unshared, idx, len, new EnumMap(elementType), discardMissing));
                        }
                        case ID_CC_NCOPIES: {
                            final int idx = instanceCache.size();
                            instanceCache.add(null);
                            final Object obj = Collections.nCopies(len, doReadNestedObject(false, "n-copies member object"));
View Full Code Here

     */
    public static Map<Statistics.Tokens, String> fillTokens(String rasterFullPath, String layerName, String year, String month,
            Map<Statistics.Tokens, String> props) {
       
        if (props == null) {
            props = new EnumMap(Statistics.Tokens.class);
        }

        if(rasterFullPath != null)
            props.put(Tokens.FILEPATH, rasterFullPath);
        if(layerName != null)
View Full Code Here

        super.visit(that);
        post(priorCounts, added, that.getAnnotationList());
    }

    private EnumMap<E,Boolean> pre(AnnotationList al) {
        EnumMap<E,Boolean> added = new EnumMap(enumType);
        for (Map.Entry<E, Tree.StringLiteral> entry : getWarningNames(findSuppressWarnings(al), true).entrySet()) {
            E warning = entry.getKey();
            Boolean suppressedByAnnotation = this.suppressed.get(warning);
            if (suppressedByAnnotation == null) {// not suppressed
                this.suppressed.put(warning, true);
                added.put(warning, null);
            } else if (suppressedByAnnotation) {// already suppressed by annotation
                entry.getValue().addUsageWarning(Warning.suppressedAlready, "warnings already suppressed by annotation");
                added.put(warning, true);
            } else {// already suppressed by option
                this.suppressed.put(warning, true);
                added.put(warning, false);
            }
        }
        return added;
    }
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.