< prev index next >

test/jdk/java/util/Map/EntryHashCode.java

Print this page

 34 import java.util.*;
 35 import java.util.concurrent.ConcurrentHashMap;
 36 import java.util.concurrent.ConcurrentSkipListMap;
 37 
 38 public class EntryHashCode {
 39     private static final int TEST_SIZE = 100;
 40 
 41     static final Object[][] entryData = {
 42         new Object[TEST_SIZE],
 43         new Object[TEST_SIZE]
 44     };
 45 
 46     @SuppressWarnings("unchecked")
 47     static final Map<Object,Object>[] maps = (Map<Object,Object>[])new Map[] {
 48         new HashMap<>(),
 49         new Hashtable<>(),
 50         new IdentityHashMap<>(),
 51         new LinkedHashMap<>(),
 52         new TreeMap<>(),
 53         new WeakHashMap<>(),


 54         new ConcurrentHashMap<>(),
 55         new ConcurrentSkipListMap<>()
 56     };
 57 
 58     static {
 59         for (int i = 0; i < entryData[0].length; i++) {
 60             // key objects need to be Comparable for use in TreeMap
 61             entryData[0][i] = new Comparable<Object>() {
 62                 public int compareTo(Object o) {
 63                     return (hashCode() - o.hashCode());
 64                 }
 65             };
 66             entryData[1][i] = new Object();
 67         }
 68     }
 69 
 70     private static void addTestData(Map<Object,Object> map) {
 71         for (int i = 0; i < entryData[0].length; i++) {
 72             map.put(entryData[0][i], entryData[1][i]);
 73         }

 34 import java.util.*;
 35 import java.util.concurrent.ConcurrentHashMap;
 36 import java.util.concurrent.ConcurrentSkipListMap;
 37 
 38 public class EntryHashCode {
 39     private static final int TEST_SIZE = 100;
 40 
 41     static final Object[][] entryData = {
 42         new Object[TEST_SIZE],
 43         new Object[TEST_SIZE]
 44     };
 45 
 46     @SuppressWarnings("unchecked")
 47     static final Map<Object,Object>[] maps = (Map<Object,Object>[])new Map[] {
 48         new HashMap<>(),
 49         new Hashtable<>(),
 50         new IdentityHashMap<>(),
 51         new LinkedHashMap<>(),
 52         new TreeMap<>(),
 53         new WeakHashMap<>(),
 54         new WeakHashMap<>(16, 0.75f, WeakHashMap.ValuePolicy.SOFT),
 55         new WeakHashMap<>(16, 0.75f, WeakHashMap.ValuePolicy.STRONG),
 56         new ConcurrentHashMap<>(),
 57         new ConcurrentSkipListMap<>()
 58     };
 59 
 60     static {
 61         for (int i = 0; i < entryData[0].length; i++) {
 62             // key objects need to be Comparable for use in TreeMap
 63             entryData[0][i] = new Comparable<Object>() {
 64                 public int compareTo(Object o) {
 65                     return (hashCode() - o.hashCode());
 66                 }
 67             };
 68             entryData[1][i] = new Object();
 69         }
 70     }
 71 
 72     private static void addTestData(Map<Object,Object> map) {
 73         for (int i = 0; i < entryData[0].length; i++) {
 74             map.put(entryData[0][i], entryData[1][i]);
 75         }
< prev index next >