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