--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2006/04/19 15:10:54 1.2 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2009/11/16 04:57:10 1.5 @@ -11,13 +11,13 @@ import java.io.*; public class ConcurrentSkipListSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } public static Test suite() { return new TestSuite(ConcurrentSkipListSetTest.class); } - static class MyReverseComparator implements Comparator { + static class MyReverseComparator implements Comparator { public int compare(Object x, Object y) { int i = ((Integer)x).intValue(); int j = ((Integer)y).intValue(); @@ -34,9 +34,9 @@ public class ConcurrentSkipListSetTest e private ConcurrentSkipListSet populatedSet(int n) { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); - for(int i = n-1; i >= 0; i-=2) + for (int i = n-1; i >= 0; i-=2) assertTrue(q.add(new Integer(i))); - for(int i = (n & 1); i < n; i+=2) + for (int i = (n & 1); i < n; i+=2) assertTrue(q.add(new Integer(i))); assertFalse(q.isEmpty()); assertEquals(n, q.size()); @@ -57,7 +57,7 @@ public class ConcurrentSkipListSetTest e assertEquals(5, q.size()); return q; } - + /** * A new set has unbounded capacity */ @@ -172,7 +172,7 @@ public class ConcurrentSkipListSetTest e ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.add(null); shouldThrow(); - } catch (NullPointerException success) { } + } catch (NullPointerException success) { } } /** @@ -204,7 +204,7 @@ public class ConcurrentSkipListSetTest e q.add(new Object()); shouldThrow(); } - catch(ClassCastException success) {} + catch (ClassCastException success) {} } /** @@ -301,7 +301,7 @@ public class ConcurrentSkipListSetTest e } assertTrue(q.isEmpty()); } - + /** * contains(x) reports true when elements added but not yet removed */ @@ -377,7 +377,7 @@ public class ConcurrentSkipListSetTest e } } - + /** * lower returns preceding element @@ -462,7 +462,7 @@ public class ConcurrentSkipListSetTest e ConcurrentSkipListSet q = populatedSet(SIZE); Object[] o = q.toArray(); Arrays.sort(o); - for(int i = 0; i < o.length; i++) + for (int i = 0; i < o.length; i++) assertEquals(o[i], q.pollFirst()); } @@ -474,10 +474,10 @@ public class ConcurrentSkipListSetTest e Integer[] ints = new Integer[SIZE]; ints = (Integer[])q.toArray(ints); Arrays.sort(ints); - for(int i = 0; i < ints.length; i++) + for (int i = 0; i < ints.length; i++) assertEquals(ints[i], q.pollFirst()); } - + /** * iterator iterates through all elements */ @@ -485,7 +485,7 @@ public class ConcurrentSkipListSetTest e ConcurrentSkipListSet q = populatedSet(SIZE); int i = 0; Iterator it = q.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } @@ -499,7 +499,7 @@ public class ConcurrentSkipListSetTest e ConcurrentSkipListSet q = new ConcurrentSkipListSet(); int i = 0; Iterator it = q.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } @@ -535,10 +535,10 @@ public class ConcurrentSkipListSetTest e for (int i = 0; i < SIZE; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } /** - * A deserialized serialized set has same elements + * A deserialized serialized set has same elements */ public void testSerialization() { ConcurrentSkipListSet q = populatedSet(SIZE); @@ -552,9 +552,9 @@ public class ConcurrentSkipListSetTest e ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject(); assertEquals(q.size(), r.size()); - while (!q.isEmpty()) + while (!q.isEmpty()) assertEquals(q.pollFirst(), r.pollFirst()); - } catch(Exception e){ + } catch (Exception e){ e.printStackTrace(); unexpectedException(); } @@ -700,7 +700,7 @@ public class ConcurrentSkipListSetTest e check(set, 0, setSize - 1, true); check(set.descendingSet(), 0, setSize - 1, false); - bashSubSet(set.navigableSubSet(0, true, setSize, false), + bashSubSet(set.subSet(0, true, setSize, false), 0, setSize - 1, true); } @@ -708,7 +708,7 @@ public class ConcurrentSkipListSetTest e NavigableSet result = null; try { result = (NavigableSet) cl.newInstance(); - } catch(Exception e) { + } catch (Exception e) { fail(); } assertEquals(result.size(), 0); @@ -733,7 +733,7 @@ public class ConcurrentSkipListSetTest e } // Remove a bunch of entries with iterator - for(Iterator it = set.iterator(); it.hasNext(); ) { + for (Iterator it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -758,7 +758,7 @@ public class ConcurrentSkipListSetTest e } // Remove a bunch of entries with iterator - for(Iterator it = set.iterator(); it.hasNext(); ) { + for (Iterator it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -774,7 +774,7 @@ public class ConcurrentSkipListSetTest e try { set.add(element); fail(); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // expected } } @@ -807,7 +807,7 @@ public class ConcurrentSkipListSetTest e // headSet - pick direction and endpoint inclusion randomly boolean incl = rnd.nextBoolean(); - NavigableSet hm = set.navigableHeadSet(midPoint, incl); + NavigableSet hm = set.headSet(midPoint, incl); if (ascending) { if (rnd.nextBoolean()) bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true); @@ -824,7 +824,7 @@ public class ConcurrentSkipListSetTest e // tailSet - pick direction and endpoint inclusion randomly incl = rnd.nextBoolean(); - NavigableSet tm = set.navigableTailSet(midPoint,incl); + NavigableSet tm = set.tailSet(midPoint,incl); if (ascending) { if (rnd.nextBoolean()) bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true); @@ -849,7 +849,7 @@ public class ConcurrentSkipListSetTest e boolean lowIncl = rnd.nextBoolean(); boolean highIncl = rnd.nextBoolean(); if (ascending) { - NavigableSet sm = set.navigableSubSet( + NavigableSet sm = set.subSet( endpoints[0], lowIncl, endpoints[1], highIncl); if (rnd.nextBoolean()) bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1), @@ -858,7 +858,7 @@ public class ConcurrentSkipListSetTest e bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1), endpoints[1] - (highIncl ? 0 : 1), false); } else { - NavigableSet sm = set.navigableSubSet( + NavigableSet sm = set.subSet( endpoints[1], highIncl, endpoints[0], lowIncl); if (rnd.nextBoolean()) bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1), @@ -976,13 +976,13 @@ public class ConcurrentSkipListSetTest e try { set.first(); fail(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } try { set.last(); fail(); - } catch(NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } }