@Test public void forEachUsingFromToWithOptimisable() { ArrayList<Integer> expected = Interval.oneTo(5).addAllTo(new ArrayList<Integer>()); final ArrayList<Integer> optimisableList = Interval.oneTo(105).addAllTo(new ArrayList<Integer>()); ArrayList<Integer> results = new ArrayList<Integer>(); ArrayListIterate.forEach(optimisableList, 0, 4, CollectionAddProcedure.on(results)); Assert.assertEquals(expected, results); MutableList<Integer> reverseResults = Lists.mutable.of(); final CollectionAddProcedure<Integer> procedure = CollectionAddProcedure.on(reverseResults); ArrayListIterate.forEach(optimisableList, 4, 0, procedure); Assert.assertEquals(ListIterate.reverseThis(expected), reverseResults); Verify.assertThrows( IndexOutOfBoundsException.class, new Runnable() { public void run() { ArrayListIterate.forEach(optimisableList, 104, -1, procedure); } }); Verify.assertThrows( IndexOutOfBoundsException.class, new Runnable() { public void run() { ArrayListIterate.forEach(optimisableList, -1, 4, procedure); } }); }
@Test public void forEachOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101)); Iterate.sortThis(list); FastList<Integer> result = FastList.newList(101); ArrayListIterate.forEach(list, CollectionAddProcedure.<Integer>on(result)); Verify.assertListsEqual(list, result); }
@Test public void forEach() { ArrayList<Integer> list = this.getIntegerList(); Iterate.sortThis(list); MutableList<Integer> result = Lists.mutable.of(); ArrayListIterate.forEach(list, CollectionAddProcedure.<Integer>on(result)); Verify.assertListsEqual(list, result); }