1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
– |
import java.util.*; |
6 |
|
import java.io.*; |
7 |
+ |
import java.util.*; |
8 |
|
|
9 |
|
public class CollectionWordLoops { |
10 |
|
|
23 |
|
static final int numTests = 2; |
24 |
|
|
25 |
|
public static void main(String[] args) { |
26 |
< |
Class collectionClass = null; |
26 |
> |
Class<?> collectionClass = null; |
27 |
|
try { |
28 |
|
collectionClass = Class.forName(args[0]); |
29 |
|
} catch (ClassNotFoundException e) { |
37 |
|
|
38 |
|
for (int s = WORDS_FILES.length-1; s >= 0; --s) |
39 |
|
tests(collectionClass, numTests, s); |
40 |
– |
|
40 |
|
} |
41 |
|
|
42 |
< |
static void tests(Class collectionClass, int numTests, int sizeIndex) { |
42 |
> |
static void tests(Class<?> collectionClass, int numTests, int sizeIndex) { |
43 |
|
try { |
44 |
|
String[] key = readWords(sizeIndex); |
45 |
|
int size = key.length; |
62 |
|
} |
63 |
|
} |
64 |
|
|
65 |
< |
|
67 |
< |
static Collection<String> newCollection(Class cl) { |
65 |
> |
static Collection<String> newCollection(Class<?> cl) { |
66 |
|
try { |
67 |
< |
Collection m = (Collection<String>)cl.newInstance(); |
70 |
< |
return m; |
67 |
> |
return (Collection<String>) cl.getConstructor().newInstance(); |
68 |
|
} catch (Exception e) { |
69 |
|
throw new RuntimeException("Can't instantiate " + cl + ": " + e); |
70 |
|
} |
111 |
|
long startTime = System.currentTimeMillis(); |
112 |
|
runner.run(); |
113 |
|
long afterRun = System.currentTimeMillis(); |
114 |
< |
long runTime = (afterRun - startTime); |
114 |
> |
long runTime = afterRun - startTime; |
115 |
|
int np = runner.total; |
116 |
|
if (runner.total == runner.hashCode()) |
117 |
|
System.out.println("Useless Number" + runner.total); |
122 |
|
return runTime; |
123 |
|
} |
124 |
|
|
128 |
– |
|
125 |
|
static class Runner implements Runnable { |
126 |
|
final Collection<String> collection; |
127 |
|
final String[] key; |
141 |
|
pctins = (int)(((long)pinsert * (long)(Integer.MAX_VALUE/2)) / 50); |
142 |
|
} |
143 |
|
|
148 |
– |
|
144 |
|
int oneStep(int j) { |
145 |
|
int n = key.length; |
146 |
|
int r = rng.next() & 0x7FFFFFFF; |
168 |
|
if (r < pctrem) { |
169 |
|
collection.remove(k); |
170 |
|
++nremoves; |
171 |
< |
j += ((r >>> 8) & 7) + n / 2; |
171 |
> |
j += ((r >>> 8) & 7) + n / 2; |
172 |
|
if (j >= n) j -= n; |
173 |
|
} |
174 |
|
} |