Skip to content

Instantly share code, notes, and snippets.

@Satomaru
Created July 6, 2017 06:49
Show Gist options
  • Save Satomaru/245d835a80959fb4c6c9ae26e57791e9 to your computer and use it in GitHub Desktop.
Save Satomaru/245d835a80959fb4c6c9ae26e57791e9 to your computer and use it in GitHub Desktop.
public final class MapLists<K, V> {
public final class Maps {
private final HashMap<K, V> map = new HashMap<K, V>();
private Maps() {
}
public Maps put(K key, V value) {
map.put(key, value);
return this;
}
public MapLists<K, V> end() {
list.add((unmodifiable) ? Collections.unmodifiableMap(map) : map);
return MapLists.this;
}
}
public static <K, V> MapLists<K, V> begin(boolean unmodifiable) {
return new MapLists<K, V>(unmodifiable);
}
private final List<Map<K, V>> list = new ArrayList<Map<K, V>>();
private final boolean unmodifiable;
private MapLists(boolean unmodifiable) {
this.unmodifiable = unmodifiable;
}
public Maps row() {
return new Maps();
}
public List<Map<K, V>> end() {
return (unmodifiable) ? Collections.unmodifiableList(list) : list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment