Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package org.mapdb;/*
   /*
    * 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/publicdomain/zero/1.0/
    */
   
   import junit.framework.*;
   import java.util.*;
  
  public class BTreeMapTest6 extends JSR166TestCase {
      public static void main(String[] args) {
          junit.textui.TestRunner.run(suite());
      }
      public static Test suite() {
          return new TestSuite(BTreeMapTest6.class);
      }

    
Returns a new map from Integers 1-5 to Strings "A"-"E".
  
      private static ConcurrentNavigableMap map5() {
          ConcurrentNavigableMap map = DBMaker.newMemoryDB().make().createTreeMap("test").make();
          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() {
          ConcurrentNavigableMap map = map5();
          map.clear();
          assertEquals(0, map.size());
      }
  
  //    /**
  //     * copy constructor creates map equal to source map
  //     */
  //    public void testConstructFromSorted() {
  //        ConcurrentNavigableMap map = map5();
  //        ConcurrentNavigableMap map2 = new ConcurrentSkipListMap(map);
  //        assertEquals(map, map2);
  //    }
  
    
Maps with same contents are equal
  
      public void testEquals() {
          ConcurrentNavigableMap map1 = map5();
          ConcurrentNavigableMap map2 = map5();
          assertEquals(map1map2);
          assertEquals(map2map1);
          map1.clear();
          assertFalse(map1.equals(map2));
          assertFalse(map2.equals(map1));
      }

    
containsKey returns true for contained key
  
      public void testContainsKey() {
          ConcurrentNavigableMap map = map5();
          assertTrue(map.containsKey(one));
          assertFalse(map.containsKey(zero));
      }

    
containsValue returns true for held values
  
      public void testContainsValue() {
          ConcurrentNavigableMap 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() {
          ConcurrentNavigableMap map = map5();
          assertEquals("A", (String)map.get(one));
          ConcurrentNavigableMap empty = DBMaker.newMemoryDB().make().createTreeMap("test").make();
          assertNull(empty.get(one));
      }

    
isEmpty is true of empty map and false for non-empty
  
      public void testIsEmpty() {
         ConcurrentNavigableMap empty = DBMaker.newMemoryDB().make().createTreeMap("test").make();
         ConcurrentNavigableMap map = map5();
         assertTrue(empty.isEmpty());
         assertFalse(map.isEmpty());
     }

    
firstKey returns first key
 
     public void testFirstKey() {
         ConcurrentNavigableMap map = map5();
         assertEquals(one, map.firstKey());
     }

    
lastKey returns last key
 
     public void testLastKey() {
         ConcurrentNavigableMap map = map5();
         assertEquals(five, map.lastKey());
     }

    
keySet.toArray returns contains all keys
 
     public void testKeySetToArray() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap map = map5();
         Set s = map.keySet();
         Iterator i = s.iterator();
         Integer last = (Integer)i.next();
         assertEquals(last, one);
         int count = 1;
         while (i.hasNext()) {
             Integer k = (Integer)i.next();
             assertTrue(last.compareTo(k) < 0);
             last = k;
             ++count;
         }
         assertEquals(5, count);
     }

    
descending iterator of key set is inverse ordered
 
     public void testKeySetDescendingIteratorOrder() {
         ConcurrentNavigableMap map = map5();
         NavigableSet s = map.navigableKeySet();
         Iterator i = s.descendingIterator();
         Integer last = (Integer)i.next();
         assertEquals(last, five);
         int count = 1;
         while (i.hasNext()) {
             Integer k = (Integer)i.next();
             assertTrue(last.compareTo(k) > 0);
             last = k;
             ++count;
         }
         assertEquals(5, count);
     }

    
descendingKeySet is ordered
 
     public void testDescendingKeySetOrder() {
         ConcurrentNavigableMap map = map5();
         Set s = map.descendingKeySet();
         Iterator i = s.iterator();
         Integer last = (Integer)i.next();
         assertEquals(last, five);
         int count = 1;
         while (i.hasNext()) {
             Integer k = (Integer)i.next();
             assertTrue(last.compareTo(k) > 0);
             last = k;
             ++count;
         }
         assertEquals(5, count);
     }

    
descending iterator of descendingKeySet is ordered
 
         ConcurrentNavigableMap map = map5();
         NavigableSet s = map.descendingKeySet();
         Iterator i = s.descendingIterator();
         Integer last = (Integer)i.next();
         assertEquals(last, one);
         int count = 1;
         while (i.hasNext()) {
             Integer k = (Integer)i.next();
             assertTrue(last.compareTo(k) < 0);
             last = k;
             ++count;
         }
         assertEquals(5, count);
     }

    
Values.toArray contains all values
 
     public void testValuesToArray() {
         ConcurrentNavigableMap map = map5();
         Collection v = map.values();
         Object[] ar = v.toArray();
         ArrayList s = new ArrayList(Arrays.asList(ar));
         assertEquals(5, ar.length);
         assertTrue(s.contains("A"));
         assertTrue(s.contains("B"));
         assertTrue(s.contains("C"));
         assertTrue(s.contains("D"));
         assertTrue(s.contains("E"));
     }

    
values collection contains all values
 
     public void testValues() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap map = map5();
         Set s = map.entrySet();
         assertEquals(5, s.size());
         Iterator it = s.iterator();
         while (it.hasNext()) {
             Map.Entry e = (Map.Entryit.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() {
         ConcurrentNavigableMap map = map5();
         Set s = map.descendingMap().entrySet();
         assertEquals(5, s.size());
         Iterator it = s.iterator();
         while (it.hasNext()) {
             Map.Entry e = (Map.Entryit.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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap map = map5();
         Set s = map.descendingMap().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()));
         }
     }

    
putAll adds all key-value pairs from the given map
 
     public void testPutAll() {
         ConcurrentNavigableMap empty = DBMaker.newMemoryDB().make().createTreeMap("test").make();
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap map = map5();
         assertEquals("A"map.putIfAbsent(one, "Z"));
     }

    
replace fails when the given key is not present
 
     public void testReplace() {
         ConcurrentNavigableMap map = map5();
         assertNull(map.replace(six, "Z"));
         assertFalse(map.containsKey(six));
     }

    
replace succeeds if the key is already present
 
     public void testReplace2() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap map = map5();
         map.remove(five);
         assertEquals(4, map.size());
         assertFalse(map.containsKey(five));
     }

    
remove(key,value) removes only if pair present
 
     public void testRemove2() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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() {
         ConcurrentNavigableMap 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);
     }

    
