/*
* esodata - data structures and other things, of varying utility
* Copyright 2022, Ben Culkin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package bjc.esodata;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* A string-keyed set of maps.
*
* @author bjculkin
*
* @param
* The key type of the maps.
* @param
* The value type of the maps.
*/
public class MapSet extends AbstractMap {
private Map> backing;
private Map 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> 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 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 getMap(String key) {
return backing.get(key);
}
/**
* Get all of the backing entries.
*
* @return The backing entries.
*/
public Set>> getMapEntries() {
return backing.entrySet();
}
/**
* Get all of the keys.
*
* @return The keys currently in use.
*/
public Set getMapKeys() {
return backing.keySet();
}
/**
* Get all of the keyed maps.
*
* @return The keyed maps.
*/
public Collection