Search in sources :

Example 16 with SortedSet

use of java.util.SortedSet in project mapdb by jankotek.

the class TreeSetTest method testSubSetContents2.

public void testSubSetContents2() {
    TreeSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
Also used : TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 17 with SortedSet

use of java.util.SortedSet in project mapdb by jankotek.

the class TreeSubSetTest method testSubSetContents.

/**
     * subSet returns set with keys in requested range
     */
public void testSubSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.subSet(two, four);
    assertEquals(two, sm.first());
    assertEquals(three, sm.last());
    assertEquals(2, sm.size());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.first());
    assertEquals(three, sm.last());
    assertTrue(sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, set.size());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 18 with SortedSet

use of java.util.SortedSet in project mapdb by jankotek.

the class TreeSubSetTest method testDescendingSubSetContents.

/**
     * subSet returns set with keys in requested range
     */
public void testDescendingSubSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.subSet(m2, m4);
    assertEquals(m2, sm.first());
    assertEquals(m3, sm.last());
    assertEquals(2, sm.size());
    assertFalse(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertFalse(sm.contains(m4));
    assertFalse(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(m2));
    assertEquals(4, set.size());
    assertEquals(1, sm.size());
    assertEquals(m3, sm.first());
    assertEquals(m3, sm.last());
    assertTrue(sm.remove(m3));
    assertTrue(sm.isEmpty());
    assertEquals(3, set.size());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 19 with SortedSet

use of java.util.SortedSet in project mapdb by jankotek.

the class TreeSubSetTest method testDescendingTailSetContents.

/**
     * tailSet returns set with keys in requested range
     */
public void testDescendingTailSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.tailSet(m2);
    assertFalse(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertTrue(sm.contains(m4));
    assertTrue(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    k = (Integer) (i.next());
    assertEquals(m4, k);
    k = (Integer) (i.next());
    assertEquals(m5, k);
    assertFalse(i.hasNext());
    SortedSet ssm = sm.tailSet(m4);
    assertEquals(m4, ssm.first());
    assertEquals(m5, ssm.last());
    assertTrue(ssm.remove(m4));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 20 with SortedSet

use of java.util.SortedSet in project mapdb by jankotek.

the class TreeSubSetTest method testHeadSetContents.

/**
     * headSet returns set with keys in requested range
     */
public void testHeadSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.headSet(four);
    assertTrue(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.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, set.size());
    assertEquals(four, set.first());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Aggregations

SortedSet (java.util.SortedSet)377 TreeSet (java.util.TreeSet)174 Iterator (java.util.Iterator)116 HashMap (java.util.HashMap)94 Map (java.util.Map)94 Set (java.util.Set)90 ArrayList (java.util.ArrayList)78 List (java.util.List)78 TreeMap (java.util.TreeMap)61 HashSet (java.util.HashSet)60 IOException (java.io.IOException)58 NavigableSet (java.util.NavigableSet)56 Test (org.junit.Test)50 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 SortedMap (java.util.SortedMap)31 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)30 Comparator (java.util.Comparator)30 File (java.io.File)28 Collection (java.util.Collection)28