29 |
|
static class PDelay implements Delayed { |
30 |
|
int pseudodelay; |
31 |
|
PDelay(int i) { pseudodelay = Integer.MIN_VALUE + i; } |
32 |
< |
public int compareTo(Object y) { |
32 |
> |
public int compareTo(PDelay y) { |
33 |
|
int i = pseudodelay; |
34 |
|
int j = ((PDelay)y).pseudodelay; |
35 |
|
if (i < j) return -1; |
37 |
|
return 0; |
38 |
|
} |
39 |
|
|
40 |
< |
public int compareTo(PDelay y) { |
40 |
> |
public int compareTo(Delayed y) { |
41 |
|
int i = pseudodelay; |
42 |
|
int j = ((PDelay)y).pseudodelay; |
43 |
|
if (i < j) return -1; |
74 |
|
NanoDelay(long i) { |
75 |
|
trigger = System.nanoTime() + i; |
76 |
|
} |
77 |
< |
public int compareTo(Object y) { |
77 |
> |
public int compareTo(NanoDelay y) { |
78 |
|
long i = trigger; |
79 |
|
long j = ((NanoDelay)y).trigger; |
80 |
|
if (i < j) return -1; |
82 |
|
return 0; |
83 |
|
} |
84 |
|
|
85 |
< |
public int compareTo(NanoDelay y) { |
85 |
> |
public int compareTo(Delayed y) { |
86 |
|
long i = trigger; |
87 |
|
long j = ((NanoDelay)y).trigger; |
88 |
|
if (i < j) return -1; |
665 |
|
assertTrue(q.isEmpty()); |
666 |
|
assertEquals(0, q.size()); |
667 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
668 |
< |
q.add(new PDelay(1)); |
668 |
> |
PDelay x = new PDelay(1); |
669 |
> |
q.add(x); |
670 |
|
assertFalse(q.isEmpty()); |
671 |
+ |
assertTrue(q.contains(x)); |
672 |
|
q.clear(); |
673 |
|
assertTrue(q.isEmpty()); |
674 |
|
} |
912 |
|
* drainTo(c) empties queue into another collection c |
913 |
|
*/ |
914 |
|
public void testDrainTo() { |
915 |
< |
DelayQueue q = populatedQueue(SIZE); |
915 |
> |
DelayQueue q = new DelayQueue(); |
916 |
> |
PDelay[] elems = new PDelay[SIZE]; |
917 |
> |
for (int i = 0; i < SIZE; ++i) { |
918 |
> |
elems[i] = new PDelay(i); |
919 |
> |
q.add(elems[i]); |
920 |
> |
} |
921 |
|
ArrayList l = new ArrayList(); |
922 |
|
q.drainTo(l); |
923 |
|
assertEquals(q.size(), 0); |
924 |
< |
assertEquals(l.size(), SIZE); |
924 |
> |
for (int i = 0; i < SIZE; ++i) |
925 |
> |
assertEquals(l.get(i), elems[i]); |
926 |
> |
q.add(elems[0]); |
927 |
> |
q.add(elems[1]); |
928 |
> |
assertFalse(q.isEmpty()); |
929 |
> |
assertTrue(q.contains(elems[0])); |
930 |
> |
assertTrue(q.contains(elems[1])); |
931 |
> |
l.clear(); |
932 |
> |
q.drainTo(l); |
933 |
> |
assertEquals(q.size(), 0); |
934 |
> |
assertEquals(l.size(), 2); |
935 |
> |
for (int i = 0; i < 2; ++i) |
936 |
> |
assertEquals(l.get(i), elems[i]); |
937 |
|
} |
938 |
|
|
939 |
|
/** |