Package java.util

Examples of java.util.EnumMap$EntrySetIterator


    /**
     * @tests java.util.EnumMap#containsKey(Object)
     */
    @SuppressWarnings( { "unchecked", "boxing" })
    public void test_containsKeyLjava_lang_Object() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
                .containsKey(Size.Small));
        enumSizeMap.put(Size.Small, 1);
        assertTrue("Returned false for contained key", enumSizeMap //$NON-NLS-1$
                .containsKey(Size.Small));

        enumSizeMap.put(Size.Big, null);
        assertTrue("Returned false for contained key", enumSizeMap //$NON-NLS-1$
                .containsKey(Size.Big));

        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
                .containsKey(Color.Red));
        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
                .containsKey(new Integer("3"))); //$NON-NLS-1$
        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
                .containsKey(null));
    }
View Full Code Here


    /**
     * @tests java.util.EnumMap#clone()
     */
    @SuppressWarnings( { "unchecked", "boxing" })
    public void test_clone() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        Integer integer = new Integer("3"); //$NON-NLS-1$
        enumSizeMap.put(Size.Small, integer);
        EnumMap enumSizeMapClone = enumSizeMap.clone();
        assertNotSame("Should not be same", enumSizeMap, enumSizeMapClone); //$NON-NLS-1$
        assertEquals("Clone answered unequal EnumMap", enumSizeMap, //$NON-NLS-1$
                enumSizeMapClone);

        assertSame("Should be same", enumSizeMap.get(Size.Small), //$NON-NLS-1$
                enumSizeMapClone.get(Size.Small));
        assertSame("Clone is not shallow clone", integer, enumSizeMapClone //$NON-NLS-1$
                .get(Size.Small));
        enumSizeMap.remove(Size.Small);
        assertSame("Clone is not shallow clone", integer, enumSizeMapClone //$NON-NLS-1$
                .get(Size.Small));
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#containsValue(Object)
     */
    @SuppressWarnings( { "unchecked", "boxing" })
    public void test_containsValueLjava_lang_Object() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        Double double1 = new Double(3);
        Double double2 = new Double(3);

        assertFalse("Returned true for uncontained value", enumSizeMap //$NON-NLS-1$
                .containsValue(double1));
        enumSizeMap.put(Size.Middle, 2);
        enumSizeMap.put(Size.Small, double1);
        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
                .containsValue(double1));
        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
                .containsValue(double2));
        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
                .containsValue(2));
        assertFalse("Returned true for uncontained value", enumSizeMap //$NON-NLS-1$
                .containsValue(1));

        assertFalse("Returned true for uncontained value", enumSizeMap //$NON-NLS-1$
                .containsValue(null));
        enumSizeMap.put(Size.Big, null);
        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
                .containsValue(null));
    }
