Search in sources :

Example 26 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class IntOpenHashSetTest method iterator.

@Test
public void iterator() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    IntIterator itr = intSet.iterator();
    int[] values = new int[3];
    for (int i = 0; i < 3; i++) {
        assertTrue("Iterator should indicate that the next value is available.", itr.hasNext());
        values[i] = itr.next();
    }
    assertFalse("Iterator should indicate that there are no more elements.", itr.hasNext());
    Arrays.sort(values);
    assertEquals("Iterator should return first element.", 0, values[0]);
    assertEquals("Iterator should return second element.", 5, values[1]);
    assertEquals("Iterator should return third element.", 10, values[2]);
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 27 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class IntOpenHashSetTest method add.

@Test
public void add() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    assertEquals("Integer set size should be 3.", 3, intSet.size());
    assertTrue("Integer set should contain element 0.", intSet.contains(0));
    assertTrue("Integer set should contain element 5.", intSet.contains(5));
    assertTrue("Integer set should contain element 10.", intSet.contains(10));
}
Also used : IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 28 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class IntOpenHashSetTest method removeAll_null.

@Test(expected = NullPointerException.class)
public void removeAll_null() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    intSet.removeAll(null);
}
Also used : IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 29 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class IntOpenHashSetTest method create_collection.

@Test
public void create_collection() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet(PrimitiveLists.newIntArrayList(0, 5, 10, 5));
    assertEquals("Integer set size should be 3.", 3, intSet.size());
    assertTrue("Integer set should contain element 0.", intSet.contains(0));
    assertTrue("Integer set should contain element 5.", intSet.contains(5));
    assertTrue("Integer set should contain element 10.", intSet.contains(10));
}
Also used : IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 30 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class IntOpenHashSetTest method toArray.

@Test
public void toArray() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    int[] array = intSet.toArray();
    Arrays.sort(array);
    assertArrayEquals("Array should contain all stored elements.", new int[] { 0, 5, 10 }, array);
}
Also used : IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Aggregations

IntSet (com.b2international.collections.ints.IntSet)43 Test (org.junit.Test)38 IntIterator (com.b2international.collections.ints.IntIterator)4 PrimitiveSets (com.b2international.collections.PrimitiveSets)2 Comparator (java.util.Comparator)2 List (java.util.List)2 LongSet (com.b2international.collections.longs.LongSet)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 AbstractSet (java.util.AbstractSet)1 Iterator (java.util.Iterator)1 Objects (java.util.Objects)1