OnJava8-Examples/containers/CollectionDataTest.java

26 lines
838 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: containers/CollectionDataTest.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
import java.util.*;
import net.mindview.util.*;
class Government implements Generator<String> {
String[] foundation = ("strange women lying in ponds " +
"distributing swords is no basis for a system of " +
"government").split(" ");
private int index;
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public String next() { return foundation[index++]; }
}
public class CollectionDataTest {
public static void main(String[] args) {
2015-05-05 11:20:13 -07:00
Set<String> set = new LinkedHashSet<>(
new CollectionData<>(new Government(), 15));
2015-04-20 15:36:01 -07:00
// 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]
*///:~