Search in sources :

Example 41 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class IntOpenHashSetTest method retainAll_disjoint_set.

@Test
public void retainAll_disjoint_set() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    IntSet otherSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    otherSet.add(2);
    otherSet.add(3);
    otherSet.add(4);
    intSet.retainAll(otherSet);
    assertTrue("Integer set should be empty after retaining a disjoint set of elements.", intSet.isEmpty());
}
Also used : IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 42 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class NormalFormGroupSet method fillNumbers.

public void fillNumbers() {
    final IntSet numbersUsed = PrimitiveSets.newIntOpenHashSetWithExpectedSize(groups.size());
    this.groups.stream().filter(group -> group.getGroupNumber() > 0).forEachOrdered(group -> numbersUsed.add(group.getGroupNumber()));
    int groupNumber = 1;
    for (final NormalFormGroup group : groups) {
        if (group.getGroupNumber() == NormalFormGroup.UNKOWN_GROUP) {
            while (numbersUsed.contains(groupNumber)) {
                groupNumber++;
            }
            group.setGroupNumber(groupNumber);
            groupNumber++;
        }
        // Always check if there are any union groups that need numbers
        group.fillNumbers();
    }
}
Also used : List(java.util.List) PrimitiveSets(com.b2international.collections.PrimitiveSets) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Iterator(java.util.Iterator) AbstractSet(java.util.AbstractSet) Comparator(java.util.Comparator) IntSet(com.b2international.collections.ints.IntSet) IntSet(com.b2international.collections.ints.IntSet)

Example 43 with IntSet

use of com.b2international.collections.ints.IntSet in project snow-owl by b2ihealthcare.

the class InternalSctIdMultimap method get.

@Override
public LongSet get(final long key) {
    final int internalId = internalIdMap.getInternalId(key);
    if (internalId == InternalIdMap.NO_INTERNAL_ID) {
        return PrimitiveSets.newLongOpenHashSet();
    }
    final IntSet values = internalIdMultimap.get(internalId);
    if (values == null) {
        return PrimitiveSets.newLongOpenHashSet();
    } else {
        final LongSet sctIdValues = PrimitiveSets.newLongOpenHashSetWithExpectedSize(values.size());
        for (final IntIterator itr = values.iterator(); itr.hasNext(); ) /*empty*/
        {
            final int valueInternalId = itr.next();
            final long valueSctId = internalIdMap.getSctId(valueInternalId);
            sctIdValues.add(valueSctId);
        }
        return sctIdValues;
    }
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) IntSet(com.b2international.collections.ints.IntSet) LongSet(com.b2international.collections.longs.LongSet)

Aggregations

IntSet (com.b2international.collections.ints.IntSet)43 Test (org.junit.Test)38 IntIterator (com.b2international.collections.ints.IntIterator)4 PrimitiveSets (com.b2international.collections.PrimitiveSets)2 Comparator (java.util.Comparator)2 List (java.util.List)2 LongSet (com.b2international.collections.longs.LongSet)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 AbstractSet (java.util.AbstractSet)1 Iterator (java.util.Iterator)1 Objects (java.util.Objects)1