1 |
|
/* |
2 |
|
* Written by Doug Lea and Josh Bloch with assistance from members of |
3 |
|
* JCP JSR-166 Expert Group and released to the public domain, as |
4 |
< |
* explained at http://creativecommons.org/licenses/publicdomain |
4 |
> |
* explained at http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
import java.util.*; |
7 |
|
|
11 |
|
public static void main(String[] args) { |
12 |
|
int numItr = Integer.parseInt(args[1]); |
13 |
|
int setSize = Integer.parseInt(args[2]); |
14 |
< |
Class cl = null; |
14 |
> |
Class<?> cl = null; |
15 |
|
|
16 |
|
try { |
17 |
|
cl = Class.forName(args[0]); |
19 |
|
fail("Class " + args[0] + " not found."); |
20 |
|
} |
21 |
|
|
22 |
< |
boolean synch = (args.length>3); |
22 |
> |
boolean synch = (args.length > 3); |
23 |
|
|
24 |
< |
for (int i=0; i<numItr; i++) { |
24 |
> |
for (int i = 0; i < numItr; i++) { |
25 |
|
Set s1 = newSet(cl, synch); |
26 |
|
AddRandoms(s1, setSize); |
27 |
|
|
78 |
|
} |
79 |
|
|
80 |
|
// Done inefficiently so as to exercise toArray |
81 |
< |
static Set clone(Set s, Class cl, boolean synch) { |
81 |
> |
static Set clone(Set s, Class<?> cl, boolean synch) { |
82 |
|
Set clone = newSet(cl, synch); |
83 |
|
clone.addAll(Arrays.asList(s.toArray())); |
84 |
|
if (!s.equals(clone)) |
90 |
|
return clone; |
91 |
|
} |
92 |
|
|
93 |
< |
static Set newSet(Class cl, boolean synch) { |
93 |
> |
static Set newSet(Class<?> cl, boolean synch) { |
94 |
|
try { |
95 |
|
Set s = (Set) cl.newInstance(); |
96 |
|
if (synch) |
105 |
|
} |
106 |
|
|
107 |
|
static void AddRandoms(Set s, int n) { |
108 |
< |
for (int i=0; i<n; i++) { |
108 |
> |
for (int i = 0; i < n; i++) { |
109 |
|
int r = rnd.nextInt() % n; |
110 |
|
Integer e = new Integer(r < 0 ? -r : r); |
111 |
|
|
113 |
|
boolean prePresent = s.contains(e); |
114 |
|
boolean added = s.add(e); |
115 |
|
if (!s.contains(e)) |
116 |
< |
fail ("Element not present after addition."); |
116 |
> |
fail("Element not present after addition."); |
117 |
|
if (added == prePresent) |
118 |
< |
fail ("added == alreadyPresent"); |
118 |
> |
fail("added == alreadyPresent"); |
119 |
|
int postSize = s.size(); |
120 |
|
if (added && preSize == postSize) |
121 |
< |
fail ("Add returned true, but size didn't change."); |
121 |
> |
fail("Add returned true, but size didn't change."); |
122 |
|
if (!added && preSize != postSize) |
123 |
< |
fail ("Add returned false, but size changed."); |
123 |
> |
fail("Add returned false, but size changed."); |
124 |
|
} |
125 |
|
} |
126 |
|
|