--- jsr166/src/test/loops/ListBash.java 2009/10/29 23:09:07 1.6 +++ jsr166/src/test/loops/ListBash.java 2013/07/14 22:29:33 1.14 @@ -1,7 +1,7 @@ /* * Written by Josh Bloch and 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 + * explained at http://creativecommons.org/publicdomain/zero/1.0/ */ import java.util.*; @@ -19,13 +19,13 @@ public class ListBash { listSize = Integer.parseInt(args[2]); cl = null; - try { - cl = Class.forName(args[0]); - } catch(ClassNotFoundException e) { - fail("Class " + args[0] + " not found."); - } + try { + cl = Class.forName(args[0]); + } catch (ClassNotFoundException e) { + fail("Class " + args[0] + " not found."); + } - synch = (args.length>3); + synch = (args.length > 3); oneRun(); oneRun(); oneRun(); @@ -33,14 +33,14 @@ public class ListBash { static void oneRun() { long startTime = System.nanoTime(); - for (int i=0; i s = newList(cl, synch); - for (int i=0; i s = newList(cl, synch); + for (int i = 0; i < listSize; i++) + s.add(new Integer(i)); + if (s.size() != listSize) + fail("Size of [0..n-1] != n"); evenOdd(s); sublists(s); arrays(); @@ -67,10 +67,10 @@ public class ListBash { if (!(s1.equals(s2) && s2.equals(s1))) fail("addAll(int, Collection) doesn't work."); // Reverse List - for (int j=0, n=s1.size(); j itAll = all.listIterator(all.size()); ListIterator itEven = even.listIterator(even.size()); while (itEven.hasPrevious()) { @@ -189,8 +189,8 @@ public class ListBash { } itAll = all.listIterator(); it = s.iterator(); - while(it.hasNext()) - if(it.next()==itAll.next()) + while (it.hasNext()) + if (it.next()==itAll.next()) fail("Iterator.set failed to change value."); } if (!all.equals(s)) @@ -205,7 +205,7 @@ public class ListBash { Object o = it.next(); if (all.indexOf(o) != all.lastIndexOf(o)) fail("Apparent duplicate detected."); - if (all.subList(i, all.size()).indexOf(o) != 0) { + if (all.subList(i, all.size()).indexOf(o) != 0) { System.out.println("s0: " + all.subList(i, all.size()).indexOf(o)); fail("subList/indexOf is screwy."); } @@ -224,16 +224,16 @@ public class ListBash { static void arrays() { List l = newList(cl, synch); AddRandoms(l, listSize); - Integer[] ia = (Integer[]) l.toArray(new Integer[0]); + Integer[] ia = l.toArray(new Integer[0]); if (!l.equals(Arrays.asList(ia))) fail("toArray(Object[]) is hosed (1)"); ia = new Integer[listSize]; - Integer[] ib = (Integer[]) l.toArray(ia); + Integer[] ib = l.toArray(ia); if (ia != ib || !l.equals(Arrays.asList(ia))) fail("toArray(Object[]) is hosed (2)"); ia = new Integer[listSize+1]; ia[listSize] = new Integer(69); - ib = (Integer[]) l.toArray(ia); + ib = l.toArray(ia); if (ia != ib || ia[listSize] != null || !l.equals(Arrays.asList(ia).subList(0, listSize))) fail("toArray(Object[]) is hosed (3)"); @@ -245,48 +245,48 @@ public class ListBash { if (s.hashCode() != a.hashCode()) fail("Incorrect hashCode computation."); - List clone = newList(cl, synch); - clone.addAll(a); - if (!s.equals(clone)) - fail("List not equal to copy."); - if (!s.containsAll(clone)) - fail("List does not contain copy."); - if (!clone.containsAll(s)) - fail("Copy does not contain list."); + List clone = newList(cl, synch); + clone.addAll(a); + if (!s.equals(clone)) + fail("List not equal to copy."); + if (!s.containsAll(clone)) + fail("List does not contain copy."); + if (!clone.containsAll(s)) + fail("Copy does not contain list."); - return (List)clone; + return (List) clone; } static List newList(Class cl, boolean synch) { - try { - List s = (List)cl.newInstance(); + try { + List s = (List) cl.newInstance(); if (synch) s = Collections.synchronizedList(s); - if (!s.isEmpty()) - fail("New instance non empty."); - return s; - } catch(Throwable t) { - fail("Can't instantiate " + cl + ": " + t); - } - return null; //Shut up compiler. + if (!s.isEmpty()) + fail("New instance non empty."); + return s; + } catch (Throwable t) { + fail("Can't instantiate " + cl + ": " + t); + } + return null; //Shut up compiler. } static void AddRandoms(List s, int n) { - for (int i=0; i