lowerEntry, higherEntry, ceilingEntry, and floorEntry return immutable entries
 
     public void testEntryImmutability() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e = map.lowerEntry(three);
         assertEquals(two, e.getKey());
         try {
             e.setValue("X");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.higherEntry(zero);
         assertEquals(one, e.getKey());
         try {
             e.setValue("X");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.floorEntry(one);
         assertEquals(one, e.getKey());
         try {
             e.setValue("X");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.ceilingEntry(five);
         assertEquals(five, e.getKey());
         try {
             e.setValue("X");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
     }

    
lowerKey returns preceding element
 
     public void testLowerKey() {
         ConcurrentNavigableMap qmap5();
         Object e1 = q.lowerKey(three);
         assertEquals(two, e1);
 
         Object e2 = q.lowerKey(six);
         assertEquals(five, e2);
 
         Object e3 = q.lowerKey(one);
         assertNull(e3);
 
         Object e4 = q.lowerKey(zero);
         assertNull(e4);
     }

    
higherKey returns next element
 
     public void testHigherKey() {
         ConcurrentNavigableMap qmap5();
         Object e1 = q.higherKey(three);
         assertEquals(four, e1);
 
         Object e2 = q.higherKey(zero);
         assertEquals(one, e2);
 
         Object e3 = q.higherKey(five);
         assertNull(e3);
 
         Object e4 = q.higherKey(six);
         assertNull(e4);
     }

    
floorKey returns preceding element
 
     public void testFloorKey() {
         ConcurrentNavigableMap qmap5();
         Object e1 = q.floorKey(three);
         assertEquals(three, e1);
 
         Object e2 = q.floorKey(six);
         assertEquals(five, e2);
 
         Object e3 = q.floorKey(one);
         assertEquals(one, e3);
 
         Object e4 = q.floorKey(zero);
         assertNull(e4);
     }

    
ceilingKey returns next element
 
     public void testCeilingKey() {
         ConcurrentNavigableMap qmap5();
         Object e1 = q.ceilingKey(three);
         assertEquals(three, e1);
 
         Object e2 = q.ceilingKey(zero);
         assertEquals(one, e2);
 
         Object e3 = q.ceilingKey(five);
         assertEquals(five, e3);
 
         Object e4 = q.ceilingKey(six);
         assertNull(e4);
     }

    
pollFirstEntry returns entries in order
 
     public void testPollFirstEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e = map.pollFirstEntry();
         assertEquals(one, e.getKey());
         assertEquals("A"e.getValue());
         e = map.pollFirstEntry();
         assertEquals(two, e.getKey());
         map.put(one, "A");
         e = map.pollFirstEntry();
         assertEquals(one, e.getKey());
         assertEquals("A"e.getValue());
         e = map.pollFirstEntry();
         assertEquals(three, e.getKey());
         map.remove(four);
         e = map.pollFirstEntry();
         assertEquals(five, e.getKey());
         try {
             e.setValue("A");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.pollFirstEntry();
         assertNull(e);
     }

    
pollLastEntry returns entries in order
 
     public void testPollLastEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e = map.pollLastEntry();
         assertEquals(five, e.getKey());
         assertEquals("E"e.getValue());
         e = map.pollLastEntry();
         assertEquals(four, e.getKey());
         map.put(five, "E");
         e = map.pollLastEntry();
         assertEquals(five, e.getKey());
         assertEquals("E"e.getValue());
         e = map.pollLastEntry();
         assertEquals(three, e.getKey());
         map.remove(two);
         e = map.pollLastEntry();
         assertEquals(one, e.getKey());
         try {
             e.setValue("E");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.pollLastEntry();
         assertNull(e);
     }

    
size returns the correct values
 
     public void testSize() {
         ConcurrentNavigableMap map = map5();
         ConcurrentNavigableMap empty = DBMaker.newMemoryDB().make().createTreeMap("test").make();
         assertEquals(0, empty.size());
         assertEquals(5, map.size());
     }

    
toString contains toString of elements
 
     public void testToString() {
         ConcurrentNavigableMap map = map5();
         String s = map.toString();
         for (int i = 1; i <= 5; ++i) {
             assertTrue(s.contains(String.valueOf(i)));
         }
     }
 
     // Exception tests
 
    
get(null) of nonempty map throws NPE
 
     public void testGet_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.get(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
containsKey(null) of nonempty map throws NPE
 
     public void testContainsKey_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.containsKey(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
containsValue(null) throws NPE
 
     public void testContainsValue_NullPointerException() {
         try {
             ConcurrentNavigableMap c = DBMaker.newMemoryDB().make().createTreeMap("test").make();
             c.containsValue(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
put(null,x) throws NPE
 
     public void testPut1_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.put(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
putIfAbsent(null, x) throws NPE
 
     public void testPutIfAbsent1_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.putIfAbsent(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
replace(null, x) throws NPE
 
     public void testReplace_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.replace(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
replace(null, x, y) throws NPE
 
     public void testReplaceValue_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.replace(null, one, "whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
remove(null) throws NPE
 
     public void testRemove1_NullPointerException() {
         try {
             ConcurrentNavigableMap c = DBMaker.newMemoryDB().make().createTreeMap("test").make();
             c.put("sadsdf""asdads");
             c.remove(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
remove(null, x) throws NPE
 
     public void testRemove2_NullPointerException() {
         try {
             ConcurrentNavigableMap c = DBMaker.newMemoryDB().make().createTreeMap("test").make();
             c.put("sadsdf""asdads");
             c.remove(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
remove(x, null) returns false
 
     public void testRemove3() {
         ConcurrentNavigableMap c = DBMaker.newMemoryDB().make().createTreeMap("test").make();
         c.put("sadsdf""asdads");
         assertFalse(c.remove("sadsdf"null));
     }
 
 //    /**
 //     * A deserialized map equals original
 //     */
 //    public void testSerialization() throws Exception {
 //        NavigableMap x = map5();
 //        NavigableMap y = serialClone(x);
 //
 //        assertNotSame(x, y);
 //        assertEquals(x.size(), y.size());
 //        assertEquals(x.toString(), y.toString());
 //        assertEquals(x, y);
 //        assertEquals(y, x);
 //    }
 
    
subMap returns map with keys in requested range
 
     public void testSubMapContents() {
         ConcurrentNavigableMap map = map5();
         NavigableMap sm = map.subMap(two, true, four, false);
         assertEquals(two, sm.firstKey());
         assertEquals(three, sm.lastKey());
         assertEquals(2, sm.size());
         assertFalse(sm.containsKey(one));
         assertTrue(sm.containsKey(two));
         assertTrue(sm.containsKey(three));
         assertFalse(sm.containsKey(four));
         assertFalse(sm.containsKey(five));
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(two, k);
         k = (Integer)(i.next());
         assertEquals(three, k);
         assertFalse(i.hasNext());
         Iterator r = sm.descendingKeySet().iterator();
         k = (Integer)(r.next());
         assertEquals(three, k);
         k = (Integer)(r.next());
         assertEquals(two, k);
         assertFalse(r.hasNext());
 
         Iterator j = sm.keySet().iterator();
         j.next();
         j.remove();
         assertFalse(map.containsKey(two));
         assertEquals(4, map.size());
         assertEquals(1, sm.size());
         assertEquals(three, sm.firstKey());
         assertEquals(three, sm.lastKey());
         assertEquals("C"sm.remove(three));
         assertTrue(sm.isEmpty());
         assertEquals(3, map.size());
     }
 
     public void testSubMapContents2() {
         ConcurrentNavigableMap map = map5();
         NavigableMap sm = map.subMap(two, true, three, false);
         assertEquals(1, sm.size());
         assertEquals(two, sm.firstKey());
         assertEquals(two, sm.lastKey());
         assertFalse(sm.containsKey(one));
         assertTrue(sm.containsKey(two));
         assertFalse(sm.containsKey(three));
         assertFalse(sm.containsKey(four));
         assertFalse(sm.containsKey(five));
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(two, k);
         assertFalse(i.hasNext());
         Iterator r = sm.descendingKeySet().iterator();
         k = (Integer)(r.next());
         assertEquals(two, k);
         assertFalse(r.hasNext());
 
         Iterator j = sm.keySet().iterator();
         j.next();
         j.remove();
         assertFalse(map.containsKey(two));
         assertEquals(4, map.size());
         assertEquals(0, sm.size());
         assertTrue(sm.isEmpty());
         assertSame(sm.remove(three), null);
         assertEquals(4, map.size());
     }

    
headMap returns map with keys in requested range
 
     public void testHeadMapContents() {
         ConcurrentNavigableMap map = map5();
         NavigableMap sm = map.headMap(four, false);
         assertTrue(sm.containsKey(one));
         assertTrue(sm.containsKey(two));
         assertTrue(sm.containsKey(three));
         assertFalse(sm.containsKey(four));
         assertFalse(sm.containsKey(five));
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(one, k);
         k = (Integer)(i.next());
         assertEquals(two, k);
         k = (Integer)(i.next());
         assertEquals(three, k);
         assertFalse(i.hasNext());
         sm.clear();
         assertTrue(sm.isEmpty());
         assertEquals(2, map.size());
         assertEquals(four, map.firstKey());
     }

    
tailMap returns map with keys in requested range
 
     public void testTailMapContents() {
         ConcurrentNavigableMap map = map5();
         NavigableMap sm = map.tailMap(two, true);
         assertFalse(sm.containsKey(one));
         assertTrue(sm.containsKey(two));
         assertTrue(sm.containsKey(three));
         assertTrue(sm.containsKey(four));
         assertTrue(sm.containsKey(five));
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(two, k);
         k = (Integer)(i.next());
         assertEquals(three, k);
         k = (Integer)(i.next());
         assertEquals(four, k);
         k = (Integer)(i.next());
         assertEquals(five, k);
         assertFalse(i.hasNext());
         Iterator r = sm.descendingKeySet().iterator();
         k = (Integer)(r.next());
         assertEquals(five, k);
         k = (Integer)(r.next());
         assertEquals(four, k);
         k = (Integer)(r.next());
         assertEquals(three, k);
         k = (Integer)(r.next());
         assertEquals(two, k);
         assertFalse(r.hasNext());
 
         Iterator ei = sm.entrySet().iterator();
         Map.Entry e;
         e = (Map.Entry)(ei.next());
         assertEquals(two, e.getKey());
         assertEquals("B"e.getValue());
         e = (Map.Entry)(ei.next());
         assertEquals(three, e.getKey());
         assertEquals("C"e.getValue());
         e = (Map.Entry)(ei.next());
         assertEquals(four, e.getKey());
         assertEquals("D"e.getValue());
         e = (Map.Entry)(ei.next());
         assertEquals(five, e.getKey());
         assertEquals("E"e.getValue());
         assertFalse(i.hasNext());
 
         NavigableMap ssm = sm.tailMap(four, true);
         assertEquals(four, ssm.firstKey());
         assertEquals(five, ssm.lastKey());
         assertEquals("D"ssm.remove(four));
         assertEquals(1, ssm.size());
         assertEquals(3, sm.size());
         assertEquals(4, map.size());
     }
 
     Random rnd = new Random(666);
     BitSet bs;
 
     final boolean expensiveTests = true;

    
Submaps of submaps subdivide correctly
 
     public void testRecursiveSubMaps() throws Exception {
         int mapSize =  ? 1000 : 100;
         //Class cl = ConcurrentSkipListMap.class;
         NavigableMap<IntegerIntegermap = // newMap(cl);
                 DBMaker.newMemoryDB().make().createTreeMap("test").make();
          = new BitSet(mapSize);
 
         populate(mapmapSize);
         check(map,                 0, mapSize - 1, true);
         check(map.descendingMap(), 0, mapSize - 1, false);
 
         mutateMap(map, 0, mapSize - 1);
         check(map,                 0, mapSize - 1, true);
         check(map.descendingMap(), 0, mapSize - 1, false);
 
         bashSubMap(map.subMap(0, truemapSizefalse),
                 0, mapSize - 1, true);
     }
 
     static NavigableMap<IntegerIntegernewMap(Class clthrows Exception {
         NavigableMap<IntegerIntegerresult =
                 (NavigableMap<IntegerInteger>) cl.newInstance();
         assertEquals(0, result.size());
         assertFalse(result.keySet().iterator().hasNext());
         return result;
     }
 
     void populate(NavigableMap<IntegerIntegermapint limit) {
         for (int i = 0, n = 2 * limit / 3; i < ni++) {
            int key = .nextInt(limit);
            put(mapkey);
        }
    }
    void mutateMap(NavigableMap<IntegerIntegermapint minint max) {
        int size = map.size();
        int rangeSize = max - min + 1;
        // Remove a bunch of entries directly
        for (int i = 0, n = rangeSize / 2; i < ni++) {
            remove(mapmin - 5 + .nextInt(rangeSize + 10));
        }
        // Remove a bunch of entries with iterator
        for (Iterator<Integerit = map.keySet().iterator(); it.hasNext(); ) {
            if (.nextBoolean()) {
                .clear(it.next());
                it.remove();
            }
        }
        // Add entries till we're back to original size
        while (map.size() < size) {
            int key = min + .nextInt(rangeSize);
            assertTrue(key >= min && key<= max);
            put(mapkey);
        }
    }
    void mutateSubMap(NavigableMap<IntegerIntegermapint minint max) {
        int size = map.size();
        int rangeSize = max - min + 1;
        // Remove a bunch of entries directly
        for (int i = 0, n = rangeSize / 2; i < ni++) {
            remove(mapmin - 5 + .nextInt(rangeSize + 10));
        }
        // Remove a bunch of entries with iterator
        for (Iterator<Integerit = map.keySet().iterator(); it.hasNext(); ) {
            if (.nextBoolean()) {
                .clear(it.next());
                it.remove();
            }
        }
        // Add entries till we're back to original size
        while (map.size() < size) {
            int key = min - 5 + .nextInt(rangeSize + 10);
            if (key >= min && key<= max) {
                put(mapkey);
            } else {
                try {
                    map.put(key, 2 * key);
                    shouldThrow();
                } catch (IllegalArgumentException success) {}
            }
        }
    }
    void put(NavigableMap<IntegerIntegermapint key) {
        if (map.put(key, 2 * key) == null)
            .set(key);
    }
    void remove(NavigableMap<IntegerIntegermapint key) {
        if (map.remove(key) != null)
            .clear(key);
    }
                    int minint maxboolean ascending) {
        check(mapminmaxascending);
        check(map.descendingMap(), minmax, !ascending);
        mutateSubMap(mapminmax);
        check(mapminmaxascending);
        check(map.descendingMap(), minmax, !ascending);
        // Recurse
        if (max - min < 2)
            return;
        int midPoint = (min + max) / 2;
        // headMap - pick direction and endpoint inclusion randomly
        boolean incl = .nextBoolean();
        NavigableMap<Integer,Integerhm = map.headMap(midPointincl);
        if (ascending) {
            if (.nextBoolean())
                bashSubMap(hmminmidPoint - (incl ? 0 : 1), true);
            else
                bashSubMap(hm.descendingMap(), minmidPoint - (incl ? 0 : 1),
                        false);
        } else {
            if (.nextBoolean())
                bashSubMap(hmmidPoint + (incl ? 0 : 1), maxfalse);
            else
                bashSubMap(hm.descendingMap(), midPoint + (incl ? 0 : 1), max,
                        true);
        }
        // tailMap - pick direction and endpoint inclusion randomly
        incl = .nextBoolean();
        NavigableMap<Integer,Integertm = map.tailMap(midPoint,incl);
        if (ascending) {
            if (.nextBoolean())
                bashSubMap(tmmidPoint + (incl ? 0 : 1), maxtrue);
            else
                bashSubMap(tm.descendingMap(), midPoint + (incl ? 0 : 1), max,
                        false);
        } else {
            if (.nextBoolean()) {
                bashSubMap(tmminmidPoint - (incl ? 0 : 1), false);
            } else {
                bashSubMap(tm.descendingMap(), minmidPoint - (incl ? 0 : 1),
                        true);
            }
        }
        // subMap - pick direction and endpoint inclusion randomly
        int rangeSize = max - min + 1;
        int[] endpoints = new int[2];
        endpoints[0] = min + .nextInt(rangeSize);
        endpoints[1] = min + .nextInt(rangeSize);
        Arrays.sort(endpoints);
        boolean lowIncl = .nextBoolean();
        boolean highIncl = .nextBoolean();
        if (ascending) {
            NavigableMap<Integer,Integersm = map.subMap(
                    endpoints[0], lowInclendpoints[1], highIncl);
            if (.nextBoolean())
                bashSubMap(smendpoints[0] + (lowIncl ? 0 : 1),
                        endpoints[1] - (highIncl ? 0 : 1), true);
            else
                bashSubMap(sm.descendingMap(), endpoints[0] + (lowIncl ? 0 : 1),
                        endpoints[1] - (highIncl ? 0 : 1), false);
        } else {
            NavigableMap<Integer,Integersm = map.subMap(
                    endpoints[1], highInclendpoints[0], lowIncl);
            if (.nextBoolean())
                bashSubMap(smendpoints[0] + (lowIncl ? 0 : 1),
                        endpoints[1] - (highIncl ? 0 : 1), false);
            else
                bashSubMap(sm.descendingMap(), endpoints[0] + (lowIncl ? 0 : 1),
                        endpoints[1] - (highIncl ? 0 : 1), true);
        }
    }

    
min and max are both inclusive. If max < min, interval is empty.
    void check(NavigableMap<IntegerIntegermap,
               final int minfinal int maxfinal boolean ascending) {
        class ReferenceSet {
            int lower(int key) {
                return ascending ? lowerAscending(key) : higherAscending(key);
            }
            int floor(int key) {
                return ascending ? floorAscending(key) : ceilingAscending(key);
            }
            int ceiling(int key) {
                return ascending ? ceilingAscending(key) : floorAscending(key);
            }
            int higher(int key) {
                return ascending ? higherAscending(key) : lowerAscending(key);
            }
            int first() {
                return ascending ? firstAscending() : lastAscending();
            }
            int last() {
                return ascending ? lastAscending() : firstAscending();
            }
            int lowerAscending(int key) {
                return floorAscending(key - 1);
            }
            int floorAscending(int key) {
                if (key < min)
                    return -1;
                else if (key >