@Test public void toSortedSet_with_comparator() { LazyIterable<Integer> integers = this.newWith(2, 4, 4, 2, 1, 4, 1, 3); MutableSortedSet<Integer> set = integers.toSortedSet(Collections.<Integer>reverseOrder()); Verify.assertSortedSetsEqual( TreeSortedSet.newSetWith(Collections.<Integer>reverseOrder(), 1, 2, 3, 4), set); }
@Test public void asLazy() { ImmutableBag<String> bag = this.newBag(); LazyIterable<String> lazyIterable = bag.asLazy(); Verify.assertInstanceOf(LazyIterable.class, lazyIterable); Assert.assertEquals(bag, lazyIterable.toBag()); }
@Test public void toSortedMap() { LazyIterable<Integer> integers = this.newWith(1, 2, 3); MutableSortedMap<Integer, String> map = integers.toSortedMap(Functions.getIntegerPassThru(), Functions.getToString()); Verify.assertMapsEqual(TreeSortedMap.newMapWith(1, "1", 2, "2", 3, "3"), map); Verify.assertListsEqual(FastList.newListWith(1, 2, 3), map.keySet().toList()); }
/** @deprecated since 3.0. */ @Deprecated @Test public void lazySelectForEach() { UnifiedSetWithHashingStrategy<Integer> integers = UnifiedSetWithHashingStrategy.newSetWith(INTEGER_HASHING_STRATEGY, 1, 2, 3, 4, 5); LazyIterable<Integer> select = integers.lazySelect(Predicates.lessThan(5)); Sum sum = new IntegerSum(0); select.forEach(new SumProcedure<Integer>(sum)); Assert.assertEquals(10, sum.getValue().intValue()); }
@Test public void toSortedMap_with_comparator() { LazyIterable<Integer> integers = this.newWith(1, 2, 3); MutableSortedMap<Integer, String> map = integers.toSortedMap( Comparators.<Integer>reverseNaturalOrder(), Functions.getIntegerPassThru(), Functions.getToString()); Verify.assertMapsEqual( TreeSortedMap.newMapWith( Comparators.<Integer>reverseNaturalOrder(), 1, "1", 2, "2", 3, "3"), map); Verify.assertListsEqual(FastList.newListWith(3, 2, 1), map.keySet().toList()); }
/** @deprecated since 3.0. */ @Deprecated @Test public void lazyCollectForEach() { UnifiedSetWithHashingStrategy<Integer> integers = UnifiedSetWithHashingStrategy.newSetWith(INTEGER_HASHING_STRATEGY, 1, 2, 3, 4, 5); LazyIterable<String> select = integers.lazyCollect(String::valueOf); Procedure<String> builder = Procedures.append(new StringBuilder()); select.forEach(builder); String result = builder.toString(); Verify.assertContains("1", result); Verify.assertContains("2", result); Verify.assertContains("3", result); Verify.assertContains("4", result); Verify.assertContains("5", result); }
@Test public void flatCollect() { LazyIterable<Integer> collection = this.newWith(1, 2, 3, 4); Function<Integer, MutableList<String>> function = new Function<Integer, MutableList<String>>() { public MutableList<String> valueOf(Integer object) { return FastList.newListWith(String.valueOf(object)); } }; Verify.assertListsEqual( FastList.newListWith("1", "2", "3", "4"), collection.flatCollect(function).toSortedList()); Verify.assertSetsEqual( UnifiedSet.newSetWith("1", "2", "3", "4"), collection.flatCollect(function, UnifiedSet.<String>newSet())); }
@Test public void asLazy() { MutableMap<String, String> map = this.classUnderTest(); LazyIterable<String> lazy = map.asLazy(); switch (map.size()) { case 1: Verify.assertContains("One", lazy.toList()); break; case 2: Verify.assertContainsAll(lazy.toList(), "One", "Two"); break; case 3: Verify.assertContainsAll(lazy.toList(), "One", "Two", "Three"); break; default: Verify.assertEmpty(lazy.toList()); break; } }
@Test public void asLazy() { ImmutableMap<String, String> map = this.newMapWithKeysValues("1", "One", "2", "Two", "3", "Three", "4", "Four"); LazyIterable<String> lazy = map.asLazy(); switch (map.size()) { case 1: Verify.assertContains("One", lazy.toList()); break; case 2: Verify.assertContainsAll(lazy.toList(), "One", "Two"); break; case 3: Verify.assertContainsAll(lazy.toList(), "One", "Two", "Three"); break; case 4: Verify.assertContainsAll(lazy.toList(), "One", "Two", "Three", "Four"); break; default: Verify.assertEmpty(lazy.toList()); break; } }
@Test public void toSortedSetBy() { LazyIterable<Integer> integers = this.newWith(2, 4, 1, 3); MutableSortedSet<Integer> set = integers.toSortedSetBy(Functions.getToString()); Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3, 4), set); }
@Test public void toSortedSet() { LazyIterable<Integer> integers = this.newWith(2, 4, 1, 3, 2, 1, 3, 4); MutableSortedSet<Integer> set = integers.toSortedSet(); Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3, 4), set); }
@Test public void toSortedListBy() { LazyIterable<Integer> integers = this.newWith(2, 4, 1, 3); MutableList<Integer> list = integers.toSortedListBy(Functions.getToString()); Assert.assertEquals(FastList.newListWith(1, 2, 3, 4), list); }