Package java.util

Examples of java.util.EnumMap$EntryIterator$Entry


  public static Map<Object, Object> createMap(Class<?> mapType, Class<?> keyType, int size) {

    Assert.notNull(mapType, "Map type must not be null!");

    if (EnumMap.class.isAssignableFrom(mapType)) {
      return new EnumMap(asEnumType(keyType));
    }

    return org.springframework.core.CollectionFactory.createMap(mapType, size);
  }
View Full Code Here


                        case ID_CC_ENUM_MAP: {
                            int idx = instanceCache.size();
                            instanceCache.add(null);
                            final ClassDescriptor nestedDescriptor = doReadClassDescriptor(readUnsignedByte());
                            final Class<? extends Enum> elementType = nestedDescriptor.getType().asSubclass(Enum.class);
                            return replace(readMapData(unshared, idx, len, new EnumMap(elementType)));
                        }
                        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

        if (attributeName == null) {
            throw new ConversionException("No EnumType specified for EnumMap");
        }
        final Class<?> type = mapper().realClass(reader.getAttribute(attributeName));
        @SuppressWarnings({"rawtypes", "unchecked"})
        final EnumMap<?, ?> map = new EnumMap(type);
        populateMap(reader, context, map);
        return map;
    }
View Full Code Here

        super.marshal(source, writer, context);
    }

    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        Class type = mapper().realClass(reader.getAttribute(mapper().aliasForAttribute("enum-type")));
        EnumMap map = new EnumMap(type);
        populateMap(reader, context, map);
        return map;
    }
View Full Code Here

  // This is legit because enumKeyType above is both an enum type (checked at
  // runtime in the EnumMap ctor) and is the type of a subclass of K.
  @SuppressWarnings({ "rawtypes", "unchecked" })
  private static <K, V>
  Map<K, V> makeEnumMap(Class<? extends Enum> t) { return new EnumMap(t); }
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

        checkNotNull(entry.getKey());
        checkNotNull(entry.getValue());
      }
      @SuppressWarnings("unchecked")
      // immutable collections are safe for covariant casts
      ImmutableMap<K, V> result = ImmutableEnumMap.asImmutable(new EnumMap(enumMap));
      return result;
    }

    int size = map.size();
    switch (size) {
View Full Code Here

        checkNotNull(entry.getKey());
        checkNotNull(entry.getValue());
      }
      @SuppressWarnings("unchecked")
      // immutable collections are safe for covariant casts
      ImmutableMap<K, V> result = ImmutableEnumMap.asImmutable(new EnumMap(enumMap));
      return result;
    }

    @SuppressWarnings("unchecked") // we won't write to this array
    Entry<K, V>[] entries = map.entrySet().toArray(new Entry[0]);
View Full Code Here

    /**
     * @tests java.util.EnumMap#equals(Object)
     */
    @SuppressWarnings( { "unchecked", "boxing" })
    public void test_equalsLjava_lang_Object() {
        EnumMap enumMap = new EnumMap(Size.class);
        enumMap.put(Size.Small, 1);

        EnumMap enumSizeMap = new EnumMap(Size.class);
        assertFalse("Returned true for unequal EnumMap", enumSizeMap //$NON-NLS-1$
                .equals(enumMap));
        enumSizeMap.put(Size.Small, 1);
        assertTrue("Returned false for equal EnumMap", enumSizeMap //$NON-NLS-1$
                .equals(enumMap));
        enumSizeMap.put(Size.Big, null);
        assertFalse("Returned true for unequal EnumMap", enumSizeMap //$NON-NLS-1$
                .equals(enumMap));

        enumMap.put(Size.Middle, null);
        assertFalse("Returned true for unequal EnumMap", enumSizeMap //$NON-NLS-1$
                .equals(enumMap));
        enumMap.remove(Size.Middle);
        enumMap.put(Size.Big, 3);
        assertFalse("Returned true for unequal EnumMap", enumSizeMap //$NON-NLS-1$
                .equals(enumMap));
        enumMap.put(Size.Big, null);
        assertTrue("Returned false for equal EnumMap", enumSizeMap //$NON-NLS-1$
                .equals(enumMap));

        HashMap hashMap = new HashMap();
        hashMap.put(Size.Small, 1);
        assertFalse("Returned true for unequal EnumMap", hashMap //$NON-NLS-1$
                .equals(enumMap));
        hashMap.put(Size.Big, null);
        assertTrue("Returned false for equal EnumMap", enumMap.equals(hashMap)); //$NON-NLS-1$

        assertFalse("Should return false", enumSizeMap //$NON-NLS-1$
                .equals(new Integer(1)));
    }
