ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/ListBash.java
(Generate patch)

Comparing jsr166/src/test/loops/ListBash.java (file contents):
Revision 1.11 by jsr166, Wed Sep 1 07:47:27 2010 UTC vs.
Revision 1.17 by jsr166, Sun Oct 23 03:03:23 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Josh Bloch and Doug Lea 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  
7   import java.util.*;
# Line 12 | Line 12 | public class ListBash {
12      static int numItr;
13      static int listSize;
14      static boolean synch;
15 <    static Class cl;
15 >    static Class<?> cl;
16  
17      public static void main(String[] args) {
18          numItr = Integer.parseInt(args[1]);
# Line 25 | Line 25 | public class ListBash {
25              fail("Class " + args[0] + " not found.");
26          }
27  
28 <        synch = (args.length>3);
28 >        synch = (args.length > 3);
29          oneRun();
30          oneRun();
31          oneRun();
# Line 33 | Line 33 | public class ListBash {
33  
34      static void oneRun() {
35          long startTime = System.nanoTime();
36 <        for (int i=0; i<numItr; i++) {
36 >        for (int i = 0; i < numItr; i++) {
37              elementLoop();
38          }
39          List<Integer> s = newList(cl, synch);
40 <        for (int i=0; i<listSize; i++)
40 >        for (int i = 0; i < listSize; i++)
41              s.add(new Integer(i));
42          if (s.size() != listSize)
43              fail("Size of [0..n-1] != n");
# Line 48 | Line 48 | public class ListBash {
48          System.out.println("Time: " + (elapsed/1000000000.0) + "s");
49      }
50  
51
52
51      static void elementLoop() {
52          List<Integer> s1 = newList(cl, synch);
53          AddRandoms(s1, listSize);
# Line 67 | Line 65 | public class ListBash {
65          if (!(s1.equals(s2) && s2.equals(s1)))
66              fail("addAll(int, Collection) doesn't work.");
67          // Reverse List
68 <        for (int j=0, n=s1.size(); j<n; j++)
68 >        for (int j = 0, n = s1.size(); j < n; j++)
69              s1.set(j, s1.set(n-j-1, s1.get(j)));
70          // Reverse it again
71 <        for (int j=0, n=s1.size(); j<n; j++)
71 >        for (int j = 0, n = s1.size(); j < n; j++)
72              s1.set(j, s1.set(n-j-1, s1.get(j)));
73          if (!(s1.equals(s2) && s2.equals(s1)))
74              fail("set(int, Object) doesn't work");
# Line 174 | Line 172 | public class ListBash {
172              if (!all.equals(s))
173                  fail("Failed to reconstruct ints from odds and evens.");
174  
175 <            all = clone(odd,  cl, synch);
175 >            all = clone(odd, cl, synch);
176              ListIterator<Integer> itAll = all.listIterator(all.size());
177              ListIterator<Integer> itEven = even.listIterator(even.size());
178              while (itEven.hasPrevious()) {
# Line 205 | Line 203 | public class ListBash {
203              Object o = it.next();
204              if (all.indexOf(o) != all.lastIndexOf(o))
205                  fail("Apparent duplicate detected.");
206 <            if (all.subList(i,   all.size()).indexOf(o) != 0) {
206 >            if (all.subList(i, all.size()).indexOf(o) != 0) {
207                  System.out.println("s0: " + all.subList(i,   all.size()).indexOf(o));
208                  fail("subList/indexOf is screwy.");
209              }
# Line 240 | Line 238 | public class ListBash {
238      }
239  
240      // Done inefficiently so as to exercise toArray
241 <    static List<Integer> clone(List s, Class cl, boolean synch) {
241 >    static List<Integer> clone(List s, Class<?> cl, boolean synch) {
242          List a = Arrays.asList(s.toArray());
243          if (s.hashCode() != a.hashCode())
244              fail("Incorrect hashCode computation.");
# Line 257 | Line 255 | public class ListBash {
255          return (List<Integer>) clone;
256      }
257  
258 <    static List<Integer> newList(Class cl, boolean synch) {
258 >    static List<Integer> newList(Class<?> cl, boolean synch) {
259          try {
260 <            List<Integer> s = (List<Integer>) cl.newInstance();
260 >            List<Integer> s = (List<Integer>) cl.getConstructor().newInstance();
261              if (synch)
262                  s = Collections.synchronizedList(s);
263              if (!s.isEmpty())
# Line 272 | Line 270 | public class ListBash {
270      }
271  
272      static void AddRandoms(List<Integer> s, int n) {
273 <        for (int i=0; i<n; i++) {
273 >        for (int i = 0; i < n; i++) {
274              int r = rnd.nextInt() % n;
275              Integer e = new Integer(r < 0 ? -r : r);
276  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines