--- jsr166/src/test/loops/IntMapCheck.java 2010/09/01 07:47:27 1.9 +++ jsr166/src/test/loops/IntMapCheck.java 2016/10/23 03:03:23 1.15 @@ -1,14 +1,14 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ /** * @test * @synopsis Times and checks basic map operations */ -import java.util.*; import java.io.*; +import java.util.*; public class IntMapCheck { static int absentSize; @@ -22,7 +22,7 @@ public class IntMapCheck { } public static void main(String[] args) throws Exception { - Class mapClass = java.util.concurrent.ConcurrentHashMap.class; + Class mapClass = java.util.concurrent.ConcurrentHashMap.class; int numTests = 50; int size = 75000; @@ -34,7 +34,6 @@ public class IntMapCheck { } } - if (args.length > 1) numTests = Integer.parseInt(args[1]); @@ -68,21 +67,18 @@ public class IntMapCheck { TestTimer.printStats(); - if (doSerializeTest) stest(newMap(mapClass), size); } - static Map newMap(Class cl) { + static Map newMap(Class cl) { try { - Map m = (Map)cl.newInstance(); - return m; + return (Map) cl.getConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Can't instantiate " + cl + ": " + e); } } - static void runTest(Map s, Integer[] key) { int size = key.length; long startTime = System.nanoTime(); @@ -115,7 +111,6 @@ public class IntMapCheck { reallyAssert(sum == expect * iters); } - static void t2(String nm, int n, Map s, Integer[] key, int expect) { int sum = 0; timer.start(nm, n); @@ -190,7 +185,6 @@ public class IntMapCheck { reallyAssert(sum == expect); } - static void t9(Map s) { int sum = 0; int iters = 20; @@ -202,7 +196,6 @@ public class IntMapCheck { reallyAssert(sum != 0); } - static void ktest(Map s, int size, Integer[] key) { timer.start("ContainsKey ", size); Set ks = s.keySet(); @@ -214,7 +207,6 @@ public class IntMapCheck { reallyAssert(sum == size); } - static void ittest1(Map s, int size) { int sum = 0; timer.start("Iter Key ", size); @@ -286,7 +278,6 @@ public class IntMapCheck { reallyAssert(s.size() == size); } - static void ittest(Map s, int size) { for (int i = 0; i < 4; ++i) { ittest1(s, size); @@ -320,7 +311,6 @@ public class IntMapCheck { reallyAssert(sum == size); } - static void entest3(Hashtable ht, int size) { int sum = 0; @@ -399,7 +389,6 @@ public class IntMapCheck { reallyAssert(s.equals(m)); } - static void test(Map s, Integer[] key) { int size = key.length; @@ -449,9 +438,10 @@ public class IntMapCheck { t3("Put (presized) ", size, s, key, size); timer.start("Put (putAll) ", size * 2); - Map s2 = null; + final Map s2; try { - s2 = (Map) (s.getClass().newInstance()); + s2 = (Map) + s.getClass().getConstructor().newInstance(); s2.putAll(s); } catch (Exception e) { e.printStackTrace(); return; } @@ -551,7 +541,6 @@ public class IntMapCheck { startTime = System.nanoTime(); } - String classify() { if (name.startsWith("Get")) return "Get "; @@ -607,7 +596,7 @@ public class IntMapCheck { static void shuffle(Integer[] keys) { int size = keys.length; - for (int i=size; i>1; i--) { + for (int i = size; i > 1; i--) { int r = rng.nextInt(i); Integer t = keys[i-1]; keys[i-1] = keys[r];