View Full Code Here

    /**
     * @tests java.util.EnumMap#entrySet()
     */
    @SuppressWarnings({ "unchecked", "boxing" })
    public void test_entrySet() {
        EnumMap enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        MockEntry mockEntry = new MockEntry(Size.Middle, 1);
        Set set = enumSizeMap.entrySet();

        Set set1 = enumSizeMap.entrySet();
        assertSame("Should be same", set1, set); //$NON-NLS-1$
        try {
            set.add(mockEntry);
            fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
        } catch (UnsupportedOperationException e) {
            // Expected
        }

        assertTrue("Returned false for contained object", set//$NON-NLS-1$
                .contains(mockEntry));
        mockEntry = new MockEntry(Size.Middle, null);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(mockEntry));
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(Size.Small));
        mockEntry = new MockEntry(new Integer(1), 1);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(mockEntry));
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(new Integer(1)));

        mockEntry = new MockEntry(Size.Big, null);
        assertTrue("Returned false for contained object", set//$NON-NLS-1$
                .contains(mockEntry));
        assertTrue("Returned false when the object can be removed", set //$NON-NLS-1$
                .remove(mockEntry));
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(mockEntry));
        assertFalse("Returned true when the object can not be removed", set //$NON-NLS-1$
                .remove(mockEntry));
        mockEntry = new MockEntry(new Integer(1), 1);
        assertFalse("Returned true when the object can not be removed", set //$NON-NLS-1$
                .remove(mockEntry));
        assertFalse("Returned true when the object can not be removed", set //$NON-NLS-1$
                .remove(new Integer(1)));

        // The set is backed by the map so changes to one are reflected by the
        // other.
        enumSizeMap.put(Size.Big, 3);
        mockEntry = new MockEntry(Size.Big, 3);
        assertTrue("Returned false for contained object", set//$NON-NLS-1$
                .contains(mockEntry));
        enumSizeMap.remove(Size.Big);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(mockEntry));

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

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.entrySet();
        Collection c = new ArrayList();
        c.add(new MockEntry(Size.Middle, 1));
        assertTrue("Return wrong value", set.containsAll(c)); //$NON-NLS-1$
        assertTrue("Remove does not success", set.removeAll(c)); //$NON-NLS-1$

        enumSizeMap.put(Size.Middle, 1);
        c.add(new MockEntry(Size.Big, 3));
        assertTrue("Remove does not success", set.removeAll(c)); //$NON-NLS-1$
        assertFalse("Should return false", set.removeAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, set.size()); //$NON-NLS-1$

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.entrySet();
        c = new ArrayList();
        c.add(new MockEntry(Size.Middle, 1));
        c.add(new MockEntry(Size.Big, 3));

        assertTrue("Retain does not success", set.retainAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, set.size()); //$NON-NLS-1$
        assertFalse("Should return false", set.retainAll(c)); //$NON-NLS-1$

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);

        set = enumSizeMap.entrySet();
        Object[] array = set.toArray();
        assertEquals("Wrong length", 2, array.length); //$NON-NLS-1$
        Map.Entry entry = (Map.Entry) array[0];
        assertEquals("Wrong key", Size.Middle, entry.getKey()); //$NON-NLS-1$
        assertEquals("Wrong value", 1, entry.getValue()); //$NON-NLS-1$

        Object[] array1 = new Object[10];
        array1 = set.toArray();
        assertEquals("Wrong length", 2, array1.length); //$NON-NLS-1$
        entry = (Map.Entry) array[0];
        assertEquals("Wrong key", Size.Middle, entry.getKey()); //$NON-NLS-1$
        assertEquals("Wrong value", 1, entry.getValue()); //$NON-NLS-1$

        array1 = new Object[10];
        array1 = set.toArray(array1);
        assertEquals("Wrong length", 10, array1.length); //$NON-NLS-1$
        entry = (Map.Entry) array[1];
        assertEquals("Wrong key", Size.Big, entry.getKey()); //$NON-NLS-1$
        assertNull("Should be null", array1[2]); //$NON-NLS-1$

        set = enumSizeMap.entrySet();
        Integer integer = new Integer("1"); //$NON-NLS-1$
        assertFalse("Returned true when the object can not be removed", set //$NON-NLS-1$
                .remove(integer));
        assertTrue("Returned false when the object can be removed", set //$NON-NLS-1$
                .remove(entry));

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.entrySet();
        Iterator iter = set.iterator();
        entry = (Map.Entry) iter.next();
        assertTrue("Returned false for contained object", set.contains(entry)); //$NON-NLS-1$
        mockEntry = new MockEntry(Size.Middle, 2);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(mockEntry));
        mockEntry = new MockEntry(new Integer(2), 2);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(mockEntry));
        entry = (Map.Entry) iter.next();
        assertTrue("Returned false for contained object", set.contains(entry)); //$NON-NLS-1$

        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.remove(Size.Big);
        mockEntry = new MockEntry(Size.Big, null);
        assertEquals("Wrong size", 1, set.size()); //$NON-NLS-1$
        assertFalse("Returned true for uncontained object", set.contains(mockEntry)); //$NON-NLS-1$
        enumSizeMap.put(Size.Big, 2);
        mockEntry = new MockEntry(Size.Big, 2);
        assertTrue("Returned false for contained object", set //$NON-NLS-1$
                .contains(mockEntry));

        iter.remove();
        try {
            iter.remove();
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
            // Expected
        }
        try {
            entry.setValue(2);
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
            // Expected
        }
        try {
            set.contains(entry);
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
            // Expected
        }

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.entrySet();
        iter = set.iterator();
        entry = (Map.Entry) iter.next();
        assertEquals("Wrong key", Size.Middle, entry.getKey()); //$NON-NLS-1$

        assertTrue("Returned false for contained object", set.contains(entry)); //$NON-NLS-1$
        enumSizeMap.put(Size.Middle, 3);
        assertTrue("Returned false for contained object", set.contains(entry)); //$NON-NLS-1$
        entry.setValue(2);
        assertTrue("Returned false for contained object", set.contains(entry)); //$NON-NLS-1$
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .remove(new Integer(1)));

        iter.next();
        //The following test case fails on RI.
        assertEquals("Wrong key", Size.Middle, entry.getKey()); //$NON-NLS-1$
        set.clear();
        assertEquals("Wrong size", 0, set.size()); //$NON-NLS-1$

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.entrySet();
        iter = set.iterator();
        mockEntry = new MockEntry(Size.Middle, 1);

        assertFalse("Wrong result", entry.equals(mockEntry)); //$NON-NLS-1$
        try {
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

   */
  public static EnumMap instantiate(SerializationStreamReader streamReader)
      throws SerializationException {
    Object exemplar = streamReader.readObject();
    Class clazz = exemplar.getClass();
    return new EnumMap(clazz);
  }
View Full Code Here

            SchemaId schemaId = idGenerator.getSchemaId(schemaIdBytes);
            idToQNameMapping.put(schemaId, name);
        }

        Map<Scope, SchemaId> recordTypeIds = new EnumMap(Scope.class);
        for (Scope scope : Scope.values()) {
            byte[] schemaIdBytes = readNullOrBytes(input);
            if (schemaIdBytes != null) {
                SchemaId schemaId = idGenerator.getSchemaId(schemaIdBytes);
                recordTypeIds.put(scope, schemaId);
            }
        }

        return new IdRecordImpl(record, idToQNameMapping, recordTypeIds);
    }
View Full Code Here

        String attributeName = mapper().aliasForSystemAttribute("enum-type");
        if (attributeName == null) {
            throw new ConversionException("No EnumType specified for EnumMap");
        }
        Class type = mapper().realClass(reader.getAttribute(attributeName));
        EnumMap map = new EnumMap(type);
        populateMap(reader, context, map);
        return map;
    }
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

TOP

Related Classes of java.util.EnumMap$EntrySetIterator

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.