Search in sources :

Example 1 with LongSet

use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.

the class LongSets 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 LongSet difference(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.removeAll(set2);
    return result;
}
Also used : LongSet(com.b2international.collections.longs.LongSet)

Example 2 with LongSet

use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.

the class LongSets method transform.

/**
 * Transforms the given {@link LongCollection} into a collection of object based on the {@link InverseLongFunction function} argument.
 * @param fromCollection the collection of primitive long values to transform.
 * @param function the function for the transformation.
 * @return the transformed collection of long values.
 */
public static <T> Collection<T> transform(final LongCollection fromCollection, final InverseLongFunction<? extends T> function) {
    checkNotNull(fromCollection, "fromCollection");
    checkNotNull(function, "function");
    @SuppressWarnings("unchecked") final Collection<T> toCollection = (Collection<T>) (fromCollection instanceof LongSet ? Sets.newHashSetWithExpectedSize(fromCollection.size()) : Lists.newArrayListWithExpectedSize(fromCollection.size()));
    for (final LongIterator itr = fromCollection.iterator(); itr.hasNext(); ) /**/
    {
        toCollection.add(function.apply(itr.next()));
    }
    return toCollection;
}
Also used : LongSet(com.b2international.collections.longs.LongSet) LongCollection(com.b2international.collections.longs.LongCollection) Collection(java.util.Collection) AbstractLongIterator(com.b2international.collections.longs.AbstractLongIterator) LongIterator(com.b2international.collections.longs.LongIterator)

Example 3 with LongSet

use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.

the class LongKeyLongSetMultimap method put.

public boolean put(final long key, final long value) {
    LongSet values = delegateGet(key);
    if (values == null) {
        values = PrimitiveSets.newLongOpenHashSet();
        delegatePut(key, values);
    }
    return values.add(value);
}
Also used : LongSet(com.b2international.collections.longs.LongSet)

Example 4 with LongSet

use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.

the class LongOpenHashSetTest method addAll_empty.

@Test
public void addAll_empty() {
    LongSet longSet = PrimitiveSets.newLongOpenHashSet();
    longSet.addAll(PrimitiveSets.newLongOpenHashSet());
    assertTrue("Long set should be empty.", longSet.isEmpty());
}
Also used : LongSet(com.b2international.collections.longs.LongSet) Test(org.junit.Test)

Example 5 with LongSet

use of com.b2international.collections.longs.LongSet in project snow-owl by b2ihealthcare.

the class LongOpenHashSetTest method retainAll_disjoint_set.

@Test
public void retainAll_disjoint_set() {
    LongSet longSet = PrimitiveSets.newLongOpenHashSet();
    LongSet otherSet = PrimitiveSets.newLongOpenHashSet();
    longSet.add(0L);
    longSet.add(5L);
    longSet.add(10L);
    otherSet.add(2L);
    otherSet.add(3L);
    otherSet.add(4L);
    longSet.retainAll(otherSet);
    assertTrue("Long set should be empty after retaining a disjoint set of elements.", longSet.isEmpty());
}
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