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

Comparing jsr166/src/test/tck/DelayQueueTest.java (file contents):
Revision 1.54 by jsr166, Tue May 31 16:16:23 2011 UTC vs.
Revision 1.62 by jsr166, Thu May 30 03:28:55 2013 UTC

# Line 49 | Line 49 | public class DelayQueueTest extends JSR1
49       */
50      static class PDelay implements Delayed {
51          int pseudodelay;
52 <        PDelay(int i) { pseudodelay = Integer.MIN_VALUE + i; }
53 <        public int compareTo(PDelay y) {
54 <            int i = pseudodelay;
55 <            int j = y.pseudodelay;
56 <            if (i < j) return -1;
57 <            if (i > j) return 1;
58 <            return 0;
52 >        PDelay(int i) { pseudodelay = i; }
53 >        public int compareTo(PDelay other) {
54 >            int a = this.pseudodelay;
55 >            int b = other.pseudodelay;
56 >            return (a < b) ? -1 : (a > b) ? 1 : 0;
57          }
60
58          public int compareTo(Delayed y) {
59              return compareTo((PDelay)y);
60          }
64
61          public boolean equals(Object other) {
62 <            return equals((PDelay)other);
63 <        }
68 <        public boolean equals(PDelay other) {
69 <            return other.pseudodelay == pseudodelay;
62 >            return (other instanceof PDelay) &&
63 >                this.pseudodelay == ((PDelay)other).pseudodelay;
64          }
65 <
65 >        // suppress [overrides] javac warning
66 >        public int hashCode() { return pseudodelay; }
67          public long getDelay(TimeUnit ignore) {
68 <            return pseudodelay;
74 <        }
75 <        public int intValue() {
76 <            return pseudodelay;
68 >            return Integer.MIN_VALUE + pseudodelay;
69          }
78
70          public String toString() {
71              return String.valueOf(pseudodelay);
72          }
# Line 108 | Line 99 | public class DelayQueueTest extends JSR1
99              return other.trigger == trigger;
100          }
101  
102 +        // suppress [overrides] javac warning
103 +        public int hashCode() { return (int) trigger; }
104 +
105          public long getDelay(TimeUnit unit) {
106              long n = trigger - System.nanoTime();
107              return unit.convert(n, TimeUnit.NANOSECONDS);
# Line 123 | Line 117 | public class DelayQueueTest extends JSR1
117      }
118  
119      /**
120 <     * Create a queue of given size containing consecutive
120 >     * Returns a new queue of given size containing consecutive
121       * PDelays 0 ... n.
122       */
123      private DelayQueue<PDelay> populatedQueue(int n) {
# Line 493 | Line 487 | public class DelayQueueTest extends JSR1
487      }
488  
489      /**
496     * remove(x) removes x and returns true if present
497     */
498    public void testRemoveElement() {
499        DelayQueue q = populatedQueue(SIZE);
500        for (int i = 1; i < SIZE; i+=2) {
501            assertTrue(q.remove(new PDelay(i)));
502        }
503        for (int i = 0; i < SIZE; i+=2) {
504            assertTrue(q.remove(new PDelay(i)));
505            assertFalse(q.remove(new PDelay(i+1)));
506        }
507        assertTrue(q.isEmpty());
508    }
509
510    /**
490       * contains(x) reports true when elements added but not yet removed
491       */
492      public void testContains() {
# Line 646 | Line 625 | public class DelayQueueTest extends JSR1
625          it.next();
626          it.remove();
627          it = q.iterator();
628 <        assertEquals(it.next(), new PDelay(2));
629 <        assertEquals(it.next(), new PDelay(3));
628 >        assertEquals(new PDelay(2), it.next());
629 >        assertEquals(new PDelay(3), it.next());
630          assertFalse(it.hasNext());
631      }
632  
# Line 657 | Line 636 | public class DelayQueueTest extends JSR1
636      public void testToString() {
637          DelayQueue q = populatedQueue(SIZE);
638          String s = q.toString();
639 <        for (int i = 0; i < SIZE; ++i) {
640 <            assertTrue(s.contains(String.valueOf(Integer.MIN_VALUE+i)));
662 <        }
639 >        for (Object e : q)
640 >            assertTrue(s.contains(e.toString()));
641      }
642  
643      /**
# Line 673 | Line 651 | public class DelayQueueTest extends JSR1
651              public void realRun() throws InterruptedException {
652                  assertNull(q.poll());
653                  threadsStarted.await();
654 <                assertTrue(null != q.poll(LONG_DELAY_MS, MILLISECONDS));
654 >                assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS));
655                  checkEmpty(q);
656              }});
657  
# Line 745 | Line 723 | public class DelayQueueTest extends JSR1
723          }
724          ArrayList l = new ArrayList();
725          q.drainTo(l);
726 <        assertEquals(q.size(), 0);
726 >        assertEquals(0, q.size());
727          for (int i = 0; i < SIZE; ++i)
728 <            assertEquals(l.get(i), elems[i]);
728 >            assertEquals(elems[i], l.get(i));
729          q.add(elems[0]);
730          q.add(elems[1]);
731          assertFalse(q.isEmpty());
# Line 755 | Line 733 | public class DelayQueueTest extends JSR1
733          assertTrue(q.contains(elems[1]));
734          l.clear();
735          q.drainTo(l);
736 <        assertEquals(q.size(), 0);
737 <        assertEquals(l.size(), 2);
736 >        assertEquals(0, q.size());
737 >        assertEquals(2, l.size());
738          for (int i = 0; i < 2; ++i)
739 <            assertEquals(l.get(i), elems[i]);
739 >            assertEquals(elems[i], l.get(i));
740      }
741  
742      /**
# Line 788 | Line 766 | public class DelayQueueTest extends JSR1
766              ArrayList l = new ArrayList();
767              q.drainTo(l, i);
768              int k = (i < SIZE) ? i : SIZE;
769 <            assertEquals(q.size(), SIZE-k);
770 <            assertEquals(l.size(), k);
769 >            assertEquals(SIZE-k, q.size());
770 >            assertEquals(k, l.size());
771          }
772      }
773  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines