Search in sources :

Example 11 with MutableBooleanCollection

use of org.eclipse.collections.api.collection.primitive.MutableBooleanCollection in project eclipse-collections by eclipse.

the class SortedNaturalOrderTestCase method RichIterable_collectPrimitive.

@Override
@Test
default void RichIterable_collectPrimitive() {
    assertEquals(this.getExpectedBoolean(false, false, true, true, false, false), this.newWith(1, 1, 2, 2, 3, 3).collectBoolean(each -> each % 2 == 0));
    {
        MutableBooleanCollection target = this.newBooleanForTransform();
        MutableBooleanCollection result = this.newWith(1, 1, 2, 2, 3, 3).collectBoolean(each -> each % 2 == 0, target);
        assertEquals(this.newBooleanForTransform(false, false, true, true, false, false), result);
        assertSame(target, result);
    }
    RichIterable<Integer> iterable = this.newWith(1, 1, 2, 2, 3, 3, 11, 11, 12, 12, 13, 13);
    assertEquals(this.getExpectedByte((byte) 1, (byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 3, (byte) 1, (byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 3), iterable.collectByte(each -> (byte) (each % 10)));
    {
        MutableByteCollection target = this.newByteForTransform();
        MutableByteCollection result = iterable.collectByte(each -> (byte) (each % 10), target);
        assertEquals(this.newByteForTransform((byte) 1, (byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 3, (byte) 1, (byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 3), result);
        assertSame(target, result);
    }
    assertEquals(this.getExpectedChar((char) 1, (char) 1, (char) 2, (char) 2, (char) 3, (char) 3, (char) 1, (char) 1, (char) 2, (char) 2, (char) 3, (char) 3), iterable.collectChar(each -> (char) (each % 10)));
    {
        MutableCharCollection target = this.newCharForTransform();
        MutableCharCollection result = iterable.collectChar(each -> (char) (each % 10), target);
        assertEquals(this.newCharForTransform((char) 1, (char) 1, (char) 2, (char) 2, (char) 3, (char) 3, (char) 1, (char) 1, (char) 2, (char) 2, (char) 3, (char) 3), result);
        assertSame(target, result);
    }
    assertEquals(this.getExpectedDouble(1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0), iterable.collectDouble(each -> (double) (each % 10)));
    {
        MutableDoubleCollection target = this.newDoubleForTransform();
        MutableDoubleCollection result = iterable.collectDouble(each -> (double) (each % 10), target);
        assertEquals(this.newDoubleForTransform(1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0), result);
        assertSame(target, result);
    }
    assertEquals(this.getExpectedFloat(1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f), iterable.collectFloat(each -> (float) (each % 10)));
    {
        MutableFloatCollection target = this.newFloatForTransform();
        MutableFloatCollection result = iterable.collectFloat(each -> (float) (each % 10), target);
        assertEquals(this.newFloatForTransform(1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f), result);
        assertSame(target, result);
    }
    assertEquals(this.getExpectedInt(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3), iterable.collectInt(each -> each % 10));
    {
        MutableIntCollection target = this.newIntForTransform();
        MutableIntCollection result = iterable.collectInt(each -> each % 10, target);
        assertEquals(this.newIntForTransform(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3), result);
        assertSame(target, result);
    }
    assertEquals(this.getExpectedLong(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3), iterable.collectLong(each -> each % 10));
    {
        MutableLongCollection target = this.newLongForTransform();
        MutableLongCollection result = iterable.collectLong(each -> each % 10, target);
        assertEquals(this.newLongForTransform(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3), result);
        assertSame(target, result);
    }
    assertEquals(this.getExpectedShort((short) 1, (short) 1, (short) 2, (short) 2, (short) 3, (short) 3, (short) 1, (short) 1, (short) 2, (short) 2, (short) 3, (short) 3), iterable.collectShort(each -> (short) (each % 10)));
    MutableShortCollection target = this.newShortForTransform();
    MutableShortCollection result = iterable.collectShort(each -> (short) (each % 10), target);
    assertEquals(this.newShortForTransform((short) 1, (short) 1, (short) 2, (short) 2, (short) 3, (short) 3, (short) 1, (short) 1, (short) 2, (short) 2, (short) 3, (short) 3), result);
    assertSame(target, result);
}
Also used : SortedIterable(org.eclipse.collections.api.ordered.SortedIterable) OrderedIterable(org.eclipse.collections.api.ordered.OrderedIterable) IterableTestCase.assertEquals(org.eclipse.collections.test.IterableTestCase.assertEquals) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) MutableList(org.eclipse.collections.api.list.MutableList) Verify.assertThrows(org.eclipse.collections.impl.test.Verify.assertThrows) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) RichIterable(org.eclipse.collections.api.RichIterable) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) MutableCollection(org.eclipse.collections.api.collection.MutableCollection) Predicates(org.eclipse.collections.impl.block.factory.Predicates) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) Iterator(java.util.Iterator) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) Test(org.junit.Test) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) Assert.assertNull(org.junit.Assert.assertNull) Lists(org.eclipse.collections.impl.factory.Lists) Optional(java.util.Optional) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) Matchers.is(org.hamcrest.Matchers.is) Assert(org.junit.Assert) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) Test(org.junit.Test)

Example 12 with MutableBooleanCollection

use of org.eclipse.collections.api.collection.primitive.MutableBooleanCollection in project eclipse-collections by eclipse.

the class AbstractBooleanSetTestCase method withAll.

@Override
@Test
public void withAll() {
    super.withAll();
    MutableBooleanCollection emptySet = this.newWith();
    MutableBooleanCollection set = emptySet.withAll(BooleanArrayList.newListWith(false));
    MutableBooleanSet set1 = this.newWith().withAll(BooleanArrayList.newListWith(true));
    MutableBooleanSet set2 = this.newWith().withAll(BooleanArrayList.newListWith(true, false));
    MutableBooleanSet set3 = this.newWith().withAll(BooleanArrayList.newListWith(true, false));
    Assert.assertSame(emptySet, set);
    Assert.assertEquals(this.setWithFalse, set);
    Assert.assertEquals(this.setWithTrue, set1);
    Assert.assertEquals(this.setWithTrueFalse, set2);
    Assert.assertEquals(this.setWithTrueFalse, set3);
    Assert.assertEquals(BooleanHashSet.newSetWith(true, false), this.setWithTrueFalse.withAll(BooleanHashSet.newSetWith(true, false)));
}
Also used : MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) MutableBooleanSet(org.eclipse.collections.api.set.primitive.MutableBooleanSet) Test(org.junit.Test)

Example 13 with MutableBooleanCollection

use of org.eclipse.collections.api.collection.primitive.MutableBooleanCollection in project eclipse-collections by eclipse.

the class AbstractBooleanSetTestCase method with.

@Override
@Test
public void with() {
    super.with();
    MutableBooleanCollection emptySet = this.newWith();
    MutableBooleanCollection set = emptySet.with(false);
    MutableBooleanSet set1 = this.newWith().with(true);
    MutableBooleanSet set2 = this.newWith().with(true).with(false);
    MutableBooleanSet set3 = this.newWith().with(false).with(true);
    Assert.assertSame(emptySet, set);
    Assert.assertEquals(this.setWithFalse, set);
    Assert.assertEquals(this.setWithTrue, set1);
    Assert.assertEquals(this.setWithTrueFalse, set2);
    Assert.assertEquals(this.setWithTrueFalse, set3);
    Assert.assertEquals(BooleanHashSet.newSetWith(true, false), this.setWithTrueFalse.with(true));
}
Also used : MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) MutableBooleanSet(org.eclipse.collections.api.set.primitive.MutableBooleanSet) Test(org.junit.Test)

Example 14 with MutableBooleanCollection

use of org.eclipse.collections.api.collection.primitive.MutableBooleanCollection in project eclipse-collections by eclipse.

the class UnmodifiableMutableCollectionTest method delegatingCollectPrimitiveMethods.

