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