--- jsr166/src/test/loops/DequeBash.java 2009/10/29 23:09:07 1.3 +++ jsr166/src/test/loops/DequeBash.java 2009/11/16 04:57:09 1.5 @@ -26,14 +26,14 @@ public class DequeBash { static int random(int bound) { int x = seed; int t = (x % 127773) * 16807 - (x / 127773) * 2836; - seed = (t > 0)? t : t + 0x7fffffff; + seed = (t > 0) ? t : t + 0x7fffffff; return (t & 0x7fffffff) % bound; } static int random() { int x = seed; int t = (x % 127773) * 16807 - (x / 127773) * 2836; - seed = (t > 0)? t : t + 0x7fffffff; + seed = (t > 0) ? t : t + 0x7fffffff; return (t & 0x7fffffff); } @@ -157,9 +157,9 @@ public class DequeBash { static void randomOp(Deque deque) throws Exception { // Perform a random operation - switch(random() & 3) { + switch (random() & 3) { case 0: - switch(random() & 3) { + switch (random() & 3) { case 0: deque.addLast(nextTail++); break; case 1: deque.offerLast(nextTail++); break; case 2: deque.offer(nextTail++); break; @@ -172,20 +172,20 @@ public class DequeBash { int result = 666; boolean threw = false; try { - switch(random(3)) { + switch (random(3)) { case 0: result = deque.removeFirst(); break; case 1: result = deque.remove(); break; case 2: result = deque.pop(); break; default: throw new Exception("How'd we get here"); } - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { threw = true; } if (!threw) throw new Exception("Remove-no exception: " + result); } else { // deque nonempty int result = -1; - switch(random(5)) { + switch (random(5)) { case 0: result = deque.removeFirst(); break; case 1: result = deque.remove(); break; case 2: result = deque.pop(); break; @@ -199,7 +199,7 @@ public class DequeBash { } break; case 2: - switch(random(3)) { + switch (random(3)) { case 0: deque.addFirst(nextHead--); break; case 1: deque.offerFirst(nextHead--); break; case 2: deque.push(nextHead--); break; @@ -212,17 +212,17 @@ public class DequeBash { boolean threw = false; try { result = deque.removeLast(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { threw = true; } if (!threw) throw new Exception("Remove-no exception: " + result); } else { // deque nonempty - int result = ((random() & 1) == 0? + int result = ((random() & 1) == 0 ? deque.removeLast() : deque.pollLast()); if (result != --nextTail) throw new Exception( - "Removed "+ result + " expecting "+(nextTail + 1)); + "Removed "+ result + " expecting "+(nextTail + 1)); } break; default: @@ -237,16 +237,16 @@ public class DequeBash { if (d1.size() != d2.size()) throw new Exception("Size " + d1.size() + " != " + d2.size()); Iterator it = d2.iterator(); - for(int i : d1) { + for (int i : d1) { int j = it.next(); if (j != i) throw new Exception("Element " + j + " != " + i); } - for(int i : d1) + for (int i : d1) if (!d2.contains(i)) throw new Exception("d2 doesn't contain " + i); - for(int i : d2) + for (int i : d2) if (!d1.contains(i)) throw new Exception("d2 doesn't contain " + i); @@ -280,14 +280,14 @@ public class DequeBash { bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bin); return (T) ois.readObject(); - } catch(Exception e) { + } catch (Exception e) { throw new IllegalArgumentException(e); } } private static void testRemove(Deque deque) throws Exception { Deque copy = null; - switch(random() & 1) { + switch (random() & 1) { case 0: copy = (Deque) deque.getClass(). getConstructor(Collection.class).newInstance(deque); @@ -320,7 +320,7 @@ public class DequeBash { throw new Exception(e + " missing."); boolean removed = false; - switch(random(3)) { + switch (random(3)) { case 0: removed = copy.remove(e); break; case 1: removed = copy.removeFirstOccurrence(e); break; case 2: removed = copy.removeLastOccurrence(e); break; @@ -368,9 +368,9 @@ public class DequeBash { boolean threw = false; int result = 666; try { - result = ((random() & 1) == 0? + result = ((random() & 1) == 0 ? deque.getFirst() : deque.element()); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { threw = true; } if (!threw) @@ -378,7 +378,7 @@ public class DequeBash { threw = false; try { result = deque.getLast(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { threw = true; } if (!threw)