--- jsr166/src/test/loops/CollectionWordLoops.java 2009/11/02 23:51:32 1.5 +++ jsr166/src/test/loops/CollectionWordLoops.java 2016/10/23 03:03:23 1.12 @@ -1,10 +1,10 @@ /* * 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/ */ -import java.util.*; import java.io.*; +import java.util.*; public class CollectionWordLoops { @@ -23,7 +23,7 @@ public class CollectionWordLoops { static final int numTests = 2; public static void main(String[] args) { - Class collectionClass = null; + Class collectionClass = null; try { collectionClass = Class.forName(args[0]); } catch (ClassNotFoundException e) { @@ -37,10 +37,9 @@ public class CollectionWordLoops { for (int s = WORDS_FILES.length-1; s >= 0; --s) tests(collectionClass, numTests, s); - } - static void tests(Class collectionClass, int numTests, int sizeIndex) { + static void tests(Class collectionClass, int numTests, int sizeIndex) { try { String[] key = readWords(sizeIndex); int size = key.length; @@ -63,11 +62,9 @@ public class CollectionWordLoops { } } - - static Collection newCollection(Class cl) { + static Collection newCollection(Class cl) { try { - Collection m = (Collection) cl.newInstance(); - return m; + return (Collection) cl.getConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Can't instantiate " + cl + ": " + e); } @@ -114,7 +111,7 @@ public class CollectionWordLoops { long startTime = System.currentTimeMillis(); runner.run(); long afterRun = System.currentTimeMillis(); - long runTime = (afterRun - startTime); + long runTime = afterRun - startTime; int np = runner.total; if (runner.total == runner.hashCode()) System.out.println("Useless Number" + runner.total); @@ -125,7 +122,6 @@ public class CollectionWordLoops { return runTime; } - static class Runner implements Runnable { final Collection collection; final String[] key; @@ -145,7 +141,6 @@ public class CollectionWordLoops { pctins = (int)(((long)pinsert * (long)(Integer.MAX_VALUE/2)) / 50); } - int oneStep(int j) { int n = key.length; int r = rng.next() & 0x7FFFFFFF; @@ -173,7 +168,7 @@ public class CollectionWordLoops { if (r < pctrem) { collection.remove(k); ++nremoves; - j += ((r >>> 8) & 7) + n / 2; + j += ((r >>> 8) & 7) + n / 2; if (j >= n) j -= n; } }