Search in sources :

Example 1 with LongIterator

use of com.b2international.collections.longs.LongIterator 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 2 with LongIterator

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

the class LongTarjan method visit.

private void visit(final long currentId, final LongCollection ids) {
    indexMap.put(currentId, index);
    lowLinkMap.put(currentId, index);
    index++;
    idStack.add(currentId);
    final LongCollection followers = getFollowers.apply(currentId);
    for (final LongIterator itr = followers.iterator(); itr.hasNext(); ) /* empty */
    {
        final long currentFollowerId = itr.next();
        if (!indexMap.containsKey(currentFollowerId)) {
            continue;
        }
        if (indexMap.get(currentFollowerId) == -1) {
            visit(currentFollowerId, ids);
            final int newLowLink = Math.min(lowLinkMap.get(currentId), lowLinkMap.get(currentFollowerId));
            lowLinkMap.put(currentId, newLowLink);
        } else if (idStack.contains(currentFollowerId)) {
            final int newLowLink = Math.min(lowLinkMap.get(currentId), indexMap.get(currentFollowerId));
            lowLinkMap.put(currentId, newLowLink);
        }
    }
    if (lowLinkMap.get(currentId) == indexMap.get(currentId)) {
        long sccMember = removeLast();
        if (currentId == sccMember) {
            addToCurrent(sccMember);
            if (currentSize() >= batchSize) {
                flushBatch();
            }
        } else {
            addToCurrent(sccMember);
            do {
                sccMember = removeLast();
                addToCurrent(sccMember);
            } while (currentId != sccMember);
            if (currentSize() >= batchSize) {
                flushBatch();
            }
        }
    }
}
Also used : LongCollection(com.b2international.collections.longs.LongCollection) LongIterator(com.b2international.collections.longs.LongIterator)

Example 3 with LongIterator

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

the class EmptyLongListTest method iterator_overrun.

@Test(expected = NoSuchElementException.class)
public void iterator_overrun() {
    LongList emptyList = LongCollections.emptyList();
    LongIterator itr = emptyList.iterator();
    itr.next();
}
Also used : LongList(com.b2international.collections.longs.LongList) LongIterator(com.b2international.collections.longs.LongIterator) Test(org.junit.Test)

Example 4 with LongIterator

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

the class LongOpenHashSetTest method iterator_empty.

@Test
public void iterator_empty() {
    LongSet longSet = PrimitiveSets.newLongOpenHashSet();
    LongIterator itr = longSet.iterator();
    assertFalse("Iterator should indicate that there are no elements.", itr.hasNext());
}
Also used : LongSet(com.b2international.collections.longs.LongSet) LongIterator(com.b2international.collections.longs.LongIterator) Test(org.junit.Test)

Example 5 with LongIterator

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

the class LongOpenHashSetTest method iterator_overrun.

@Test(expected = NoSuchElementException.class)
public void iterator_overrun() {
    LongSet longSet = PrimitiveSets.newLongOpenHashSet();
    LongIterator itr = longSet.iterator();
    itr.next();
}
Also used : LongSet(com.b2international.collections.longs.LongSet) LongIterator(com.b2international.collections.longs.LongIterator) Test(org.junit.Test)

Aggregations

LongIterator (com.b2international.collections.longs.LongIterator)17 LongSet (com.b2international.collections.longs.LongSet)9 LongList (com.b2international.collections.longs.LongList)5 Test (org.junit.Test)5 PrimitiveMaps (com.b2international.collections.PrimitiveMaps)2 PrimitiveSets (com.b2international.collections.PrimitiveSets)2 AbstractLongIterator (com.b2international.collections.longs.AbstractLongIterator)2 LongCollection (com.b2international.collections.longs.LongCollection)2 LongKeyMap (com.b2international.collections.longs.LongKeyMap)2 LongSets (com.b2international.commons.collect.LongSets)2 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)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 PropertyChain (com.b2international.snowowl.snomed.datastore.index.taxonomy.PropertyChain)2 ReasonerTaxonomy (com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy)2 INormalFormGenerator (com.b2international.snowowl.snomed.reasoner.classification.INormalFormGenerator)2 ReasonerTaxonomyInferrer (com.b2international.snowowl.snomed.reasoner.classification.ReasonerTaxonomyInferrer)2