2015-09-07 11:44:36 -06:00
|
|
|
// containersindepth/CollectionDataTest.java
|
2015-06-15 17:47:35 -07:00
|
|
|
import java.util.*;
|
2015-11-03 12:00:44 -08:00
|
|
|
import java.util.function.*;
|
2015-06-15 17:47:35 -07:00
|
|
|
import com.mindviewinc.util.*;
|
|
|
|
|
2015-11-03 12:00:44 -08:00
|
|
|
class Government implements Supplier<String> {
|
2015-06-15 17:47:35 -07:00
|
|
|
String[] foundation = ("strange women lying in ponds " +
|
|
|
|
"distributing swords is no basis for a system of " +
|
|
|
|
"government").split(" ");
|
|
|
|
private int index;
|
|
|
|
@Override
|
2015-11-03 12:00:44 -08:00
|
|
|
public String get() { return foundation[index++]; }
|
2015-06-15 17:47:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
[strange, women, lying, in, ponds, distributing, swords,
|
|
|
|
is, no, basis, for, a, system, of, government]
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|