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

The following examples show how to use java.util.EnumMap#clone() . 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 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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));
}