diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-10-16 06:11:39 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-10-16 06:11:39 -0300 |
| commit | d2be5b73d7a5653ad5c8273c17284346baa6f1c7 (patch) | |
| tree | 9d3c6adb193f53588bd5d004fdf80c0381685351 /base/src/main/java/bjc/utils/esodata/MapSet.java | |
| parent | 0308029629a12711b849ea7765639b9b1f9e03d2 (diff) | |
| parent | d1d01769e7c55f7f62dc01cadf420d5f63424584 (diff) | |
Merge branch 'master' of github.com:bculkin2442/bjc-utils2
Diffstat (limited to 'base/src/main/java/bjc/utils/esodata/MapSet.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/esodata/MapSet.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/esodata/MapSet.java b/base/src/main/java/bjc/utils/esodata/MapSet.java index 94d7700..16def9e 100644 --- a/base/src/main/java/bjc/utils/esodata/MapSet.java +++ b/base/src/main/java/bjc/utils/esodata/MapSet.java @@ -6,49 +6,115 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +/** + * A string-keyed set of maps. + * + * @author bjculkin + * + * @param <KeyType> + * The key type of the maps. + * @param <ValueType> + * The value type of the maps. + */ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType> { private Map<String, Map<KeyType, ValueType>> backing; private Map<KeyType, ValueType> currentMap = null; + /** + * Create a new set of maps. + */ public MapSet() { backing = new HashMap<>(); } + /** + * Create a new set of maps, with the specified set of maps. + * + * @param back + * The set of maps to use. + */ public MapSet(Map<String, Map<KeyType, ValueType>> back) { backing = back; } + /** + * Add a keyed map. + * + * @param key + * The key for the map. + * @param map + * The map itself. + */ public void addMap(String key, Map<KeyType, ValueType> map) { backing.put(key, map); } + /** + * Clear out the contents of the set + */ public void clearMap() { currentMap = null; backing.clear(); } + /** + * Check if there is a map attached to the specified key. + * + * @param key + * The key to look for. + * @return Whether or not there is anything attached to the key. + */ public boolean containsMap(String key) { return backing.containsKey(key); } + /** + * Get the map attached to a specified key. + * + * @param key + * The key to look for. + * @return The map attached to the key. + */ public Map<KeyType, ValueType> getMap(String key) { return backing.get(key); } + /** + * Get all of the backing entries. + * + * @return The backing entries. + */ public Set<Map.Entry<String, Map<KeyType, ValueType>>> getMapEntries() { return backing.entrySet(); } + /** + * Get all of the keys. + * + * @return The keys currently in use. + */ public Set<String> getMapKeys() { return backing.keySet(); } + /** + * Get all of the keyed maps. + * + * @return The keyed maps. + */ public Collection<Map<KeyType, ValueType>> getMapValues() { return backing.values(); } + /** + * Set the current map. + * + * @param key + * The key to use as the current map. + * @return False if there is no map attached to the key, true otherwise. + */ public boolean setMap(String key) { if (!backing.containsKey(key)) return false; @@ -57,6 +123,13 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType> return true; } + /** + * Sets the current map, or creates a new one if there isn't one + * attached to that key. + * + * @param key + * The key to use as the current map. + */ public void setCreateMap(String key) { if (!backing.containsKey(key)) { currentMap = new HashMap<>(); @@ -69,6 +142,14 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType> currentMap = backing.get(key); } + /** + * Set the current map, or bind a map to it. + * + * @param key + * The key to set or bind. + * @param map + * The map to bind to the key if it isn't present. + */ public void setPutMap(String key, Map<KeyType, ValueType> map) { if (!backing.containsKey(key)) { currentMap = map; |
