2015-09-07 11:44:36 -06:00
|
|
|
|
// com/mindviewinc/util/MapData.java
|
2015-06-15 17:47:35 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
|
|
|
|
// A Map filled with data using a generator object.
|
|
|
|
|
package com.mindviewinc.util;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public class MapData<K, V> extends LinkedHashMap<K, V> {
|
2015-06-15 17:47:35 -07:00
|
|
|
|
// A single Pair Generator:
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public MapData(Generator<Pair<K, V>> gen, int quantity) {
|
2015-06-15 17:47:35 -07:00
|
|
|
|
for(int i = 0; i < quantity; i++) {
|
2015-09-07 11:44:36 -06:00
|
|
|
|
Pair<K, V> p = gen.next();
|
2015-06-15 17:47:35 -07:00
|
|
|
|
put(p.key, p.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Two separate Generators:
|
|
|
|
|
public MapData(Generator<K> genK, Generator<V> 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<K> 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<K> genK, Generator<V> genV) {
|
|
|
|
|
for(K key : genK) {
|
|
|
|
|
put(key, genV.next());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// An Iterable and a single value:
|
|
|
|
|
public MapData(Iterable<K> genK, V value) {
|
|
|
|
|
for(K key : genK) {
|
|
|
|
|
put(key, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Generic convenience methods:
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public static <K, V> MapData<K, V>
|
|
|
|
|
map(Generator<Pair<K, V>> gen, int quantity) {
|
2015-06-15 17:47:35 -07:00
|
|
|
|
return new MapData<>(gen, quantity);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public static <K, V> MapData<K, V>
|
2015-06-15 17:47:35 -07:00
|
|
|
|
map(Generator<K> genK, Generator<V> genV, int quantity) {
|
|
|
|
|
return new MapData<>(genK, genV, quantity);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public static <K, V> MapData<K, V>
|
2015-06-15 17:47:35 -07:00
|
|
|
|
map(Generator<K> genK, V value, int quantity) {
|
|
|
|
|
return new MapData<>(genK, value, quantity);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public static <K, V> MapData<K, V>
|
2015-06-15 17:47:35 -07:00
|
|
|
|
map(Iterable<K> genK, Generator<V> genV) {
|
|
|
|
|
return new MapData<>(genK, genV);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
public static <K, V> MapData<K, V>
|
2015-06-15 17:47:35 -07:00
|
|
|
|
map(Iterable<K> genK, V value) {
|
|
|
|
|
return new MapData<>(genK, value);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
}
|