Search in sources :

Example 1 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class ArrayStack method zipWithIndex.

@Override
public ArrayStack<Pair<T, Integer>> zipWithIndex() {
    int maxIndex = this.delegate.size() - 1;
    Interval indices = Interval.fromTo(0, maxIndex);
    return ArrayStack.newStackFromTopToBottom(this.delegate.asReversed().zip(indices).toList());
}
Also used : Interval(org.eclipse.collections.impl.list.Interval)

Example 2 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class Collectors2Test method countByParallel.

@Test
public void countByParallel() {
    Interval integers = Interval.oneTo(100000);
    MutableBag<Integer> counts = integers.parallelStream().collect(Collectors2.countBy(i -> i % 2));
    Assert.assertEquals(integers.countBy(i -> i % 2), counts);
    Assert.assertEquals(50000, counts.occurrencesOf(0));
    Assert.assertEquals(50000, counts.occurrencesOf(1));
}
Also used : Maps(org.eclipse.collections.impl.factory.Maps) MutableObjectLongMap(org.eclipse.collections.api.map.primitive.MutableObjectLongMap) PartitionMutableCollection(org.eclipse.collections.api.partition.PartitionMutableCollection) Function(org.eclipse.collections.api.block.function.Function) Stacks(org.eclipse.collections.impl.factory.Stacks) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) Multimaps(org.eclipse.collections.impl.factory.Multimaps) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) MutableSortedMap(org.eclipse.collections.api.map.sorted.MutableSortedMap) BiMaps(org.eclipse.collections.impl.factory.BiMaps) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) Interval(org.eclipse.collections.impl.list.Interval) PartitionHashBag(org.eclipse.collections.impl.partition.bag.PartitionHashBag) SortedMaps(org.eclipse.collections.impl.factory.SortedMaps) MutableListMultimap(org.eclipse.collections.api.multimap.list.MutableListMultimap) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MutableBagMultimap(org.eclipse.collections.api.multimap.bag.MutableBagMultimap) List(java.util.List) Comparator(java.util.Comparator) Assert(org.junit.Assert) IntBags(org.eclipse.collections.impl.factory.primitive.IntBags) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 3 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class TakeWhileIteratorTest method iterator.

@Test
public void iterator() {
    Interval list = Interval.oneTo(5);
    Iterator<Integer> iterator1 = new TakeWhileIterator<>(list.iterator(), each -> each <= 2);
    assertElements(iterator1, 2);
    Iterator<Integer> iterator2 = new TakeWhileIterator<>(list, each -> each <= 5);
    assertElements(iterator2, 5);
    Iterator<Integer> iterator3 = new TakeWhileIterator<>(list, Predicates.alwaysTrue());
    assertElements(iterator3, 5);
    Iterator<Integer> iterator4 = new TakeWhileIterator<>(list, Predicates.alwaysFalse());
    assertElements(iterator4, 0);
    Iterator<Integer> iterator5 = new TakeWhileIterator<>(Lists.fixedSize.of(), Predicates.alwaysFalse());
    assertElements(iterator5, 0);
}
Also used : Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 4 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class TakeWhileIteratorTest method hasNext.

@Test
public void hasNext() {
    Interval list = Interval.oneTo(5);
    Iterator<Integer> iterator1 = new TakeWhileIterator<>(list.iterator(), each -> each <= 1);
    Assert.assertTrue(iterator1.hasNext());
    Assert.assertTrue(iterator1.hasNext());
    iterator1.next();
    Assert.assertFalse(iterator1.hasNext());
}
Also used : Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 5 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class DropIteratorTest method iterator.

@Test
public void iterator() {
    Interval list = Interval.oneTo(5);
    Iterator<Integer> iterator1 = new DropIterator<>(list.iterator(), 2);
    assertElements(iterator1, 2, list.size());
    Iterator<Integer> iterator2 = new DropIterator<>(list, 5);
    assertElements(iterator2, 5, list.size());
    Iterator<Integer> iterator3 = new DropIterator<>(list, 10);
    assertElements(iterator3, 5, list.size());
    Iterator<Integer> iterator4 = new DropIterator<>(list, 0);
    assertElements(iterator4, 0, list.size());
    Iterator<Integer> iterator5 = new DropIterator<>(Lists.fixedSize.of(), 0);
    assertElements(iterator5, 0, Lists.fixedSize.<Integer>of().size());
}
Also used : Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Aggregations

Interval (org.eclipse.collections.impl.list.Interval)32 Test (org.junit.Test)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 LinkedList (java.util.LinkedList)10 CompositeFastList (org.eclipse.collections.impl.list.mutable.CompositeFastList)10 Before (org.junit.Before)10 Function (org.eclipse.collections.api.block.function.Function)9 FastList (org.eclipse.collections.impl.list.mutable.FastList)9 Verify (org.eclipse.collections.impl.test.Verify)9 Assert (org.junit.Assert)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 MutableList (org.eclipse.collections.api.list.MutableList)8 MutableMap (org.eclipse.collections.api.map.MutableMap)8 BigInteger (java.math.BigInteger)7 Function2 (org.eclipse.collections.api.block.function.Function2)7 ImmutableList (org.eclipse.collections.api.list.ImmutableList)7 Predicates (org.eclipse.collections.impl.block.factory.Predicates)7 BigDecimal (java.math.BigDecimal)6 Arrays (java.util.Arrays)6