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