OnJava8-Examples/containersindepth/CollectionDataTest.java
2015-11-15 15:51:35 -08:00

31 lines
993 B
Java

// containersindepth/CollectionDataTest.java
// ©2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
import java.util.*;
import java.util.function.*;
import onjava.*;
class Government implements Supplier<String> {
String[] foundation = ("strange women lying in ponds " +
"distributing swords is no basis for a system of " +
"government").split(" ");
private int index;
@Override
public String get() { return foundation[index++]; }
}
public class CollectionDataTest {
public static void main(String[] args) {
Set<String> set = new LinkedHashSet<>(
new CollectionData<>(new Government(), 15));
// Using the convenience method:
set.addAll(CollectionData.list(new Government(), 15));
System.out.println(set);
}
}
/* Output:
[strange, women, lying, in, ponds, distributing, swords,
is, no, basis, for, a, system, of, government]
*/