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