@Override @Test public void listIterator() { super.listIterator(); CompositeFastList<String> composite = new CompositeFastList<String>(); FastList<String> firstBit = FastList.newListWith("one", "two"); FastList<String> secondBit = FastList.newListWith("three"); composite.addAll(firstBit); composite.addAll(secondBit); ListIterator<String> listIterator = composite.listIterator(); listIterator.add("four"); Verify.assertSize(4, composite); Assert.assertTrue(listIterator.hasNext()); String element = listIterator.next(); Assert.assertEquals("one", element); String element3 = listIterator.next(); Assert.assertEquals("two", element3); String element2 = listIterator.previous(); Assert.assertEquals("two", element2); String element1 = listIterator.next(); Assert.assertEquals("two", element1); listIterator.remove(); Verify.assertSize(3, composite); }
@Override @Test public void subList() { super.subList(); MutableList<String> list = this.newWith("A", "B", "C", "D"); MutableList<String> sublist = list.subList(1, 3); Verify.assertPostSerializedEqualsAndHashCode(sublist); Verify.assertSize(2, sublist); Verify.assertContainsAll(sublist, "B", "C"); sublist.add("X"); Verify.assertSize(3, sublist); Verify.assertContainsAll(sublist, "B", "C", "X"); Verify.assertSize(5, list); Verify.assertContainsAll(list, "A", "B", "C", "X", "D"); sublist.remove("X"); Verify.assertContainsAll(sublist, "B", "C"); Verify.assertContainsAll(list, "A", "B", "C", "D"); Assert.assertEquals("C", sublist.set(1, "R")); Verify.assertContainsAll(sublist, "B", "R"); Verify.assertContainsAll(list, "A", "B", "R", "D"); sublist.addAll(Arrays.asList("W", "G")); Verify.assertContainsAll(sublist, "B", "R", "W", "G"); Verify.assertContainsAll(list, "A", "B", "R", "W", "G", "D"); sublist.clear(); Verify.assertEmpty(sublist); Verify.assertContainsAll(list, "A", "D"); }
@Override @Test public void retainAllIterable() { super.retainAllIterable(); MutableList<Integer> objects = this.newWith(1, 2, 3); objects.retainAllIterable(Lists.fixedSize.of(1, 2)); Verify.assertSize(2, objects); Verify.assertContainsAll(objects, 1, 2); MutableList<Integer> objects2 = this.newWith(1, 2, 3); objects2.retainAllIterable(Lists.fixedSize.of(1)); Verify.assertSize(1, objects2); Verify.assertContainsAll(objects2, 1); MutableList<Integer> objects3 = this.newWith(1, 2, 3); objects3.retainAllIterable(Lists.fixedSize.of(3)); Verify.assertSize(1, objects3); Verify.assertContainsAll(objects3, 3); MutableList<Integer> objects4 = this.newWith(1, 2, 3); objects4.retainAllIterable(Lists.fixedSize.of(2)); Verify.assertSize(1, objects4); Verify.assertContainsAll(objects4, 2); MutableList<Integer> objects5 = this.newWith(1, 2, 3); objects5.retainAllIterable(Lists.fixedSize.of()); Verify.assertEmpty(objects5); MutableList<Integer> objects6 = this.newWith(1, 2, 3); objects6.retainAllIterable(Lists.fixedSize.of(1, 2, 3)); Verify.assertSize(3, objects6); Verify.assertContainsAll(objects6, 1, 2, 3); }
@Override @Test public void removeAllIterable() { super.removeAllIterable(); MutableList<Integer> objects = MultiReaderFastList.newListWith(1, 2, 3); objects.removeAllIterable(Lists.fixedSize.of(1, 2)); Verify.assertSize(1, objects); Verify.assertContains(3, objects); MutableList<Integer> objects2 = MultiReaderFastList.newListWith(1, 2, 3); objects2.removeAllIterable(Lists.fixedSize.of(1)); Verify.assertSize(2, objects2); Verify.assertContainsAll(objects2, 2, 3); MutableList<Integer> objects3 = MultiReaderFastList.newListWith(1, 2, 3); objects3.removeAllIterable(Lists.fixedSize.of(3)); Verify.assertSize(2, objects3); Verify.assertContainsAll(objects3, 1, 2); MutableList<Integer> objects4 = MultiReaderFastList.newListWith(1, 2, 3); objects4.removeAllIterable(Lists.fixedSize.of()); Verify.assertSize(3, objects4); Verify.assertContainsAll(objects4, 1, 2, 3); MutableList<Integer> objects5 = MultiReaderFastList.newListWith(1, 2, 3); objects5.removeAllIterable(Lists.fixedSize.of(1, 2, 3)); Verify.assertEmpty(objects5); MutableList<Integer> objects6 = MultiReaderFastList.newListWith(1, 2, 3); objects6.removeAllIterable(Lists.fixedSize.of(2)); Verify.assertSize(2, objects6); Verify.assertContainsAll(objects6, 1, 3); }
@Override @Test public void forEachWithIndex() { super.forEachWithIndex(); MutableList<Integer> list = MultiReaderFastList.newList(Interval.oneTo(5)); list.forEachWithIndex((object, index) -> Assert.assertEquals(index, object - 1)); }
@Override @Test public void newListWithSize() { super.newListWithSize(); MutableList<Integer> objects = ArrayListAdapter.<Integer>newList(4).with(1, 2, 3); Assert.assertEquals(1, objects.indexOf(2)); }
@Override @Test public void testClone() { super.testClone(); MutableList<Integer> list = this.newWith(1, 2, 3); MutableList<Integer> list2 = list.clone(); Verify.assertListsEqual(list, list2); }
@Override @Test public void retainAll() { super.retainAll(); MutableList<String> list = new CompositeFastList<String>(); list.addAll(FastList.newListWith("1", "2", "3", "4")); list.addAll(FastList.newListWith("3", "B", "3", "B")); list.retainAll(FastList.newList().with("2", "B")); Verify.assertSize(3, list); }
@Override @Test public void removeIf() { super.removeIf(); MutableList<Integer> objects = this.newWith(1, 2, 3, null); objects.removeIf(Predicates.isNull()); Verify.assertSize(3, objects); Verify.assertContainsAll(objects, 1, 2, 3); }
@Override @Test public void clear() { super.clear(); MutableList<String> list = new CompositeFastList<String>(); list.addAll(FastList.newListWith("1", "2", "3", "4")); list.addAll(FastList.newListWith("3", "B", "3", "B")); list.clear(); Assert.assertTrue(list.isEmpty()); Assert.assertEquals(0, list.size()); }
@Override @Test public void toArray() { super.toArray(); MutableList<String> list = new CompositeFastList<String>(); list.addAll(FastList.newListWith("1", "2", "3", "4")); list.addAll(Lists.mutable.<String>of()); list.addAll(FastList.newListWith("3", "B", "3", "B")); list.addAll(Lists.mutable.<String>of()); Assert.assertArrayEquals(new String[] {"1", "2", "3", "4", "3", "B", "3", "B"}, list.toArray()); }
@Override @Test public void lastIndexOf() { super.lastIndexOf(); MutableList<String> list = new CompositeFastList<String>(); list.addAll(FastList.newListWith("1", "2", "3", "4")); list.addAll(FastList.newListWith("3", "B", "3", "B")); Assert.assertEquals(6, list.lastIndexOf("3")); Assert.assertEquals(3, list.lastIndexOf("4")); Assert.assertEquals(-1, list.lastIndexOf("missing")); }
@Override @Test public void reverseThis() { super.reverseThis(); CompositeFastList<Integer> composite = new CompositeFastList<Integer>(); composite.addAll(FastList.newListWith(9, 8, 7)); composite.addAll(FastList.newListWith(6, 5, 4)); composite.addAll(FastList.newListWith(3, 2, 1)); CompositeFastList<Integer> reversed = composite.reverseThis(); Assert.assertSame(composite, reversed); Assert.assertEquals(Interval.oneTo(9), reversed); }
@Override @Test public void forEach() { super.forEach(); MutableList<Integer> list = FastList.newList(); CompositeFastList<Integer> iterables = new CompositeFastList<Integer>(); iterables.addComposited(Interval.oneTo(5).toList()); iterables.addComposited(Interval.fromTo(6, 10).toList()); iterables.forEach(CollectionAddProcedure.on(list)); Verify.assertSize(10, list); Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11))); }
@Override @Test public void removeObject() { super.removeObject(); MutableList<Integer> integers = this.newWith(1, 2, 3, 4); Integer doesExist = 1; integers.remove(doesExist); Verify.assertStartsWith(integers, 2, 3, 4); Integer doesNotExist = 5; Assert.assertFalse(integers.remove(doesNotExist)); }
@Override @Test public void forEachWithIndex() { super.forEachWithIndex(); MutableList<Integer> list = FastList.newList(); CompositeFastList<Integer> iterables = new CompositeFastList<Integer>(); iterables.addComposited(Interval.fromTo(6, 10).toList()); iterables.addComposited(Interval.oneTo(5).toList()); iterables.forEachWithIndex((each, index) -> list.add(index, each)); Verify.assertSize(10, list); Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11))); Verify.assertStartsWith(list, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5); }
@Override @Test public void addAllIterable() { super.addAllIterable(); MutableList<Integer> integers = MultiReaderFastList.newList(); Assert.assertTrue(integers.addAllIterable(Lists.fixedSize.of(1, 2, 3, 4))); Verify.assertContainsAll(integers, 1, 2, 3, 4); Assert.assertTrue(integers.addAllIterable(FastList.<Integer>newList(4).with(1, 2, 3, 4))); Verify.assertStartsWith(integers, 1, 2, 3, 4, 1, 2, 3, 4); Assert.assertTrue(integers.addAllIterable(Sets.fixedSize.of(5))); Verify.assertStartsWith(integers, 1, 2, 3, 4, 1, 2, 3, 4, 5); }
@Override @Test public void forEachWith() { super.forEachWith(); MutableList<Integer> list = FastList.newList(); CompositeFastList<Integer> iterables = new CompositeFastList<Integer>(); iterables.addComposited(Interval.fromTo(6, 10).toList()); iterables.addComposited(Interval.oneTo(5).toList()); iterables.forEachWith((each, parameter) -> list.add(parameter.intValue(), each), 0); Verify.assertSize(10, list); Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11))); Verify.assertStartsWith(list, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6); }
@Override @Test public void set() { super.set(); MutableList<String> list = new CompositeFastList<String>(); list.addAll(FastList.newListWith("1", "2", "3", "4")); list.addAll(FastList.newListWith("A", "B", "C", "B")); Assert.assertEquals("1", list.set(0, "NEW")); Verify.assertSize(8, list); Assert.assertEquals("NEW", list.getFirst()); Assert.assertEquals("2", list.get(1)); Assert.assertEquals("B", list.set(7, "END")); Verify.assertSize(8, list); Assert.assertEquals("END", list.getLast()); }