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.15 by jsr166, Thu Dec 18 18:43:22 2014 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 67 | Line 67 | public class ListBash {
67          if (!(s1.equals(s2) && s2.equals(s1)))
68              fail("addAll(int, Collection) doesn't work.");
69          // Reverse List
70 <        for (int j=0, n=s1.size(); j<n; j++)
70 >        for (int j = 0, n = s1.size(); j < n; j++)
71              s1.set(j, s1.set(n-j-1, s1.get(j)));
72          // Reverse it again
73 <        for (int j=0, n=s1.size(); j<n; j++)
73 >        for (int j = 0, n = s1.size(); j < n; j++)
74              s1.set(j, s1.set(n-j-1, s1.get(j)));
75          if (!(s1.equals(s2) && s2.equals(s1)))
76              fail("set(int, Object) doesn't work");
# Line 174 | Line 174 | public class ListBash {
174              if (!all.equals(s))
175                  fail("Failed to reconstruct ints from odds and evens.");
176  
177 <            all = clone(odd,  cl, synch);
177 >            all = clone(odd, cl, synch);
178              ListIterator<Integer> itAll = all.listIterator(all.size());
179              ListIterator<Integer> itEven = even.listIterator(even.size());
180              while (itEven.hasPrevious()) {
# Line 205 | Line 205 | public class ListBash {
205              Object o = it.next();
206              if (all.indexOf(o) != all.lastIndexOf(o))
207                  fail("Apparent duplicate detected.");
208 <            if (all.subList(i,   all.size()).indexOf(o) != 0) {
208 >            if (all.subList(i, all.size()).indexOf(o) != 0) {
209                  System.out.println("s0: " + all.subList(i,   all.size()).indexOf(o));
210                  fail("subList/indexOf is screwy.");
211              }
# Line 240 | Line 240 | public class ListBash {
240      }
241  
242      // Done inefficiently so as to exercise toArray
243 <    static List<Integer> clone(List s, Class cl, boolean synch) {
243 >    static List<Integer> clone(List s, Class<?> cl, boolean synch) {
244          List a = Arrays.asList(s.toArray());
245          if (s.hashCode() != a.hashCode())
246              fail("Incorrect hashCode computation.");
# Line 257 | Line 257 | public class ListBash {
257          return (List<Integer>) clone;
258      }
259  
260 <    static List<Integer> newList(Class cl, boolean synch) {
260 >    static List<Integer> newList(Class<?> cl, boolean synch) {
261          try {
262              List<Integer> s = (List<Integer>) cl.newInstance();
263              if (synch)
# Line 272 | Line 272 | public class ListBash {
272      }
273  
274      static void AddRandoms(List<Integer> s, int n) {
275 <        for (int i=0; i<n; i++) {
275 >        for (int i = 0; i < n; i++) {
276              int r = rnd.nextInt() % n;
277              Integer e = new Integer(r < 0 ? -r : r);
278  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines