Search in sources :

Example 1 with IntegerWithCast

use of org.eclipse.collections.impl.IntegerWithCast in project eclipse-collections by eclipse.

the class AbstractUnifiedSetTestCase method retainAllFromKeySet_null_collision.

@Test
public void retainAllFromKeySet_null_collision() {
    IntegerWithCast key = new IntegerWithCast(0);
    MutableSet<IntegerWithCast> mutableSet = this.newWith(null, key);
    Assert.assertFalse(mutableSet.retainAll(FastList.newListWith(key, null)));
    Assert.assertEquals(this.newWith(null, key), mutableSet);
}
Also used : IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) Test(org.junit.Test)

Example 2 with IntegerWithCast

use of org.eclipse.collections.impl.IntegerWithCast in project eclipse-collections by eclipse.

the class AbstractMutableBiMapTestCase method nullCollisionWithCastInEquals.

@Override
@Test
public void nullCollisionWithCastInEquals() {
    MutableBiMap<IntegerWithCast, String> mutableMap = this.newMap();
    mutableMap.put(new IntegerWithCast(0), "Test 2");
    mutableMap.forcePut(new IntegerWithCast(0), "Test 3");
    mutableMap.put(null, "Test 1");
    Assert.assertEquals(this.newMapWithKeysValues(new IntegerWithCast(0), "Test 3", null, "Test 1"), mutableMap);
    Assert.assertEquals("Test 3", mutableMap.get(new IntegerWithCast(0)));
    Assert.assertEquals("Test 1", mutableMap.get(null));
}
Also used : IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) Test(org.junit.Test)

Example 3 with IntegerWithCast

use of org.eclipse.collections.impl.IntegerWithCast in project eclipse-collections by eclipse.

the class MutableMapIterableTestCase method retainAllFromKeySet_null_collision.

@Test
public void retainAllFromKeySet_null_collision() {
    if (this.newMap() instanceof ConcurrentMap || this.newMap() instanceof SortedMap) {
        return;
    }
    IntegerWithCast key = new IntegerWithCast(0);
    MutableMapIterable<IntegerWithCast, String> mutableMapIterable = this.newMapWithKeysValues(null, "Test 1", key, "Test 2");
    Assert.assertFalse(mutableMapIterable.keySet().retainAll(FastList.newListWith(key, null)));
    Assert.assertEquals(this.newMapWithKeysValues(null, "Test 1", key, "Test 2"), mutableMapIterable);
}
Also used : SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) Test(org.junit.Test)

Example 4 with IntegerWithCast

use of org.eclipse.collections.impl.IntegerWithCast in project eclipse-collections by eclipse.

the class AbstractMutableSetTestCase method removeIf.

@Override
@Test
public void removeIf() {
    super.removeIf();
    MutableSet<IntegerWithCast> set = this.newWith();
    MutableList<IntegerWithCast> collisions = COLLISIONS.collect(IntegerWithCast::new);
    set.addAll(collisions);
    collisions.reverseForEach(each -> {
        Assert.assertFalse(set.remove(null));
        Assert.assertTrue(set.remove(each));
        Assert.assertFalse(set.remove(each));
        Assert.assertFalse(set.remove(null));
        Assert.assertFalse(set.remove(new IntegerWithCast(COLLISION_10)));
    });
    Assert.assertEquals(UnifiedSet.<IntegerWithCast>newSet(), set);
    collisions.forEach(Procedures.cast(each -> {
        MutableSet<IntegerWithCast> set2 = this.newWith();
        set2.addAll(collisions);
        Assert.assertFalse(set2.remove(null));
        Assert.assertTrue(set2.remove(each));
        Assert.assertFalse(set2.remove(each));
        Assert.assertFalse(set2.remove(null));
        Assert.assertFalse(set2.remove(new IntegerWithCast(COLLISION_10)));
    }));
    // remove the second-to-last item in a fully populated single chain to cause the last item to move
    MutableSet<Integer> set3 = this.newWith(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4);
    Assert.assertTrue(set3.remove(COLLISION_3));
    Assert.assertEquals(UnifiedSet.newSetWith(COLLISION_1, COLLISION_2, COLLISION_4), set3);
    Assert.assertTrue(set3.remove(COLLISION_2));
    Assert.assertEquals(UnifiedSet.newSetWith(COLLISION_1, COLLISION_4), set3);
    // search a chain for a non-existent element
    MutableSet<Integer> chain = this.newWith(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4);
    Assert.assertFalse(chain.remove(COLLISION_5));
    // search a deep chain for a non-existent element
    MutableSet<Integer> deepChain = this.newWith(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4, COLLISION_5, COLLISION_6, COLLISION_7);
    Assert.assertFalse(deepChain.remove(COLLISION_8));
    // search for a non-existent element
    MutableSet<Integer> empty = this.newWith();
    Assert.assertFalse(empty.remove(COLLISION_1));
}
Also used : Arrays(java.util.Arrays) ArrayAdapter(org.eclipse.collections.impl.list.fixed.ArrayAdapter) Function(org.eclipse.collections.api.block.function.Function) UnsortedSetIterable(org.eclipse.collections.api.set.UnsortedSetIterable) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) AbstractCollectionTestCase(org.eclipse.collections.impl.collection.mutable.AbstractCollectionTestCase) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) Interval(org.eclipse.collections.impl.list.Interval) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Counter(org.eclipse.collections.impl.Counter) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Iterator(java.util.Iterator) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) MutableSortedBag(org.eclipse.collections.api.bag.sorted.MutableSortedBag) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) Iterables.iSet(org.eclipse.collections.impl.factory.Iterables.iSet) Lists(org.eclipse.collections.impl.factory.Lists) Assert(org.junit.Assert) Collections(java.util.Collections) MutableSet(org.eclipse.collections.api.set.MutableSet) IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) Test(org.junit.Test)

Example 5 with IntegerWithCast

use of org.eclipse.collections.impl.IntegerWithCast in project eclipse-collections by eclipse.

the class AbstractUnifiedSetTestCase method addOnObjectWithCastInEquals.

@Test
public void addOnObjectWithCastInEquals() {
    if (this.newWith() instanceof SortedSet) {
        return;
    }
    MutableSet<IntegerWithCast> mutableSet = this.newWith(new IntegerWithCast(0));
    Assert.assertFalse(mutableSet.add(new IntegerWithCast(0)));
    Assert.assertTrue(mutableSet.add(null));
    Assert.assertFalse(mutableSet.add(null));
}
Also used : IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) SortedSet(java.util.SortedSet) Test(org.junit.Test)

Aggregations

IntegerWithCast (org.eclipse.collections.impl.IntegerWithCast)8 Test (org.junit.Test)8 SortedMap (java.util.SortedMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 SortedSet (java.util.SortedSet)1 LazyIterable (org.eclipse.collections.api.LazyIterable)1 RichIterable (org.eclipse.collections.api.RichIterable)1 MutableSortedBag (org.eclipse.collections.api.bag.sorted.MutableSortedBag)1 Function (org.eclipse.collections.api.block.function.Function)1 MutableList (org.eclipse.collections.api.list.MutableList)1 MutableSet (org.eclipse.collections.api.set.MutableSet)1 UnsortedSetIterable (org.eclipse.collections.api.set.UnsortedSetIterable)1 Pair (org.eclipse.collections.api.tuple.Pair)1 Counter (org.eclipse.collections.impl.Counter)1 TreeBag (org.eclipse.collections.impl.bag.sorted.mutable.TreeBag)1 Predicates (org.eclipse.collections.impl.block.factory.Predicates)1