Java Code Examples for java.util.EnumMap#remove()

The following examples show how to use java.util.EnumMap#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProperEntrySetOnClone.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 2
Source File: EnumMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings( { "unchecked", "boxing" })
public void test_clone() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    Integer integer = new Integer("3");
    enumSizeMap.put(Size.Small, integer);
    EnumMap enumSizeMapClone = enumSizeMap.clone();
    assertNotSame("Should not be same", enumSizeMap, enumSizeMapClone);
    assertEquals("Clone answered unequal EnumMap", enumSizeMap,
            enumSizeMapClone);

    assertSame("Should be same", enumSizeMap.get(Size.Small),
            enumSizeMapClone.get(Size.Small));
    assertSame("Clone is not shallow clone", integer, enumSizeMapClone
            .get(Size.Small));
    enumSizeMap.remove(Size.Small);
    assertSame("Clone is not shallow clone", integer, enumSizeMapClone
            .get(Size.Small));
}
 
Example 3
Source File: ProperEntrySetOnClone.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 4
Source File: ProperEntrySetOnClone.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 5
Source File: ProperEntrySetOnClone.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 6
Source File: ProperEntrySetOnClone.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 7
Source File: ProperEntrySetOnClone.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 8
Source File: ProperEntrySetOnClone.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 9
Source File: ProperEntrySetOnClone.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 10
Source File: ProperEntrySetOnClone.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 11
Source File: ProperEntrySetOnClone.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 12
Source File: ProperEntrySetOnClone.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 13
Source File: ProperEntrySetOnClone.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 14
Source File: ProperEntrySetOnClone.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 15
Source File: ProperEntrySetOnClone.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
Example 16
Source File: EnumMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@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
            .equals(enumMap));
    enumSizeMap.put(Size.Small, 1);
    assertTrue("Returned false for equal EnumMap", enumSizeMap
            .equals(enumMap));
    enumSizeMap.put(Size.Big, null);
    assertFalse("Returned true for unequal EnumMap", enumSizeMap
            .equals(enumMap));

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

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

    assertFalse("Should return false", enumSizeMap
            .equals(new Integer(1)));
}
 
Example 17
Source File: EnumMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "boxing" })
public void test_size() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    assertEquals("Wrong size", 0, enumSizeMap.size());
    enumSizeMap.put(Size.Small, 1);
    assertEquals("Wrong size", 1, enumSizeMap.size());
    enumSizeMap.put(Size.Small, 0);
    assertEquals("Wrong size", 1, enumSizeMap.size());
    try {
        enumSizeMap.put(Color.Red, 2);
        fail("Expected ClassCastException");
    } catch (ClassCastException e) {
        // Expected
    }
    assertEquals("Wrong size", 1, enumSizeMap.size());

    enumSizeMap.put(Size.Middle, null);
    assertEquals("Wrong size", 2, enumSizeMap.size());
    enumSizeMap.remove(Size.Big);
    assertEquals("Wrong size", 2, enumSizeMap.size());
    enumSizeMap.remove(Size.Middle);
    assertEquals("Wrong size", 1, enumSizeMap.size());
    enumSizeMap.remove(Color.Green);
    assertEquals("Wrong size", 1, enumSizeMap.size());

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

    EnumMap enumEmptyMap = new EnumMap<Empty, Double>(Empty.class);
    assertEquals("Wrong size", 0, enumEmptyMap.size());
}
 
Example 18
Source File: QueryHints.java    From Carbonado with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new QueryHints object without the given hint.
 */
public QueryHints without(QueryHint hint) {
    if (hint == null || mMap == null || !mMap.containsKey(hint)) {
        return this;
    }
    EnumMap<QueryHint, Object> map = mMap.clone();
    map.remove(hint);
    if (map.size() == 0) {
        map = null;
    }
    return new QueryHints(map);
}
 
