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));
}
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);
}
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());
}
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;
}
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;
}
Aggregations