Search in sources :

Example 51 with LongSet

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;
}
Also used : LongSet(com.b2international.collections.longs.LongSet)

Example 52 with LongSet

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));
}
Also used : LongSet(com.b2international.collections.longs.LongSet) Test(org.junit.Test)

Example 53 with LongSet

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));
}
Also used : LongSet(com.b2international.collections.longs.LongSet) Test(org.junit.Test)

Example 54 with 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);
}
Also used : LongSet(com.b2international.collections.longs.LongSet) Test(org.junit.Test)

Example 55 with LongSet

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"));
}
Also used : LongSet(com.b2international.collections.longs.LongSet) Test(org.junit.Test)

Aggregations

LongSet (com.b2international.collections.longs.LongSet)63 Test (org.junit.Test)46 LongIterator (com.b2international.collections.longs.LongIterator)9 PrimitiveSets (com.b2international.collections.PrimitiveSets)3 LongList (com.b2international.collections.longs.LongList)3 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)3 ImmutableList (com.google.common.collect.ImmutableList)3 Sets (com.google.common.collect.Sets)3 Collection (java.util.Collection)3 PrimitiveMaps (com.b2international.collections.PrimitiveMaps)2 IntIterator (com.b2international.collections.ints.IntIterator)2 LongKeyMap (com.b2international.collections.longs.LongKeyMap)2 LongSets (com.b2international.commons.collect.LongSets)2 CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)2 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)2 ConcreteDomainFragment (com.b2international.snowowl.snomed.datastore.ConcreteDomainFragment)2 StatementFragment (com.b2international.snowowl.snomed.datastore.StatementFragment)2 StatementFragmentWithDestination (com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination)2 StatementFragmentWithValue (com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue)2 List (java.util.List)2