use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.
the class LongSets 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 LongSet intersection(final LongSet set1, final LongSet set2) {
checkNotNull(set1, "The set1 argument cannot be null.");
checkNotNull(set2, "The set2 argument cannot be null.");
if (CompareUtils.isEmpty(set1)) {
// nothing to do
return LongCollections.emptySet();
}
final LongSet result = PrimitiveSets.newLongOpenHashSet(set1);
result.retainAll(set2);
return result;
}
use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.
the class LongOpenHashSetTest method retainAll_same.
@Test
public void retainAll_same() {
LongSet longSet = PrimitiveSets.newLongOpenHashSet();
LongSet otherSet = PrimitiveSets.newLongOpenHashSet();
longSet.add(0L);
longSet.add(5L);
longSet.add(10L);
otherSet.add(0L);
otherSet.add(5L);
otherSet.add(10L);
longSet.retainAll(otherSet);
assertEquals("Three elements should remain after retaining.", 3, longSet.size());
assertTrue("Long set should contain element 0.", longSet.contains(0L));
assertTrue("Long set should contain element 5.", longSet.contains(5L));
assertTrue("Long set should contain element 10.", longSet.contains(10L));
}
use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.
the class LongOpenHashSetTest method equals_false.
@Test
public void equals_false() {
LongSet longSet = PrimitiveSets.newLongOpenHashSet();
LongSet otherSet = PrimitiveSets.newLongOpenHashSet();
longSet.add(0L);
longSet.add(5L);
longSet.add(10L);
otherSet.add(0L);
otherSet.add(1L);
otherSet.add(2L);
assertFalse("First set should not be equal to second set.", longSet.equals(otherSet));
assertFalse("Second set should not be equal to first set.", otherSet.equals(longSet));
}
use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.
the class LongOpenHashSetTest method removeAll_null.
@Test(expected = NullPointerException.class)
public void removeAll_null() {
LongSet longSet = PrimitiveSets.newLongOpenHashSet();
longSet.add(0L);
longSet.add(5L);
longSet.add(10L);
longSet.removeAll(null);
}
use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.
the class LongOpenHashSetTest method toString_regular.
@Test
public void toString_regular() {
LongSet longSet = PrimitiveSets.newLongOpenHashSet();
longSet.add(11L);
longSet.add(22L);
longSet.add(33L);
String toString = longSet.toString();
assertTrue("ToString output should start with an opening square bracket.", toString.startsWith("["));
assertTrue("ToString output should end with a closing square bracket.", toString.endsWith("]"));
assertTrue("ToString output should contain the number 11.", toString.contains("11"));
assertTrue("ToString output should contain the number 22.", toString.contains("22"));
assertTrue("ToString output should contain the number 33.", toString.contains("33"));
}
Aggregations