@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); }
@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 testSubList() { MutableList<String> list = Lists.fixedSize.of("one", "two", "three", "four", "five", "six"); MutableList<String> subList = list.subList(0, 5); MutableList<String> upperList = Lists.fixedSize.of("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX"); for (String each : subList) { Verify.assertContains(each.toUpperCase(), upperList); } }
@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"); } }); }
public <V> ImmutableList<V> flatTransform(Function<? super T, ? extends Iterable<V>> function) { MutableList<V> result = Lists.mutable.of(); this.forEach(new FlatTransformProcedure<T, V>(function, result)); return result.toImmutable(); }
public <V> ImmutableList<V> transformIf( Predicate<? super T> predicate, Function<? super T, ? extends V> function) { MutableList<V> result = Lists.mutable.of(); this.forEach(new TransformIfProcedure<T, V>(result, function, predicate)); return result.toImmutable(); }
@Test public void testGetFirstGetLast() { MutableList<String> list6 = Lists.fixedSize.of("1", "2", "3", "4", "5", "6"); Assert.assertEquals("1", list6.getFirst()); Assert.assertEquals("6", list6.getLast()); }