1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
|
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import java.io.*; |
9 |
> |
import java.util.concurrent.ConcurrentSkipListMap; |
10 |
|
|
11 |
|
public class ConcurrentSkipListMapTest extends JSR166TestCase { |
12 |
|
public static void main(String[] args) { |
118 |
|
assertEquals(five, map.lastKey()); |
119 |
|
} |
120 |
|
|
122 |
– |
|
121 |
|
/** |
122 |
|
* keySet.toArray returns contains all keys |
123 |
|
*/ |
380 |
|
assertEquals("Z", map.get(one)); |
381 |
|
} |
382 |
|
|
385 |
– |
|
383 |
|
/** |
384 |
|
* replace value fails when the given key not mapped to expected value |
385 |
|
*/ |
400 |
|
assertEquals("Z", map.get(one)); |
401 |
|
} |
402 |
|
|
406 |
– |
|
403 |
|
/** |
404 |
|
* remove removes the correct key-value pair from the map |
405 |
|
*/ |
501 |
|
* lowerEntry, higherEntry, ceilingEntry, and floorEntry return |
502 |
|
* immutable entries |
503 |
|
*/ |
504 |
< |
public void testEntryImmutablity() { |
504 |
> |
public void testEntryImmutability() { |
505 |
|
ConcurrentSkipListMap map = map5(); |
506 |
|
Map.Entry e = map.lowerEntry(three); |
507 |
|
assertEquals(two, e.getKey()); |
529 |
|
} catch (UnsupportedOperationException success) {} |
530 |
|
} |
531 |
|
|
536 |
– |
|
537 |
– |
|
532 |
|
/** |
533 |
|
* lowerKey returns preceding element |
534 |
|
*/ |
672 |
|
ConcurrentSkipListMap map = map5(); |
673 |
|
String s = map.toString(); |
674 |
|
for (int i = 1; i <= 5; ++i) { |
675 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
675 |
> |
assertTrue(s.contains(String.valueOf(i))); |
676 |
|
} |
677 |
|
} |
678 |
|
|
711 |
|
} catch (NullPointerException success) {} |
712 |
|
} |
713 |
|
|
720 |
– |
|
714 |
|
/** |
715 |
|
* put(null,x) throws NPE |
716 |
|
*/ |
792 |
|
* A deserialized map equals original |
793 |
|
*/ |
794 |
|
public void testSerialization() throws Exception { |
795 |
< |
ConcurrentSkipListMap q = map5(); |
795 |
> |
NavigableMap x = map5(); |
796 |
> |
NavigableMap y = serialClone(x); |
797 |
|
|
798 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
799 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
800 |
< |
out.writeObject(q); |
801 |
< |
out.close(); |
802 |
< |
|
809 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
810 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
811 |
< |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
812 |
< |
assertEquals(q.size(), r.size()); |
813 |
< |
assertTrue(q.equals(r)); |
814 |
< |
assertTrue(r.equals(q)); |
798 |
> |
assertTrue(x != y); |
799 |
> |
assertEquals(x.size(), y.size()); |
800 |
> |
assertEquals(x.toString(), y.toString()); |
801 |
> |
assertEquals(x, y); |
802 |
> |
assertEquals(y, x); |
803 |
|
} |
804 |
|
|
817 |
– |
|
818 |
– |
|
805 |
|
/** |
806 |
|
* subMap returns map with keys in requested range |
807 |
|
*/ |
1147 |
|
*/ |
1148 |
|
void check(NavigableMap<Integer, Integer> map, |
1149 |
|
final int min, final int max, final boolean ascending) { |
1150 |
< |
class ReferenceSet { |
1150 |
> |
class ReferenceSet { |
1151 |
|
int lower(int key) { |
1152 |
|
return ascending ? lowerAscending(key) : higherAscending(key); |
1153 |
|
} |