@Override public void withoutAllKeys() { MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A"); MutableMap<Integer, String> mapWithout = map.withoutAllKeys(FastList.newListWith(2, 3)); Assert.assertSame(map, mapWithout); mapWithout = map.withoutAllKeys(FastList.newListWith(1, 2)); Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout); Verify.assertInstanceOf(EmptyMap.class, mapWithout); }
@Test public void testForEachWith() { MutableList<String> result = Lists.mutable.of(); MutableList<String> source = Lists.fixedSize.of("1", "2", "3", "4", "5", "6"); source.forEachWith(Procedures2.fromProcedure(CollectionAddProcedure.on(result)), null); Assert.assertEquals(FastList.newListWith("1", "2", "3", "4", "5", "6"), result); }
@Override @Test public void forEachKey() { MutableList<Integer> collection = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1"); map.forEachKey(CollectionAddProcedure.on(collection)); Assert.assertEquals(FastList.newListWith(1), collection); }
@Test public void without() { MutableList<Integer> list = new SextupletonList<Integer>(1, 2, 3, 2, 3, 4); Assert.assertSame(list, list.without(9)); list = list.without(2); Verify.assertListsEqual(FastList.newListWith(1, 3, 2, 3, 4), list); Verify.assertInstanceOf(QuintupletonList.class, list); }
@Override @Test public void keySet() { MutableList<Integer> result = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One"); for (Integer key : map.keySet()) { result.add(key); } Assert.assertEquals(FastList.newListWith(1), result); }
@Override @Test public void values() { MutableList<String> result = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One"); for (String value : map.values()) { result.add(value); } Assert.assertEquals(FastList.newListWith("One"), result); }
@Override @Test public void entrySet() { MutableList<String> result = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One"); for (Map.Entry<Integer, String> entry : map.entrySet()) { result.add(entry.getValue()); } Assert.assertEquals(FastList.newListWith("One"), result); }
@Override @Test public void iterator() { MutableList<String> collection = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1"); for (String eachValue : map) { collection.add(eachValue); } Assert.assertEquals(FastList.newListWith("1"), collection); }
@Test public void notIn() { MutableList<String> odds = Lists.fixedSize.of("1", "3"); Assert.assertFalse(Predicates2.notIn().accept("1", odds)); Assert.assertTrue(Predicates2.notIn().accept("2", odds)); Assert.assertNotNull(Predicates2.notIn().toString()); MutableList<String> list = Lists.fixedSize.of("1", "2"); MutableList<String> newList = ListIterate.filterWith(list, Predicates2.notIn(), odds); Assert.assertEquals(FastList.newListWith("2"), newList); }
@Test public void attributeNotIn() { Function<String, String> function = StringFunctions.toLowerCase(); MutableList<String> lowerList = Lists.fixedSize.of("a", "b"); Assert.assertFalse(Predicates2.attributeNotIn(function).accept("A", lowerList)); Assert.assertTrue(Predicates2.attributeNotIn(function).accept("C", lowerList)); MutableList<String> upperList = Lists.fixedSize.of("A", "C"); MutableList<String> newList = ListIterate.filterNotWith(upperList, Predicates2.attributeNotIn(function), lowerList); Assert.assertEquals(FastList.newListWith("A"), newList); }
@Test public void attributeIn_MultiTypes() { MutableList<String> stringInts = Lists.fixedSize.of("1", "2"); Assert.assertTrue(Predicates2.attributeIn(Functions.getToString()).accept(1, stringInts)); Assert.assertFalse(Predicates2.attributeIn(Functions.getToString()).accept(3, stringInts)); Assert.assertFalse(Predicates2.attributeIn(Functions.getToString()).accept(3, stringInts)); MutableList<Integer> intList = Lists.fixedSize.of(1, 3); MutableList<Integer> newList = ListIterate.filterWith( intList, Predicates2.attributeIn(Functions.getToString()), stringInts); Assert.assertEquals(FastList.newListWith(1), newList); }
@Test public void attributeIn() { MutableList<String> upperList = Lists.fixedSize.of("A", "B"); Assert.assertTrue( Predicates2.attributeIn(StringFunctions.toUpperCase()).accept("a", upperList)); Assert.assertFalse( Predicates2.attributeIn(StringFunctions.toUpperCase()).accept("c", upperList)); MutableList<String> lowerList = Lists.fixedSize.of("a", "c"); MutableList<String> newList = ListIterate.filterWith( lowerList, Predicates2.attributeIn(StringFunctions.toUpperCase()), upperList); Assert.assertEquals(FastList.newListWith("a"), newList); }
@Override @Test public void forEachKeyValue() { final MutableList<String> collection = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One"); map.forEachKeyValue( new Procedure2<Integer, String>() { public void value(Integer key, String value) { collection.add(key + value); } }); Assert.assertEquals(FastList.newListWith("1One"), collection); }
@Override @Test public void forEachWith() { final MutableList<Integer> result = Lists.mutable.of(); MutableMap<Integer, Integer> map = new SingletonMap<Integer, Integer>(1, 1); map.forEachWith( new Procedure2<Integer, Integer>() { public void value(Integer argument1, Integer argument2) { result.add(argument1 + argument2); } }, 10); Assert.assertEquals(FastList.newListWith(11), result); }
@Override @Test public void forEachWithIndex() { final MutableList<String> result = Lists.mutable.of(); MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One"); map.forEachWithIndex( new ObjectIntProcedure<String>() { public void value(String value, int index) { result.add(value); result.add(String.valueOf(index)); } }); Assert.assertEquals(FastList.newListWith("One", "0"), result); }
@Test public void testForEachWithIndex() { final int[] indexSum = new int[1]; final MutableList<String> result = Lists.mutable.of(); MutableList<String> source = Lists.fixedSize.of("1", "2", "3", "4", "5", "6"); source.forEachWithIndex( new ObjectIntProcedure<String>() { public void value(String each, int index) { result.add(each); indexSum[0] += index; } }); Assert.assertEquals(FastList.newListWith("1", "2", "3", "4", "5", "6"), result); Assert.assertEquals(15, indexSum[0]); }
@Test public void testSet() { final MutableList<String> list = Lists.fixedSize.of("1", "2", "3", "4", "5", "6"); Assert.assertEquals("1", list.set(0, "6")); Assert.assertEquals("2", list.set(1, "5")); Assert.assertEquals("3", list.set(2, "4")); Assert.assertEquals("4", list.set(3, "3")); Assert.assertEquals("5", list.set(4, "2")); Assert.assertEquals("6", list.set(5, "1")); Assert.assertEquals(FastList.newListWith("6", "5", "4", "3", "2", "1"), list); Verify.assertThrows( IndexOutOfBoundsException.class, new Runnable() { public void run() { list.set(6, "0"); } }); }
private void assertUnchanged() { Verify.assertSize(6, this.list); Verify.assertNotContains("7", this.list); Assert.assertEquals(FastList.newListWith("1", "2", "3", "4", "5", "6"), this.list); }
@Override @Test public void asLazyValues() { MutableList<Integer> values = Maps.fixedSize.of(1, 1).valuesView().toSortedList(); Assert.assertEquals(FastList.newListWith(1), values); }