concurrentskiplistmaptest.java
来自「SRI international 发布的OAA框架软件」· Java 代码 · 共 891 行 · 第 1/2 页
JAVA
891 行
/*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/licenses/publicdomain
*/
import junit.framework.*;
import java.util.*;
import edu.emory.mathcs.backport.java.util.concurrent.*;
import java.io.*;
public class ConcurrentSkipListMapTest extends JSR166TestCase {
// public static void main(String[] args) {
// junit.textui.TestRunner.run (suite());
// }
// public static Test suite() {
// return new TestSuite(ConcurrentSkipListMapTest.class);
// }
//
// /**
// * Create a map from Integers 1-5 to Strings "A"-"E".
// */
// private static ConcurrentSkipListMap map5() {
// ConcurrentSkipListMap map = new ConcurrentSkipListMap();
// assertTrue(map.isEmpty());
// map.put(one, "A");
// map.put(five, "E");
// map.put(three, "C");
// map.put(two, "B");
// map.put(four, "D");
// assertFalse(map.isEmpty());
// assertEquals(5, map.size());
// return map;
// }
//
// /**
// * clear removes all pairs
// */
// public void testClear() {
// ConcurrentSkipListMap map = map5();
// map.clear();
// assertEquals(map.size(), 0);
// }
//
// /**
// *
// */
// public void testConstructFromSorted() {
// ConcurrentSkipListMap map = map5();
// ConcurrentSkipListMap map2 = new ConcurrentSkipListMap(map);
// assertEquals(map, map2);
// }
//
// /**
// * Maps with same contents are equal
// */
// public void testEquals() {
// ConcurrentSkipListMap map1 = map5();
// ConcurrentSkipListMap map2 = map5();
// assertEquals(map1, map2);
// assertEquals(map2, map1);
// map1.clear();
// assertFalse(map1.equals(map2));
// assertFalse(map2.equals(map1));
// }
//
// /**
// * containsKey returns true for contained key
// */
// public void testContainsKey() {
// ConcurrentSkipListMap map = map5();
// assertTrue(map.containsKey(one));
// assertFalse(map.containsKey(zero));
// }
//
// /**
// * containsValue returns true for held values
// */
// public void testContainsValue() {
// ConcurrentSkipListMap map = map5();
// assertTrue(map.containsValue("A"));
// assertFalse(map.containsValue("Z"));
// }
//
// /**
// * get returns the correct element at the given key,
// * or null if not present
// */
// public void testGet() {
// ConcurrentSkipListMap map = map5();
// assertEquals("A", (String)map.get(one));
// ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
// assertNull(empty.get(one));
// }
//
// /**
// * isEmpty is true of empty map and false for non-empty
// */
// public void testIsEmpty() {
// ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
// ConcurrentSkipListMap map = map5();
// assertTrue(empty.isEmpty());
// assertFalse(map.isEmpty());
// }
//
// /**
// * firstKey returns first key
// */
// public void testFirstKey() {
// ConcurrentSkipListMap map = map5();
// assertEquals(one, map.firstKey());
// }
//
// /**
// * lastKey returns last key
// */
// public void testLastKey() {
// ConcurrentSkipListMap map = map5();
// assertEquals(five, map.lastKey());
// }
//
//
// /**
// * keySet.toArray returns contains all keys
// */
// public void testKeySetToArray() {
// ConcurrentSkipListMap map = map5();
// Set s = map.keySet();
// Object[] ar = s.toArray();
// assertTrue(s.containsAll(Arrays.asList(ar)));
// assertEquals(5, ar.length);
// ar[0] = m10;
// assertFalse(s.containsAll(Arrays.asList(ar)));
// }
//
// /**
// * descendingkeySet.toArray returns contains all keys
// */
// public void testDescendingKeySetToArray() {
// ConcurrentSkipListMap map = map5();
// Set s = map.descendingKeySet();
// Object[] ar = s.toArray();
// assertEquals(5, ar.length);
// assertTrue(s.containsAll(Arrays.asList(ar)));
// ar[0] = m10;
// assertFalse(s.containsAll(Arrays.asList(ar)));
// }
//
// /**
// * keySet returns a Set containing all the keys
// */
// public void testKeySet() {
// ConcurrentSkipListMap map = map5();
// Set s = map.keySet();
// assertEquals(5, s.size());
// assertTrue(s.contains(one));
// assertTrue(s.contains(two));
// assertTrue(s.contains(three));
// assertTrue(s.contains(four));
// assertTrue(s.contains(five));
// }
//
// /**
// * keySet is ordered
// */
// public void testKeySetOrder() {
// ConcurrentSkipListMap map = map5();
// Set s = map.keySet();
// Iterator i = s.iterator();
// Integer last = (Integer)i.next();
// assertEquals(last, one);
// while (i.hasNext()) {
// Integer k = (Integer)i.next();
// assertTrue(last.compareTo(k) < 0);
// last = k;
// }
// }
//
// /**
// * descendingKeySet is ordered
// */
// public void testDescendingKeySetOrder() {
// ConcurrentSkipListMap map = map5();
// Set s = map.descendingKeySet();
// Iterator i = s.iterator();
// Integer last = (Integer)i.next();
// assertEquals(last, five);
// while (i.hasNext()) {
// Integer k = (Integer)i.next();
// assertTrue(last.compareTo(k) > 0);
// last = k;
// }
// }
//
// /**
// * values collection contains all values
// */
// public void testValues() {
// ConcurrentSkipListMap map = map5();
// Collection s = map.values();
// assertEquals(5, s.size());
// assertTrue(s.contains("A"));
// assertTrue(s.contains("B"));
// assertTrue(s.contains("C"));
// assertTrue(s.contains("D"));
// assertTrue(s.contains("E"));
// }
//
// /**
// * entrySet contains all pairs
// */
// public void testEntrySet() {
// ConcurrentSkipListMap map = map5();
// Set s = map.entrySet();
// assertEquals(5, s.size());
// Iterator it = s.iterator();
// while (it.hasNext()) {
// Map.Entry e = (Map.Entry) it.next();
// assertTrue(
// (e.getKey().equals(one) && e.getValue().equals("A")) ||
// (e.getKey().equals(two) && e.getValue().equals("B")) ||
// (e.getKey().equals(three) && e.getValue().equals("C")) ||
// (e.getKey().equals(four) && e.getValue().equals("D")) ||
// (e.getKey().equals(five) && e.getValue().equals("E")));
// }
// }
//
// /**
// * descendingEntrySet contains all pairs
// */
// public void testDescendingEntrySet() {
// ConcurrentSkipListMap map = map5();
// Set s = map.descendingEntrySet();
// assertEquals(5, s.size());
// Iterator it = s.iterator();
// while (it.hasNext()) {
// Map.Entry e = (Map.Entry) it.next();
// assertTrue(
// (e.getKey().equals(one) && e.getValue().equals("A")) ||
// (e.getKey().equals(two) && e.getValue().equals("B")) ||
// (e.getKey().equals(three) && e.getValue().equals("C")) ||
// (e.getKey().equals(four) && e.getValue().equals("D")) ||
// (e.getKey().equals(five) && e.getValue().equals("E")));
// }
// }
//
// /**
// * entrySet.toArray contains all entries
// */
// public void testEntrySetToArray() {
// ConcurrentSkipListMap map = map5();
// Set s = map.entrySet();
// Object[] ar = s.toArray();
// assertEquals(5, ar.length);
// for (int i = 0; i < 5; ++i) {
// assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
// assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
// }
// }
//
// /**
// * descendingEntrySet.toArray contains all entries
// */
// public void testDescendingEntrySetToArray() {
// ConcurrentSkipListMap map = map5();
// Set s = map.descendingEntrySet();
// Object[] ar = s.toArray();
// assertEquals(5, ar.length);
// for (int i = 0; i < 5; ++i) {
// assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
// assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
// }
// }
//
// /**
// * putAll adds all key-value pairs from the given map
// */
// public void testPutAll() {
// ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
// ConcurrentSkipListMap map = map5();
// empty.putAll(map);
// assertEquals(5, empty.size());
// assertTrue(empty.containsKey(one));
// assertTrue(empty.containsKey(two));
// assertTrue(empty.containsKey(three));
// assertTrue(empty.containsKey(four));
// assertTrue(empty.containsKey(five));
// }
//
// /**
// * putIfAbsent works when the given key is not present
// */
// public void testPutIfAbsent() {
// ConcurrentSkipListMap map = map5();
// map.putIfAbsent(six, "Z");
// assertTrue(map.containsKey(six));
// }
//
// /**
// * putIfAbsent does not add the pair if the key is already present
// */
// public void testPutIfAbsent2() {
// ConcurrentSkipListMap map = map5();
// assertEquals("A", map.putIfAbsent(one, "Z"));
// }
//
// /**
// * replace fails when the given key is not present
// */
// public void testReplace() {
// ConcurrentSkipListMap map = map5();
// assertNull(map.replace(six, "Z"));
// assertFalse(map.containsKey(six));
// }
//
// /**
// * replace succeeds if the key is already present
// */
// public void testReplace2() {
// ConcurrentSkipListMap map = map5();
// assertNotNull(map.replace(one, "Z"));
// assertEquals("Z", map.get(one));
// }
//
//
// /**
// * replace value fails when the given key not mapped to expected value
// */
// public void testReplaceValue() {
// ConcurrentSkipListMap map = map5();
// assertEquals("A", map.get(one));
// assertFalse(map.replace(one, "Z", "Z"));
// assertEquals("A", map.get(one));
// }
//
// /**
// * replace value succeeds when the given key mapped to expected value
// */
// public void testReplaceValue2() {
// ConcurrentSkipListMap map = map5();
// assertEquals("A", map.get(one));
// assertTrue(map.replace(one, "A", "Z"));
// assertEquals("Z", map.get(one));
// }
//
//
// /**
// * remove removes the correct key-value pair from the map
// */
// public void testRemove() {
// ConcurrentSkipListMap map = map5();
// map.remove(five);
// assertEquals(4, map.size());
// assertFalse(map.containsKey(five));
// }
//
// /**
// * remove(key,value) removes only if pair present
// */
// public void testRemove2() {
// ConcurrentSkipListMap map = map5();
// assertTrue(map.containsKey(five));
// assertEquals("E", map.get(five));
// map.remove(five, "E");
// assertEquals(4, map.size());
// assertFalse(map.containsKey(five));
// map.remove(four, "A");
// assertEquals(4, map.size());
// assertTrue(map.containsKey(four));
//
// }
//
// /**
// * lowerEntry returns preceding entry.
// */
// public void testLowerEntry() {
// ConcurrentSkipListMap map = map5();
// Map.Entry e1 = map.lowerEntry(three);
// assertEquals(two, e1.getKey());
//
// Map.Entry e2 = map.lowerEntry(six);
// assertEquals(five, e2.getKey());
//
// Map.Entry e3 = map.lowerEntry(one);
// assertNull(e3);
//
// Map.Entry e4 = map.lowerEntry(zero);
// assertNull(e4);
//
// }
//
// /**
// * higherEntry returns next entry.
// */
// public void testHigherEntry() {
// ConcurrentSkipListMap map = map5();
// Map.Entry e1 = map.higherEntry(three);
// assertEquals(four, e1.getKey());
//
// Map.Entry e2 = map.higherEntry(zero);
// assertEquals(one, e2.getKey());
//
// Map.Entry e3 = map.higherEntry(five);
// assertNull(e3);
//
// Map.Entry e4 = map.higherEntry(six);
// assertNull(e4);
//
// }
//
// /**
// * floorEntry returns preceding entry.
// */
// public void testFloorEntry() {
// ConcurrentSkipListMap map = map5();
// Map.Entry e1 = map.floorEntry(three);
// assertEquals(three, e1.getKey());
//
// Map.Entry e2 = map.floorEntry(six);
// assertEquals(five, e2.getKey());
//
// Map.Entry e3 = map.floorEntry(one);
// assertEquals(one, e3.getKey());
//
// Map.Entry e4 = map.floorEntry(zero);
// assertNull(e4);
//
// }
//
// /**
// * ceilingEntry returns next entry.
// */
// public void testCeilingEntry() {
// ConcurrentSkipListMap map = map5();
// Map.Entry e1 = map.ceilingEntry(three);
// assertEquals(three, e1.getKey());
//
// Map.Entry e2 = map.ceilingEntry(zero);
// assertEquals(one, e2.getKey());
//
// Map.Entry e3 = map.ceilingEntry(five);
// assertEquals(five, e3.getKey());
//
// Map.Entry e4 = map.ceilingEntry(six);
// assertNull(e4);
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?