Search in sources :

Example 1 with IntIterator

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

the class IntOpenHashSetTest method iterator_empty.

@Test
public void iterator_empty() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    IntIterator itr = intSet.iterator();
    assertFalse("Iterator should indicate that there are no elements.", itr.hasNext());
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 2 with IntIterator

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

the class IntOpenHashSetTest method iterator.

@Test
public void iterator() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    intSet.add(0);
    intSet.add(5);
    intSet.add(10);
    IntIterator itr = intSet.iterator();
    int[] values = new int[3];
    for (int i = 0; i < 3; i++) {
        assertTrue("Iterator should indicate that the next value is available.", itr.hasNext());
        values[i] = itr.next();
    }
    assertFalse("Iterator should indicate that there are no more elements.", itr.hasNext());
    Arrays.sort(values);
    assertEquals("Iterator should return first element.", 0, values[0]);
    assertEquals("Iterator should return second element.", 5, values[1]);
    assertEquals("Iterator should return third element.", 10, values[2]);
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 3 with IntIterator

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

the class IntOpenHashSetTest method iterator_overrun.

@Test(expected = NoSuchElementException.class)
public void iterator_overrun() {
    IntSet intSet = PrimitiveSets.newIntOpenHashSet();
    IntIterator itr = intSet.iterator();
    itr.next();
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) IntSet(com.b2international.collections.ints.IntSet) Test(org.junit.Test)

Example 4 with IntIterator

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

the class PrimitiveSets method newBitSet.

public static BitSet newBitSet(IntCollection source) {
    if (source == null) {
        return newBitSet();
    } else {
        final BitSet bitSet = newBitSetWithExpectedSize(source.size());
        final IntIterator iter = source.iterator();
        while (iter.hasNext()) {
            bitSet.set(iter.next());
        }
        return bitSet;
    }
}
Also used : IntIterator(com.b2international.collections.ints.IntIterator) BitSet(java.util.BitSet)

Example 5 with IntIterator

use of com.b2international.collections.ints.IntIterator 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

IntIterator (com.b2international.collections.ints.IntIterator)6 IntSet (com.b2international.collections.ints.IntSet)4 Test (org.junit.Test)3 LongSet (com.b2international.collections.longs.LongSet)2 BitSet (java.util.BitSet)1