//: net/mindview/util/MapData.java // A Map filled with data using a generator object. package net.mindview.util; import java.util.*; public class MapData extends LinkedHashMap { // A single Pair Generator: public MapData(Generator> gen, int quantity) { for(int i = 0; i < quantity; i++) { Pair p = gen.next(); put(p.key, p.value); } } // Two separate Generators: public MapData(Generator genK, Generator genV, int quantity) { for(int i = 0; i < quantity; i++) { put(genK.next(), genV.next()); } } // A key Generator and a single value: public MapData(Generator genK, V value, int quantity){ for(int i = 0; i < quantity; i++) { put(genK.next(), value); } } // An Iterable and a value Generator: public MapData(Iterable genK, Generator genV) { for(K key : genK) { put(key, genV.next()); } } // An Iterable and a single value: public MapData(Iterable genK, V value) { for(K key : genK) { put(key, value); } } // Generic convenience methods: public static MapData map(Generator> gen, int quantity) { return new MapData<>(gen, quantity); } public static MapData map(Generator genK, Generator genV, int quantity) { return new MapData<>(genK, genV, quantity); } public static MapData map(Generator genK, V value, int quantity) { return new MapData<>(genK, value, quantity); } public static MapData map(Iterable genK, Generator genV) { return new MapData<>(genK, genV); } public static MapData map(Iterable genK, V value) { return new MapData<>(genK, value); } } ///:~