diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/esodata')
| -rw-r--r-- | base/src/main/java/bjc/utils/esodata/DefaultList.java | 38 | ||||
| -rw-r--r-- | base/src/main/java/bjc/utils/esodata/DoubleSided.java | 6 | ||||
| -rw-r--r-- | base/src/main/java/bjc/utils/esodata/MapSet.java | 81 | ||||
| -rw-r--r-- | base/src/main/java/bjc/utils/esodata/Tape.java | 26 |
4 files changed, 144 insertions, 7 deletions
diff --git a/base/src/main/java/bjc/utils/esodata/DefaultList.java b/base/src/main/java/bjc/utils/esodata/DefaultList.java index 235a1a8..4d3d1dc 100644 --- a/base/src/main/java/bjc/utils/esodata/DefaultList.java +++ b/base/src/main/java/bjc/utils/esodata/DefaultList.java @@ -8,6 +8,8 @@ import java.util.List; * A list that has a default value that out-of-bounds accesses return. * * @author Ben Culkin + * @param <ValueType> + * The type of the values contained in the list. */ public class DefaultList<ValueType> extends AbstractList<ValueType> { /* @@ -20,33 +22,67 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> { * bounds, but what are you going to do? */ - private ValueType defVal; private List<ValueType> backing; + /** + * Create a new DefaultList. + */ public DefaultList() { this(new ArrayList<>(), null); } + /** + * Create a new DefaultList, with a set default value. + * + * @param defVal + * The default value for the list. + */ public DefaultList(ValueType defVal) { this(new ArrayList<>(), defVal); } + /** + * Create a new DefaultList, with a specific backing list. + * + * @param backer + * The backing list to use. + * + */ public DefaultList(List<ValueType> backer) { this(backer, null); } + /** + * Create a new DefaultList, with a set default value. + * + * @param backer + * The backing list to use. + * + * @param defVal + * The default value for the list. + */ public DefaultList(List<ValueType> backer, ValueType defVal) { this.defVal = defVal; this.backing = backer; } + /** + * Get the default value. + * + * @return The default value. + */ public ValueType getDefault() { return defVal; } + /** + * Set the default value. + * + * @param defVal The default value. + */ public void setDefault(ValueType defVal) { this.defVal = defVal; } diff --git a/base/src/main/java/bjc/utils/esodata/DoubleSided.java b/base/src/main/java/bjc/utils/esodata/DoubleSided.java index 83b7c77..2c57332 100644 --- a/base/src/main/java/bjc/utils/esodata/DoubleSided.java +++ b/base/src/main/java/bjc/utils/esodata/DoubleSided.java @@ -1,5 +1,11 @@ package bjc.utils.esodata; +/** + * Interface for a double-sided object. + * + * @author bjculkin + * + */ public interface DoubleSided { /** * Flips the object. 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; diff --git a/base/src/main/java/bjc/utils/esodata/Tape.java b/base/src/main/java/bjc/utils/esodata/Tape.java index 41b0ce7..0835f7e 100644 --- a/base/src/main/java/bjc/utils/esodata/Tape.java +++ b/base/src/main/java/bjc/utils/esodata/Tape.java @@ -8,7 +8,7 @@ package bjc.utils.esodata; * unbounded to the right, but in practice bounded by available memory. * * @param <T> - * The element type of the tape. + * The element type of the tape. * * @author bjculkin */ @@ -24,7 +24,7 @@ public interface Tape<T> { * Set the item the tape is currently on. * * @param itm - * The new value for the tape item. + * The new value for the tape item. */ void item(T itm); @@ -46,7 +46,7 @@ public interface Tape<T> { * Insert an element before the current item. * * @param itm - * The item to add. + * The item to add. */ void insertBefore(T itm); @@ -54,7 +54,7 @@ public interface Tape<T> { * Insert an element after the current item. * * @param itm - * The item to insert. + * The item to insert. */ void insertAfter(T itm); @@ -90,7 +90,7 @@ public interface Tape<T> { * that would exceed zero don't move the cursor at all. * * @param amt - * The amount to attempt to move the cursor left. + * The amount to attempt to move the cursor left. * * @return True if the cursor was moved left. */ @@ -107,14 +107,28 @@ public interface Tape<T> { * Move the cursor the specified amount right. * * @param amt - * The amount to move the cursor right by. + * The amount to move the cursor right by. * * @return Whether the cursor was moved right. */ boolean right(int amt); + /** + * Seek to an absolute position on the tape. + * + * @param pos + * The position to seek to. + * @return Whether or not the tape successfully seeked to that position. + */ boolean seekTo(int pos); + /** + * Check if this tape is at its end. + * + * Equivalent to checking if position() == size(). + * + * @return Whether or not the tape is at its end. + */ default boolean atEnd() { return position() == size(); } |