Example 19
Source File: QualifiedSVGResourceFactory.java    From androidsvgdrawable-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public File getOutputFor(final Density.Value density, final File to, final OutputType outputType, final Density.Value noDpiDensity) {
    StringBuilder builder = new StringBuilder(outputType.name());
    EnumMap<Type, String> qualifiers = new EnumMap<>(typedQualifiers);
    qualifiers.remove(Type.density);
    qualifiers.put(Type.density, density == noDpiDensity ? "nodpi" : density.name());
    builder.append(Qualifier.toQualifiedString(qualifiers));
    return new File(to, builder.toString());
}
 
Example 20
Source File: RecurrenceRule.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
/**
 * Validate this rule.
 *
 * @throws InvalidRecurrenceRuleException
 *         if the rule is not valid with respect to the current {@link #mode}.
 */
private void validate() throws InvalidRecurrenceRuleException
{
    EnumMap<Part, Object> partMap = mParts;
    Freq freq = (Freq) partMap.get(Part.FREQ);

    // FREQ is mandatory part of each rule
    if (freq == null)
    {
        throw new InvalidRecurrenceRuleException("FREQ part is missing");
    }

    final boolean strict = mode == RfcMode.RFC2445_STRICT || mode == RfcMode.RFC5545_STRICT;

    // UNTIL and COUNT are mutually exclusive
    if (partMap.containsKey(Part.UNTIL) && partMap.containsKey(Part.COUNT))
    {
        throw new InvalidRecurrenceRuleException("UNTIL and COUNT must not occur in the same rule.");
    }

    // interval must not be 0 or less
    if (getInterval() <= 0)
    {
        if (strict)
        {
            throw new InvalidRecurrenceRuleException("INTERVAL must not be <= 0");
        }
        else
        {
            // just remove interval and assume 1
            partMap.remove(Part.INTERVAL);
        }
    }

    if (freq != Freq.YEARLY && partMap.containsKey(Part.BYWEEKNO))
    {
        if (strict)
        {
            throw new InvalidRecurrenceRuleException("BYWEEKNO is allowed in YEARLY rules only");
        }
        else
        {
            partMap.put(Part.FREQ, Freq.YEARLY);
        }
    }

    if (mode == RfcMode.RFC5545_STRICT)
    {
        // in RFC 5545 BYYEARDAY does not support DAILY, WEEKLY and MONTHLY rules
        if ((freq == Freq.DAILY || freq == Freq.WEEKLY || freq == Freq.MONTHLY) && partMap.containsKey(
                Part.BYYEARDAY))
        {
            throw new InvalidRecurrenceRuleException(
                    "In RFC 5545, BYYEARDAY is not allowed in DAILY, WEEKLY or MONTHLY rules");
        }

        // in RFC 5545 BYMONTHAY must not be used in WEEKLY rules
        if (freq == Freq.WEEKLY && partMap.containsKey(Part.BYMONTHDAY))
        {
            throw new InvalidRecurrenceRuleException("In RFC 5545, BYMONTHDAY is not allowed in WEEKLY rules");
        }

    }

    /**
     * BYSETPOS is only valid in combination with another BYxxx rule. We therefore check the number of elements. If this number is larger than cnt the rule
     * contains another BYxxx rule and is therefore valid.
     */
    if (partMap.containsKey(Part.BYSETPOS))
    {
        if (!partMap.containsKey(Part.BYDAY) && !partMap.containsKey(Part.BYMONTHDAY) && !partMap.containsKey(
                Part.BYMONTH)
                && !partMap.containsKey(Part.BYHOUR) && !partMap.containsKey(Part.BYMINUTE) && !partMap.containsKey(
                Part.BYSECOND)
                && !partMap.containsKey(Part.BYWEEKNO) && !partMap.containsKey(Part.BYYEARDAY))
        {
            if (strict)
            {
                // we're in strict mode => throw exception
                throw new InvalidRecurrenceRuleException(
                        "BYSETPOS must only be used in conjunction with another BYxxx rule.");
            }
            else
            {
                // we're in lax mode => drop BYSETPOS
                partMap.remove(Part.BYSETPOS);
            }
        }
    }
    /**
     * Check for invalid rules when a numeric value is set in BYDAY.
     */
    checkForInvalidNumericInByDay(freq);
}