use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class TakeIteratorTest method iterator.
@Test
public void iterator() {
Interval list = Interval.oneTo(5);
Iterator<Integer> iterator1 = new TakeIterator<>(list.iterator(), 2);
assertElements(iterator1, 2);
Iterator<Integer> iterator2 = new TakeIterator<>(list, 5);
assertElements(iterator2, 5);
Iterator<Integer> iterator3 = new TakeIterator<>(list, 10);
assertElements(iterator3, 5);
Iterator<Integer> iterator4 = new TakeIterator<>(list, 0);
assertElements(iterator4, 0);
Iterator<Integer> iterator5 = new TakeIterator<>(Lists.fixedSize.of(), 0);
assertElements(iterator5, 0);
}
use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class MultiReaderHashBagTest method concurrentWrite.
@Test
public void concurrentWrite() {
MultiReaderHashBag<Integer> numbers = this.newWith();
Interval interval = Interval.oneTo(100);
ParallelIterate.forEach(interval, each -> {
numbers.add(each);
Verify.assertSize(1, numbers.select(each::equals));
numbers.add(each);
Assert.assertEquals(2, numbers.count(each::equals));
numbers.add(each);
Integer[] removed = new Integer[1];
numbers.withWriteLockAndDelegate(bag -> {
Iterator<Integer> iterator = bag.iterator();
removed[0] = iterator.next();
bag.remove(removed[0]);
bag.add(removed[0]);
});
numbers.add(each);
Assert.assertEquals(4, numbers.count(each::equals));
}, 1);
interval.forEach(Procedures.cast(each -> Assert.assertEquals(4, numbers.occurrencesOf(each))));
}
use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class MultiReaderHashBagTest method parallelCollect.
@Test
public void parallelCollect() {
MultiReaderHashBag<String> numbers = this.newWith();
Interval interval = Interval.oneTo(50000);
ParallelIterate.collect(interval, String::valueOf, numbers, true);
Assert.assertEquals(numbers, interval.collect(String::valueOf).toBag());
}
use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class ImmutableArrayBagTest method newWith.
@Override
@Test
public void newWith() {
super.newWith();
int maximumUsefulArrayBagSize = ImmutableArrayBag.MAXIMUM_USEFUL_ARRAY_BAG_SIZE;
Verify.assertInstanceOf(ImmutableArrayBag.class, Bags.immutable.ofAll(Interval.oneTo(maximumUsefulArrayBagSize - 1)).newWith(maximumUsefulArrayBagSize));
Verify.assertInstanceOf(ImmutableHashBag.class, Bags.immutable.ofAll(Interval.oneTo(maximumUsefulArrayBagSize)).newWith(maximumUsefulArrayBagSize + 1));
Interval items = Interval.oneTo(maximumUsefulArrayBagSize);
Verify.assertInstanceOf(ImmutableHashBag.class, new ImmutableArrayBag<>(items.toArray(), items.toIntArray()).newWith(maximumUsefulArrayBagSize + 1));
}
use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class ImmutableArrayBagTest method testNewBag.
@Test
public void testNewBag() {
for (int i = 1; i <= ImmutableArrayBag.MAXIMUM_USEFUL_ARRAY_BAG_SIZE + 1; i++) {
Interval interval = Interval.oneTo(i);
Verify.assertEqualsAndHashCode(HashBag.newBag(interval), Bags.immutable.ofAll(interval));
}
Verify.assertThrows(IllegalArgumentException.class, () -> new ImmutableArrayBag<>(new Integer[] { 2, 3 }, new int[] { 2 }));
}
Aggregations