View Full Code Here

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

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

        assertTrue("Returned false for contained object", set//$NON-NLS-1$
                .contains(Size.Middle));
        assertTrue("Returned false for contained object", set//$NON-NLS-1$
                .contains(Size.Big));
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(Size.Small));
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(new Integer(1)));
        assertTrue("Returned false when the object can be removed", set //$NON-NLS-1$
                .remove(Size.Big));
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(Size.Big));
        assertFalse("Returned true when the object can not be removed", set //$NON-NLS-1$
                .remove(Size.Big));
        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);
        assertTrue("Returned false for contained object", set//$NON-NLS-1$
                .contains(Size.Big));
        enumSizeMap.remove(Size.Big);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(Size.Big));

        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.keySet();
        Collection c = new ArrayList();
        c.add(Size.Big);
        assertTrue("Should return true", set.containsAll(c)); //$NON-NLS-1$
        c.add(Size.Small);
        assertFalse("Should return false", set.containsAll(c)); //$NON-NLS-1$
        assertTrue("Should return true", set.removeAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, set.size()); //$NON-NLS-1$
        assertFalse("Should return false", set.removeAll(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 1, set.size()); //$NON-NLS-1$
        try {
            set.addAll(c);
            fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
        } catch (UnsupportedOperationException e) {
            // Expected
        }

        enumSizeMap.put(Size.Big, null);
        assertEquals("Wrong size", 2, set.size()); //$NON-NLS-1$
        assertTrue("Should return true", 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$
        assertEquals(1, set.size());
        Object[] array = set.toArray();
        assertEquals("Wrong length", 1, array.length); //$NON-NLS-1$
        assertEquals("Wrong key", Size.Big, array[0]); //$NON-NLS-1$

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.keySet();
        c = new ArrayList();
        c.add(Color.Blue);
        assertFalse("Should return false", set.remove(c)); //$NON-NLS-1$
        assertEquals("Wrong size", 2, set.size()); //$NON-NLS-1$
        assertTrue("Should return true", set.retainAll(c)); //$NON-NLS-1$
        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.keySet();

        Iterator iter = set.iterator();
        Enum enumKey = (Enum) iter.next();
        assertTrue("Returned false for contained object", set.contains(enumKey)); //$NON-NLS-1$
        enumKey = (Enum) iter.next();
        assertTrue("Returned false for contained object", set.contains(enumKey)); //$NON-NLS-1$

        enumSizeMap.remove(Size.Big);
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(enumKey));
        iter.remove();
        try {
            iter.remove();
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
            // Expected
        }
        assertFalse("Returned true for uncontained object", set //$NON-NLS-1$
                .contains(enumKey));

        iter = set.iterator();
        enumKey = (Enum) iter.next();
        assertTrue("Returned false for contained object", set.contains(enumKey)); //$NON-NLS-1$
        enumSizeMap.put(Size.Middle, 3);
        assertTrue("Returned false for contained object", set.contains(enumKey)); //$NON-NLS-1$

        enumSizeMap = new EnumMap(Size.class);
        enumSizeMap.put(Size.Middle, 1);
        enumSizeMap.put(Size.Big, null);
        set = enumSizeMap.keySet();
        iter = set.iterator();
        try {
            iter.remove();
            fail("Should throw IllegalStateException"); //$NON-NLS-1$
        } catch (IllegalStateException e) {
View Full Code Here

TOP

Related Classes of java.util.EnumMap$EntryIterator$Entry

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.