@Test public void detectIndexOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 101)); Assert.assertEquals(100, ArrayListIterate.detectIndex(list, Predicates.equal(1))); Assert.assertEquals(0, Iterate.detectIndex(list, Predicates.equal(101))); Assert.assertEquals(-1, Iterate.detectIndex(list, Predicates.equal(200))); }
@Test public void detectIndexWithSmallList() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 5)); Assert.assertEquals(4, Iterate.detectIndexWith(list, Predicates2.equal(), 1)); Assert.assertEquals(0, Iterate.detectIndexWith(list, Predicates2.equal(), 5)); Assert.assertEquals(-1, Iterate.detectIndexWith(list, Predicates2.equal(), 10)); }
@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); }
@Test public void forEachWithIndexOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101)); Iterate.sortThis(list); ArrayListIterate.forEachWithIndex( list, new ObjectIntProcedure<Integer>() { public void value(Integer object, int index) { Assert.assertEquals(index, object - 1); } }); }
@Test public void forEachWithIndex() { ArrayList<Integer> list = this.getIntegerList(); Iterate.sortThis(list); ArrayListIterate.forEachWithIndex( list, new ObjectIntProcedure<Integer>() { public void value(Integer object, int index) { Assert.assertEquals(index, object - 1); } }); }
@Test public void collectWithOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101)); ArrayList<String> result = ArrayListIterate.collectWith( list, new Function2<Integer, Integer, String>() { public String value(Integer argument1, Integer argument2) { return argument1.equals(argument2) ? "101" : null; } }, 101); Verify.assertSize(101, result); Verify.assertContainsAll(result, null, "101"); Assert.assertEquals(100, Iterate.count(result, Predicates.isNull())); }