@Test
public void delegatingCollectPrimitiveMethods() {
    MutableCollection<Integer> mutable = Interval.oneTo(4).toList();
    MutableCollection<Integer> unmodifiable = new UnmodifiableMutableCollection<>(mutable);
    MutableBooleanCollection expectedBooleans = mutable.collectBoolean(PrimitiveFunctions.integerIsPositive());
    Assert.assertEquals(expectedBooleans, unmodifiable.collectBoolean(PrimitiveFunctions.integerIsPositive()));
    Assert.assertEquals(BooleanArrayList.newListWith(true, true, true, true), expectedBooleans);
    MutableByteCollection expectedBytes = mutable.collectByte(PrimitiveFunctions.unboxIntegerToByte());
    Assert.assertEquals(expectedBytes, unmodifiable.collectByte(PrimitiveFunctions.unboxIntegerToByte()));
    Assert.assertEquals(ByteArrayList.newListWith((byte) 1, (byte) 2, (byte) 3, (byte) 4), expectedBytes);
    MutableCharCollection expectedChars = mutable.collectChar(PrimitiveFunctions.unboxIntegerToChar());
    Assert.assertEquals(expectedChars, unmodifiable.collectChar(PrimitiveFunctions.unboxIntegerToChar()));
    Assert.assertEquals(CharArrayList.newListWith((char) 1, (char) 2, (char) 3, (char) 4), expectedChars);
    MutableDoubleCollection expectedDoubles = mutable.collectDouble(PrimitiveFunctions.unboxIntegerToDouble());
    Assert.assertEquals(expectedDoubles, unmodifiable.collectDouble(PrimitiveFunctions.unboxIntegerToDouble()));
    Assert.assertEquals(DoubleArrayList.newListWith(1.0d, 2.0d, 3.0d, 4.0d), expectedDoubles);
    MutableFloatCollection expectedFloats = mutable.collectFloat(PrimitiveFunctions.unboxIntegerToFloat());
    Assert.assertEquals(expectedFloats, unmodifiable.collectFloat(PrimitiveFunctions.unboxIntegerToFloat()));
    Assert.assertEquals(FloatArrayList.newListWith(1.0f, 2.0f, 3.0f, 4.0f), expectedFloats);
    MutableIntCollection expectedInts = mutable.collectInt(PrimitiveFunctions.unboxIntegerToInt());
    Assert.assertEquals(expectedInts, unmodifiable.collectInt(PrimitiveFunctions.unboxIntegerToInt()));
    Assert.assertEquals(IntArrayList.newListWith(1, 2, 3, 4), expectedInts);
    MutableLongCollection expectedLongs = mutable.collectLong(PrimitiveFunctions.unboxIntegerToLong());
    Assert.assertEquals(expectedLongs, unmodifiable.collectLong(PrimitiveFunctions.unboxIntegerToLong()));
    Assert.assertEquals(LongArrayList.newListWith(1L, 2L, 3L, 4L), expectedLongs);
    MutableShortCollection expectedShorts = mutable.collectShort(PrimitiveFunctions.unboxIntegerToShort());
    Assert.assertEquals(expectedShorts, unmodifiable.collectShort(PrimitiveFunctions.unboxIntegerToShort()));
    Assert.assertEquals(ShortArrayList.newListWith((short) 1, (short) 2, (short) 3, (short) 4), expectedShorts);
}
Also used : MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) Test(org.junit.Test)

Example 15 with MutableBooleanCollection

use of org.eclipse.collections.api.collection.primitive.MutableBooleanCollection in project eclipse-collections by eclipse.

the class AbstractMutableBooleanBagTestCase method testHashCode.

@Override
@Test
public void testHashCode() {
    super.testHashCode();
    MutableBooleanCollection collection1 = this.newWith(true, false, true, false);
    MutableBooleanCollection collection2 = this.newWith(true, false, false, true);
    MutableBooleanCollection collection3 = this.newWith(true, false);
    MutableBooleanCollection collection4 = this.newWith(true, true, false);
    Verify.assertEqualsAndHashCode(collection1, collection2);
    Assert.assertNotEquals(collection3.hashCode(), collection4.hashCode());
}
Also used : MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) Test(org.junit.Test)

Aggregations

MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)45 Test (org.junit.Test)43 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)11 MutableByteCollection (org.eclipse.collections.api.collection.primitive.MutableByteCollection)4 MutableCharCollection (org.eclipse.collections.api.collection.primitive.MutableCharCollection)4 MutableDoubleCollection (org.eclipse.collections.api.collection.primitive.MutableDoubleCollection)4 MutableFloatCollection (org.eclipse.collections.api.collection.primitive.MutableFloatCollection)4 MutableIntCollection (org.eclipse.collections.api.collection.primitive.MutableIntCollection)4 MutableLongCollection (org.eclipse.collections.api.collection.primitive.MutableLongCollection)4 MutableShortCollection (org.eclipse.collections.api.collection.primitive.MutableShortCollection)4 MutableBooleanIterator (org.eclipse.collections.api.iterator.MutableBooleanIterator)4 Optional (java.util.Optional)3 RichIterable (org.eclipse.collections.api.RichIterable)3 MutableCollection (org.eclipse.collections.api.collection.MutableCollection)3 MutableList (org.eclipse.collections.api.list.MutableList)3 Pair (org.eclipse.collections.api.tuple.Pair)3 Predicates2 (org.eclipse.collections.impl.block.factory.Predicates2)3 Lists (org.eclipse.collections.impl.factory.Lists)3 List (java.util.List)2 Map (java.util.Map)2