Search in sources :

Example 11 with BooleanArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectBooleanOverOptimizeLimit.

@Test
public void collectBooleanOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableBooleanList actual = ArrayListIterate.collectBoolean(list, PrimitiveFunctions.integerIsPositive());
    BooleanArrayList expected = new BooleanArrayList(list.size());
    expected.add(false);
    for (int i = 1; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add(true);
    }
    Assert.assertEquals(expected, actual);
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) Test(org.junit.Test)

Example 12 with BooleanArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList in project eclipse-collections by eclipse.

the class IterateTest method collectBooleanWithTarget.

@Test
public void collectBooleanWithTarget() {
    this.iterables.each(each -> {
        MutableBooleanCollection expected = new BooleanArrayList();
        MutableBooleanCollection actual = Iterate.collectBoolean(each, PrimitiveFunctions.integerIsPositive(), expected);
        Assert.assertTrue(expected.containsAll(true, true, true, true, true));
        Assert.assertSame("Target list sent as parameter not returned", expected, actual);
    });
    Verify.assertThrows(IllegalArgumentException.class, () -> Iterate.collectBoolean(null, PrimitiveFunctions.integerIsPositive(), new BooleanArrayList()));
}
Also used : MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) Test(org.junit.Test)

Example 13 with BooleanArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList in project eclipse-collections by eclipse.

the class BooleanArrayStackTest method testPushPopAndPeek.

@Test
public void testPushPopAndPeek() {
    BooleanArrayStack stack = BooleanArrayStack.newStackFromTopToBottom();
    stack.push(true);
    Assert.assertTrue(stack.peek());
    Assert.assertEquals(BooleanArrayStack.newStackFromTopToBottom(true), stack);
    stack.push(false);
    Assert.assertFalse(stack.peek());
    Assert.assertEquals(BooleanArrayStack.newStackFromTopToBottom(false, true), stack);
    stack.push(true);
    Assert.assertTrue(stack.peek());
    Assert.assertEquals(BooleanArrayStack.newStackFromTopToBottom(true, false, true), stack);
    Assert.assertFalse(stack.peekAt(1));
    Assert.assertTrue(stack.pop());
    Assert.assertFalse(stack.peek());
    Assert.assertFalse(stack.pop());
    Assert.assertTrue(stack.peek());
    Assert.assertTrue(stack.pop());
    BooleanArrayStack stack2 = BooleanArrayStack.newStackFromTopToBottom(true, false, true, false, true);
    stack2.pop(2);
    Assert.assertEquals(BooleanArrayStack.newStackFromTopToBottom(true, false, true), stack2);
    Assert.assertEquals(BooleanArrayList.newListWith(true, false), stack2.peek(2));
    BooleanArrayStack stack8 = BooleanArrayStack.newStackFromTopToBottom(false, true, false, true);
    Verify.assertEmpty(stack8.pop(0));
    Assert.assertEquals(BooleanArrayStack.newStackFromTopToBottom(false, true, false, true), stack8);
    Assert.assertEquals(new BooleanArrayList(), stack8.peek(0));
    BooleanArrayStack stack9 = BooleanArrayStack.newStackFromTopToBottom();
    Assert.assertEquals(new BooleanArrayList(), stack9.pop(0));
    Assert.assertEquals(new BooleanArrayList(), stack9.peek(0));
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) Test(org.junit.Test)

Example 14 with BooleanArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList in project eclipse-collections by eclipse.

the class AbstractBooleanSetTestCase method retainAll_iterable.

@Override
@Test
public void retainAll_iterable() {
    super.retainAll_iterable();
    Assert.assertFalse(this.emptySet.retainAll(new BooleanArrayList()));
    Assert.assertTrue(this.setWithTrueFalse.retainAll(BooleanArrayList.newListWith(true, true)));
    Assert.assertEquals(BooleanHashSet.newSetWith(true), this.setWithTrueFalse);
    MutableBooleanSet set = this.newWith(true, false);
    Assert.assertTrue(set.retainAll(BooleanArrayList.newListWith()));
    Assert.assertEquals(BooleanHashSet.newSetWith(), set);
    MutableBooleanSet sett = this.newWith(true, false);
    Assert.assertTrue(sett.retainAll(BooleanArrayList.newListWith(false, false)));
    Assert.assertEquals(BooleanHashSet.newSetWith(false), sett);
    MutableBooleanSet sett2 = this.newWith(true);
    Assert.assertTrue(sett2.retainAll(BooleanArrayList.newListWith(false, false)));
    Assert.assertEquals(BooleanHashSet.newSetWith(), sett2);
    Assert.assertTrue(this.setWithTrue.retainAll(BooleanArrayList.newListWith(false, false)));
    Assert.assertFalse(this.setWithTrue.retainAll(BooleanArrayList.newListWith(true, false)));
    Assert.assertEquals(BooleanHashSet.newSetWith(), this.setWithTrue);
    MutableBooleanSet sett3 = this.newWith(false);
    Assert.assertFalse(sett3.retainAll(BooleanArrayList.newListWith(false, false)));
    Assert.assertEquals(BooleanHashSet.newSetWith(false), sett3);
    Assert.assertTrue(this.setWithFalse.retainAll(BooleanArrayList.newListWith(true, true)));
    Assert.assertFalse(this.setWithFalse.retainAll(BooleanArrayList.newListWith(true, false)));
    Assert.assertEquals(BooleanHashSet.newSetWith(), this.setWithFalse);
    Assert.assertFalse(this.emptySet.retainAll(BooleanArrayList.newListWith(true, true)));
    Assert.assertFalse(this.emptySet.retainAll(BooleanArrayList.newListWith(true, false)));
    Assert.assertFalse(this.emptySet.retainAll(BooleanArrayList.newListWith(false, false)));
    Assert.assertEquals(BooleanHashSet.newSetWith(), this.emptySet);
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanSet(org.eclipse.collections.api.set.primitive.MutableBooleanSet) Test(org.junit.Test)

Example 15 with BooleanArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList in project eclipse-collections by eclipse.

the class AbstractBooleanSetTestCase method toList.

@Override
@Test
public void toList() {
    super.toList();
    Assert.assertEquals(new BooleanArrayList(), this.emptySet.toList());
    Assert.assertEquals(BooleanArrayList.newListWith(false), this.setWithFalse.toList());
    Assert.assertEquals(BooleanArrayList.newListWith(true), this.setWithTrue.toList());
    Assert.assertTrue(BooleanArrayList.newListWith(false, true).equals(this.setWithTrueFalse.toList()) || BooleanArrayList.newListWith(true, false).equals(this.setWithTrueFalse.toList()));
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) Test(org.junit.Test)

Aggregations

BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)49 Test (org.junit.Test)35 MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)11 BooleanIterable (org.eclipse.collections.api.BooleanIterable)7 MutableBooleanList (org.eclipse.collections.api.list.primitive.MutableBooleanList)6 MutableBooleanSet (org.eclipse.collections.api.set.primitive.MutableBooleanSet)3 BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)3 ByteArrayList (org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList)3 CharArrayList (org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)3 DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)3 FloatArrayList (org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList)3 IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)3 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)3 ShortArrayList (org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 NoSuchElementException (java.util.NoSuchElementException)2 ImmutableSortedBag (org.eclipse.collections.api.bag.sorted.ImmutableSortedBag)2 MutableCollection (org.eclipse.collections.api.collection.MutableCollection)2