DistinctEntrySetElements.java revision 4248
10139N/A/*
10139N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
10139N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10139N/A *
10139N/A * This code is free software; you can redistribute it and/or modify it
10139N/A * under the terms of the GNU General Public License version 2 only, as
10139N/A * published by the Free Software Foundation.
10139N/A *
10139N/A * This code is distributed in the hope that it will be useful, but WITHOUT
10139N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10139N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10139N/A * version 2 for more details (a copy is included in the LICENSE file that
10139N/A * accompanied this code).
10139N/A *
10139N/A * You should have received a copy of the GNU General Public License version
10139N/A * 2 along with this work; if not, write to the Free Software Foundation,
10139N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10139N/A *
10139N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10139N/A * or visit www.oracle.com if you need additional information or have any
10139N/A * questions.
10139N/A */
10139N/A
10139N/A/*
10139N/A * Portions Copyright (c) 2011 IBM Corporation
10139N/A */
10139N/A
10139N/A/*
10139N/A * @test
10139N/A * @bug 6312706
10139N/A * @summary Sets from Map.entrySet() return distinct objects for each Entry
10139N/A * @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
10139N/A */
10139N/A
10139N/Aimport java.util.EnumMap;
10139N/Aimport java.util.HashSet;
10139N/Aimport java.util.Map;
10139N/Aimport java.util.Set;
10139N/A
10139N/Apublic class DistinctEntrySetElements {
10139N/A static enum TestEnum { e00, e01, e02 }
10139N/A
10139N/A public static void main(String[] args) throws Exception {
10139N/A final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);
10139N/A
10139N/A for (TestEnum e : TestEnum.values()) {
10139N/A enumMap.put(e, e.name());
10139N/A }
10139N/A
10139N/A Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
10139N/A HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);
10139N/A
10139N/A if (false == hashSet.equals(entrySet)) {
10139N/A throw new RuntimeException("Test FAILED: Sets are not equal.");
10139N/A }
10139N/A if (hashSet.hashCode() != entrySet.hashCode()) {
10139N/A throw new RuntimeException("Test FAILED: Set's hashcodes are not equal.");
10139N/A }
10139N/A }
10139N/A}
10139N/A