--- jsr166/src/test/loops/NavigableSetCheck.java 2010/09/01 07:47:27 1.7 +++ jsr166/src/test/loops/NavigableSetCheck.java 2016/10/23 03:03:24 1.14 @@ -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 set operations */ -import java.util.*; import java.io.*; +import java.util.*; public class NavigableSetCheck { @@ -25,7 +25,7 @@ public class NavigableSetCheck { } public static void main(String[] args) throws Exception { - Class setClass = null; + Class setClass = null; int numTests = 50; int size = 50000; @@ -37,7 +37,6 @@ public class NavigableSetCheck { } } - if (args.length > 1) numTests = Integer.parseInt(args[1]); @@ -46,7 +45,6 @@ public class NavigableSetCheck { System.out.println("Testing " + setClass.getName() + " trials: " + numTests + " size: " + size); - absentSize = 8; while (absentSize < size) absentSize <<= 1; absentMask = absentSize - 1; @@ -59,25 +57,21 @@ public class NavigableSetCheck { for (int i = 0; i < size; ++i) key[i] = new Integer(i * 2 + 1); - for (int rep = 0; rep < numTests; ++rep) { runTest(newSet(setClass), key); } TestTimer.printStats(); - } - static NavigableSet newSet(Class cl) { + static NavigableSet newSet(Class cl) { try { - NavigableSet m = (NavigableSet) cl.newInstance(); - return m; + return (NavigableSet) cl.getConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Can't instantiate " + cl + ": " + e); } } - static void runTest(NavigableSet s, Integer[] key) { shuffle(key); int size = key.length; @@ -171,7 +165,6 @@ public class NavigableSetCheck { reallyAssert(sum == expect); } - static void higherTest(NavigableSet s) { int sum = 0; int iters = s.size(); @@ -226,7 +219,6 @@ public class NavigableSetCheck { reallyAssert(sum == iters-1); } - static void ktest(NavigableSet s, int size, Integer[] key) { timer.start("Contains ", size); int sum = 0; @@ -237,7 +229,6 @@ public class NavigableSetCheck { reallyAssert(sum == size); } - static void ittest1(NavigableSet s, int size) { int sum = 0; timer.start("Iter Key ", size); @@ -268,7 +259,6 @@ public class NavigableSetCheck { rittest1(s, size); } - static void rtest(NavigableSet s, int size) { timer.start("Remove (iterator) ", size); for (Iterator it = s.iterator(); it.hasNext(); ) { @@ -278,13 +268,11 @@ public class NavigableSetCheck { timer.finish(); } - - static void dtest(NavigableSet s, int size, Integer[] key) { timer.start("Add (addAll) ", size * 2); - NavigableSet s2 = null; + final NavigableSet s2; try { - s2 = (NavigableSet) (s.getClass().newInstance()); + s2 = (NavigableSet) s.getClass().getConstructor().newInstance(); s2.addAll(s); } catch (Exception e) { e.printStackTrace(); return; } @@ -329,8 +317,6 @@ public class NavigableSetCheck { reallyAssert(s2.isEmpty() && s.isEmpty()); } - - static void test(NavigableSet s, Integer[] key) { int size = key.length; @@ -391,7 +377,6 @@ public class NavigableSetCheck { startTime = System.currentTimeMillis(); } - String classify() { if (name.startsWith("Contains")) return "Contains "; @@ -447,7 +432,7 @@ public class NavigableSetCheck { 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];