Search in sources :

Example 16 with IntSet

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

the class IntOpenHashSetTest method removeAll_empty_set.

@Test
public void removeAll_empty_set() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    IntSet otherSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    intSet.removeAll(otherSet);
    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 17 with IntSet

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

the class IntOpenHashSetTest method retainAll_null.

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

Example 18 with IntSet

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

the class IntOpenHashSetTest method create_null_collection.

@Test
public void create_null_collection() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet((IntCollection) null);
    assertTrue("Integer set should be empty.", intSet.isEmpty());
}
Also used : IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 19 with IntSet

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

the class PrimitiveSets method difference.

/**
 * Returns with the difference of two sets. The
 * returned set contains all elements that are contained by {@code set1} and
 * not contained by {@code set2}. {@code set2} may also contain elements not
 * present in {@code set1}; these are simply ignored. The iteration order of
 * the returned set matches that of {@code set1}.
 * @param set1 Cannot be {@code null}.
 * @param set2 Cannot be {@code null}.
 * @return a view of the difference of the two sets.
 */
public static IntSet difference(IntSet set1, IntSet set2) {
    checkNotNull(set1, "The set1 argument cannot be null.");
    checkNotNull(set2, "The set2 argument cannot be null.");
    if (set1.isEmpty()) {
        // nothing to do
        return PrimitiveSets.newIntOpenHashSetWithExpectedSize(1);
    }
    final IntSet result = PrimitiveSets.newIntOpenHashSet(set1);
    result.removeAll(set2);
    return result;
}
Also used : IntSet(com.b2international.collections.ints.IntSet)

Example 20 with IntSet

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

the class PrimitiveSets method intersection.

/**
 * Returns with the intersection of two sets. The
 * returned set contains all elements that are contained by both backing sets.
 * The iteration order of the returned set matches that of {@code set1}.
 *
 * <p><b>Note:</b> The returned view performs slightly better when {@code
 * set1} is the smaller of the two sets. If you have reason to believe one of
 * your sets will generally be smaller than the other, pass it first.
 *
 * @param set1 Cannot be {@code null}.
 * @param set2 Cannot be {@code null}.
 * @return a view of the intersection of the two sets.
 */
public static IntSet intersection(IntSet set1, IntSet set2) {
    checkNotNull(set1, "The set1 argument cannot be null.");
    checkNotNull(set2, "The set2 argument cannot be null.");
    if (set1.isEmpty()) {
        // nothing to do
        return PrimitiveSets.newIntOpenHashSetWithExpectedSize(1);
    }
    final IntSet result = PrimitiveSets.newIntOpenHashSet(set1);
    result.retainAll(set2);
    return result;
}
Also used : IntSet(com.b2international.collections.ints.IntSet)

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