jdk/test/java/util/EnumMap/DistinctEntrySetElements.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 9734 b33a24d77590
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9235
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     1
/*
9734
b33a24d77590 7044486: open jdk repos have files with incorrect copyright headers, which can end up in src bundles
katleman
parents: 9235
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
9235
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     4
 *
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     8
 *
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    13
 * accompanied this code).
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    14
 *
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    18
 *
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    21
 * questions.
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    22
 */
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    23
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    24
/*
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    25
 * Portions Copyright (c) 2011 IBM Corporation
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    26
 */
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    27
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    28
/*
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    29
 * @test
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    30
 * @bug 6312706
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    31
 * @summary Sets from Map.entrySet() return distinct objects for each Entry
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    32
 * @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    33
 */
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    34
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    35
import java.util.EnumMap;
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    36
import java.util.HashSet;
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    37
import java.util.Map;
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    38
import java.util.Set;
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    39
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    40
public class DistinctEntrySetElements {
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    41
    static enum TestEnum { e00, e01, e02 }
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    42
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    44
        final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    45
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    46
        for (TestEnum e : TestEnum.values()) {
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    47
            enumMap.put(e, e.name());
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    48
        }
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    49
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    50
        Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    51
        HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    52
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    53
        if (false == hashSet.equals(entrySet)) {
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    54
            throw new RuntimeException("Test FAILED: Sets are not equal.");
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    55
        }
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    56
        if (hashSet.hashCode() != entrySet.hashCode()) {
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    57
            throw new RuntimeException("Test FAILED: Set's hashcodes are not equal.");
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    58
        }
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    59
    }
ddd556c97e6c 6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff changeset
    60
}