test/java/util/concurrent/ConcurrentHashMap/MapCheck.java

Print this page

        

@@ -32,11 +32,11 @@
  */
 
 /*
  * @test
  * @bug 4486658
- * @compile MapCheck.java
+ * @compile -source 1.5 MapCheck.java
  * @run main/timeout=240 MapCheck
  * @summary Times and checks basic map operations
  */
 
 import java.util.*;

@@ -62,11 +62,11 @@
         int size = 50000;
 
         if (args.length > 0) {
             try {
                 mapClass = Class.forName(args[0]);
-            } catch(ClassNotFoundException e) {
+            } catch (ClassNotFoundException e) {
                 throw new RuntimeException("Class " + args[0] + " not found.");
             }
         }
 
 

@@ -100,11 +100,11 @@
 
     static Map newMap(Class cl) {
         try {
             Map m = (Map)cl.newInstance();
             return m;
-        } catch(Exception e) {
+        } catch (Exception e) {
             throw new RuntimeException("Can't instantiate " + cl + ": " + e);
         }
     }
 
 

@@ -137,51 +137,51 @@
             for (int i = 0; i < n; i++) {
                 if (s.get(key[i]) != null) ++sum;
             }
         }
         timer.finish();
-        reallyAssert (sum == expect * iters);
+        reallyAssert(sum == expect * iters);
     }
 
     static void t2(String nm, int n, Map s, Object[] key, int expect) {
         int sum = 0;
         timer.start(nm, n);
         for (int i = 0; i < n; i++) {
             if (s.remove(key[i]) != null) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == expect);
+        reallyAssert(sum == expect);
     }
 
     static void t3(String nm, int n, Map s, Object[] key, int expect) {
         int sum = 0;
         timer.start(nm, n);
         for (int i = 0; i < n; i++) {
             if (s.put(key[i], absent[i & absentMask]) == null) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == expect);
+        reallyAssert(sum == expect);
     }
 
     static void t4(String nm, int n, Map s, Object[] key, int expect) {
         int sum = 0;
         timer.start(nm, n);
         for (int i = 0; i < n; i++) {
             if (s.containsKey(key[i])) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == expect);
+        reallyAssert(sum == expect);
     }
 
     static void t5(String nm, int n, Map s, Object[] key, int expect) {
         int sum = 0;
         timer.start(nm, n/2);
         for (int i = n-2; i >= 0; i-=2) {
             if (s.remove(key[i]) != null) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == expect);
+        reallyAssert(sum == expect);
     }
 
     static void t6(String nm, int n, Map s, Object[] k1, Object[] k2) {
         int sum = 0;
         timer.start(nm, n * 2);

@@ -188,11 +188,11 @@
         for (int i = 0; i < n; i++) {
             if (s.get(k1[i]) != null) ++sum;
             if (s.get(k2[i & absentMask]) != null) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == n);
+        reallyAssert(sum == n);
     }
 
     static void t7(String nm, int n, Map s, Object[] k1, Object[] k2) {
         int sum = 0;
         timer.start(nm, n * 2);

@@ -199,21 +199,21 @@
         for (int i = 0; i < n; i++) {
             if (s.containsKey(k1[i])) ++sum;
             if (s.containsKey(k2[i & absentMask])) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == n);
+        reallyAssert(sum == n);
     }
 
     static void t8(String nm, int n, Map s, Object[] key, int expect) {
         int sum = 0;
         timer.start(nm, n);
         for (int i = 0; i < n; i++) {
             if (s.get(key[i]) != null) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == expect);
+        reallyAssert(sum == expect);
     }
 
 
     static void t9(Map s) {
         int sum = 0;

@@ -221,11 +221,11 @@
         timer.start("ContainsValue (/n)     ", iters * s.size());
         int step = absentSize / iters;
         for (int i = 0; i < absentSize; i += step)
             if (s.containsValue(absent[i])) ++sum;
         timer.finish();
-        reallyAssert (sum != 0);
+        reallyAssert(sum != 0);
     }
 
 
     static void ktest(Map s, int size, Object[] key) {
         timer.start("ContainsKey            ", size);

@@ -233,49 +233,49 @@
         int sum = 0;
         for (int i = 0; i < size; i++) {
             if (ks.contains(key[i])) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
 
     static void ittest1(Map s, int size) {
         int sum = 0;
         timer.start("Iter Key               ", size);
         for (Iterator it = s.keySet().iterator(); it.hasNext(); ) {
-            if(it.next() != MISSING)
+            if (it.next() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
     static void ittest2(Map s, int size) {
         int sum = 0;
         timer.start("Iter Value             ", size);
         for (Iterator it = s.values().iterator(); it.hasNext(); ) {
-            if(it.next() != MISSING)
+            if (it.next() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
     static void ittest3(Map s, int size) {
         int sum = 0;
         timer.start("Iter Entry             ", size);
         for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) {
-            if(it.next() != MISSING)
+            if (it.next() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
     static void ittest4(Map s, int size, int pos) {
         IdentityHashMap seen = new IdentityHashMap(size);
-        reallyAssert (s.size() == size);
+        reallyAssert(s.size() == size);
         int sum = 0;
         timer.start("Iter XEntry            ", size);
         Iterator it = s.entrySet().iterator();
         Object k = null;
         Object v = null;

@@ -285,27 +285,27 @@
             v = x.getValue();
             seen.put(k, k);
             if (x != MISSING)
                 ++sum;
         }
-        reallyAssert (s.containsKey(k));
+        reallyAssert(s.containsKey(k));
         it.remove();
-        reallyAssert (!s.containsKey(k));
+        reallyAssert(!s.containsKey(k));
         while (it.hasNext()) {
             Map.Entry x = (Map.Entry)(it.next());
             Object k2 = x.getKey();
             seen.put(k2, k2);
             if (x != MISSING)
                 ++sum;
         }
 
-        reallyAssert (s.size() == size-1);
+        reallyAssert(s.size() == size-1);
         s.put(k, v);
-        reallyAssert (seen.size() == size);
+        reallyAssert(seen.size() == size);
         timer.finish();
-        reallyAssert (sum == size);
-        reallyAssert (s.size() == size);
+        reallyAssert(sum == size);
+        reallyAssert(s.size() == size);
     }
 
 
     static void ittest(Map s, int size) {
         ittest1(s, size);

@@ -322,11 +322,11 @@
         for (Enumeration en = ht.keys(); en.hasMoreElements(); ) {
             if (en.nextElement() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
     static void entest2(Hashtable ht, int size) {
         int sum = 0;
         timer.start("Iter Enumeration Value ", size);

@@ -333,11 +333,11 @@
         for (Enumeration en = ht.elements(); en.hasMoreElements(); ) {
             if (en.nextElement() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
 
     static void entest3(Hashtable ht, int size) {
         int sum = 0;

@@ -347,11 +347,11 @@
         for (int i = 0; i < size; ++i) {
             if (en.nextElement() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
     static void entest4(Hashtable ht, int size) {
         int sum = 0;
         timer.start("Iterf Enumeration Value", size);

@@ -359,11 +359,11 @@
         for (int i = 0; i < size; ++i) {
             if (en.nextElement() != MISSING)
                 ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
     }
 
     static void entest(Map s, int size) {
         if (s instanceof Hashtable) {
             Hashtable ht = (Hashtable)s;

@@ -407,17 +407,17 @@
         catch (Exception e) { e.printStackTrace(); return; }
         timer.finish();
 
         timer.start("Iter Equals            ", size * 2);
         boolean eqt = s2.equals(s) && s.equals(s2);
-        reallyAssert (eqt);
+        reallyAssert(eqt);
         timer.finish();
 
         timer.start("Iter HashCode          ", size * 2);
         int shc = s.hashCode();
         int s2hc = s2.hashCode();
-        reallyAssert (shc == s2hc);
+        reallyAssert(shc == s2hc);
         timer.finish();
 
         timer.start("Put (present)          ", size);
         s2.putAll(s);
         timer.finish();

@@ -428,25 +428,25 @@
         for (Iterator i1 = s.entrySet().iterator(); i1.hasNext(); ) {
             Object entry = i1.next();
             if (es2.contains(entry)) ++sum;
         }
         timer.finish();
-        reallyAssert (sum == size);
+        reallyAssert(sum == size);
 
         t6("Get                    ", size, s2, key, absent);
 
         Object hold = s2.get(key[size-1]);
         s2.put(key[size-1], absent[0]);
         timer.start("Iter Equals            ", size * 2);
         eqt = s2.equals(s) && s.equals(s2);
-        reallyAssert (!eqt);
+        reallyAssert(!eqt);
         timer.finish();
 
         timer.start("Iter HashCode          ", size * 2);
         int s1h = s.hashCode();
         int s2h = s2.hashCode();
-        reallyAssert (s1h != s2h);
+        reallyAssert(s1h != s2h);
         timer.finish();
 
         s2.put(key[size-1], hold);
         timer.start("Remove (iterator)      ", size * 2);
         Iterator s2i = s2.entrySet().iterator();

@@ -453,16 +453,16 @@
         Set es = s.entrySet();
         while (s2i.hasNext())
             es.remove(s2i.next());
         timer.finish();
 
-        reallyAssert (s.isEmpty());
+        reallyAssert(s.isEmpty());
 
         timer.start("Clear                  ", size);
         s2.clear();
         timer.finish();
-        reallyAssert (s2.isEmpty() && s.isEmpty());
+        reallyAssert(s2.isEmpty() && s.isEmpty());
     }
 
     static void stest(Map s, int size) throws Exception {
         if (!(s instanceof Serializable))
             return;

@@ -487,11 +487,11 @@
         long time = endTime - startTime;
 
         System.out.print(time + "ms");
 
         if (s instanceof IdentityHashMap) return;
-        reallyAssert (s.equals(m));
+        reallyAssert(s.equals(m));
     }
 
 
     static void test(Map s, Object[] key) {
         int size = key.length;