summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/esodata
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-04-13 18:43:13 -0400
committerBen Culkin <scorpress@gmail.com>2020-04-13 18:43:13 -0400
commitf51f6da7319787348c38b875652b5c0e9f88c8aa (patch)
tree943888fc724da2d2dedd89abec99dcbfcc089fd0 /src/main/java/bjc/esodata
parent9052ed6da37af23ea82588d248f409e60a33c6cb (diff)
Cleanup pass
Pass to do some cleanups
Diffstat (limited to 'src/main/java/bjc/esodata')
-rw-r--r--src/main/java/bjc/esodata/AbbrevMap2.java28
-rw-r--r--src/main/java/bjc/esodata/DefaultList.java38
-rw-r--r--src/main/java/bjc/esodata/Directory.java32
-rw-r--r--src/main/java/bjc/esodata/DoubleSided.java5
-rw-r--r--src/main/java/bjc/esodata/DoubleTape.java37
-rw-r--r--src/main/java/bjc/esodata/MapSet.java57
-rw-r--r--src/main/java/bjc/esodata/Multimap.java45
-rw-r--r--src/main/java/bjc/esodata/PushdownMap.java30
-rw-r--r--src/main/java/bjc/esodata/QueueStack.java27
-rw-r--r--src/main/java/bjc/esodata/SimpleDirectory.java31
-rw-r--r--src/main/java/bjc/esodata/SimpleStack.java25
-rw-r--r--src/main/java/bjc/esodata/SingleTape.java73
-rw-r--r--src/main/java/bjc/esodata/SpaghettiStack.java41
-rw-r--r--src/main/java/bjc/esodata/Stack.java135
-rw-r--r--src/main/java/bjc/esodata/Tape.java39
-rw-r--r--src/main/java/bjc/esodata/ThresholdSet.java74
-rw-r--r--src/main/java/bjc/esodata/UnifiedDirectory.java38
17 files changed, 420 insertions, 335 deletions
diff --git a/src/main/java/bjc/esodata/AbbrevMap2.java b/src/main/java/bjc/esodata/AbbrevMap2.java
index db41471..f131aec 100644
--- a/src/main/java/bjc/esodata/AbbrevMap2.java
+++ b/src/main/java/bjc/esodata/AbbrevMap2.java
@@ -3,19 +3,22 @@ package bjc.esodata;
import java.util.*;
/**
- * A map that allows you to reference strings by unambiguous abbreviations to them.
- *
- * One example is that adding the string 'abc' would allow you to get it back with the following three keys
+ * A map that allows you to reference strings by unambiguous abbreviations to
+ * them.
+ *
+ * One example is that adding the string 'abc' would allow you to get it back
+ * with the following three keys
* <ul>
- * <li>a</li>
- * <li>ab</li>
- * <li>abc</li>
+ * <li>a</li>
+ * <li>ab</li>
+ * <li>abc</li>
* </ul>
*
* @author Ben Culkin
*/
public class AbbrevMap2 {
- // Stores a mapping from strings, to strings that they could be abbreviations for
+ // Stores a mapping from strings, to strings that they could be abbreviations
+ // for
private Multimap<String, String> backing;
/**
@@ -29,7 +32,7 @@ public class AbbrevMap2 {
* Add words to the map.
*
* @param words
- * The words to add to the map.
+ * The words to add to the map.
*/
public void add(String... words) {
for (String word : words) {
@@ -58,7 +61,7 @@ public class AbbrevMap2 {
* Remove words from the map.
*
* @param words
- * The words to remove from the map.
+ * The words to remove from the map.
*/
public void removeWords(String... words) {
for (String word : words) {
@@ -72,7 +75,7 @@ public class AbbrevMap2 {
* Get all of the strings that a string could be an abbreviation for.
*
* @param word
- * The word to attempt to deabbreviate.
+ * The word to attempt to deabbreviate.
*
* @return All of the possible deabbreviations for that word.
*/
@@ -84,9 +87,10 @@ public class AbbrevMap2 {
* Get the unambiguous thing the string is an abbreviation for.
*
* @param word
- * The word to attempt to deabbreviate.
+ * The word to attempt to deabbreviate.
*
- * @return The unambiguous deabbreviation of the string, or null if there isn't one.
+ * @return The unambiguous deabbreviation of the string, or null if there isn't
+ * one.
*/
public String deabbrev(String word) {
Set<String> st = backing.get(word);
diff --git a/src/main/java/bjc/esodata/DefaultList.java b/src/main/java/bjc/esodata/DefaultList.java
index e4b2806..c4535bd 100644
--- a/src/main/java/bjc/esodata/DefaultList.java
+++ b/src/main/java/bjc/esodata/DefaultList.java
@@ -9,17 +9,17 @@ import java.util.List;
*
* @author Ben Culkin
* @param <ValueType>
- * The type of the values contained in the list.
+ * The type of the values contained in the list.
*/
public class DefaultList<ValueType> extends AbstractList<ValueType> {
/*
* @NOTE 9/17/18
*
- * A possible feature to add would be the ability to set a 'default
- * index', so that the default value is 'whatever is at that list index'
+ * A possible feature to add would be the ability to set a 'default index', so
+ * that the default value is 'whatever is at that list index'
*
- * Of course, this would cause an exception if that index was out of
- * bounds, but what are you going to do?
+ * Of course, this would cause an exception if that index was out of bounds, but
+ * what are you going to do?
*/
private ValueType defVal;
@@ -35,9 +35,9 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
/**
* Create a new DefaultList, with a set default value.
- *
+ *
* @param defVal
- * The default value for the list.
+ * The default value for the list.
*/
public DefaultList(ValueType defVal) {
this(new ArrayList<>(), defVal);
@@ -45,10 +45,10 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
/**
* Create a new DefaultList, with a specific backing list.
- *
+ *
* @param backer
- * The backing list to use.
- *
+ * The backing list to use.
+ *
*/
public DefaultList(List<ValueType> backer) {
this(backer, null);
@@ -56,12 +56,12 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
/**
* Create a new DefaultList, with a set default value.
- *
+ *
* @param backer
- * The backing list to use.
- *
+ * The backing list to use.
+ *
* @param defVal
- * The default value for the list.
+ * The default value for the list.
*/
public DefaultList(List<ValueType> backer, ValueType defVal) {
this.defVal = defVal;
@@ -71,7 +71,7 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
/**
* Get the default value.
- *
+ *
* @return The default value.
*/
public ValueType getDefault() {
@@ -80,8 +80,9 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
/**
* Set the default value.
- *
- * @param defVal The default value.
+ *
+ * @param defVal
+ * The default value.
*/
public void setDefault(ValueType defVal) {
this.defVal = defVal;
@@ -89,7 +90,8 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
@Override
public ValueType get(int idx) {
- if (idx < 0 || idx >= backing.size()) return defVal;
+ if (idx < 0 || idx >= backing.size())
+ return defVal;
return backing.get(idx);
}
diff --git a/src/main/java/bjc/esodata/Directory.java b/src/main/java/bjc/esodata/Directory.java
index 4147e17..e083cd8 100644
--- a/src/main/java/bjc/esodata/Directory.java
+++ b/src/main/java/bjc/esodata/Directory.java
@@ -7,21 +7,21 @@ package bjc.esodata;
* be able to ensure that they can't write outside of it.
*
* @param <K>
- * The key type of the map.
+ * The key type of the map.
* @param <V>
- * The value type of the map.
+ * The value type of the map.
*/
public interface Directory<K, V> {
/**
* Retrieves a given sub-directory.
*
* @param key
- * The key to retrieve the sub-directory for.
+ * The key to retrieve the sub-directory for.
*
* @return The sub-directory under that name.
*
* @throws IllegalArgumentException
- * If the given sub-directory doesn't exist.
+ * If the given sub-directory doesn't exist.
*/
Directory<K, V> getSubdirectory(K key);
@@ -29,7 +29,7 @@ public interface Directory<K, V> {
* Check if a given sub-directory exists.
*
* @param key
- * The key to look for the sub-directory under.
+ * The key to look for the sub-directory under.
*
* @return Whether or not a sub-directory of that name exists.
*/
@@ -39,9 +39,9 @@ public interface Directory<K, V> {
* Insert a sub-directory into the dictionary.
*
* @param key
- * The name of the new sub-directory
+ * The name of the new sub-directory
* @param value
- * The sub-directory to insert
+ * The sub-directory to insert
*
* @return The old sub-directory attached to this key, or null if such a
* sub-directory didn't exist
@@ -54,13 +54,13 @@ public interface Directory<K, V> {
* Will fail if a sub-directory of that name already exists.
*
* @param key
- * The name of the new sub-directory.
+ * The name of the new sub-directory.
*
- * @return The new sub-directory, or null if one by that name already
- * exists.
+ * @return The new sub-directory, or null if one by that name already exists.
*/
default Directory<K, V> newSubdirectory(final K key) {
- if(hasSubdirectory(key)) return null;
+ if (hasSubdirectory(key))
+ return null;
final Directory<K, V> dir = new SimpleDirectory<>();
@@ -73,7 +73,7 @@ public interface Directory<K, V> {
* Check if the directory contains a data-item under the given key.
*
* @param key
- * The key to check for.
+ * The key to check for.
*
* @return Whether or not there is a data item for the given key.
*/
@@ -83,12 +83,12 @@ public interface Directory<K, V> {
* Retrieve a given data-item from the directory.
*
* @param key
- * The key to retrieve data for.
+ * The key to retrieve data for.
*
* @return The value for the given key.
*
* @throws IllegalArgumentException
- * If no value exists for the given key.
+ * If no value exists for the given key.
*/
V getKey(K key);
@@ -96,10 +96,10 @@ public interface Directory<K, V> {
* Insert a data-item into the directory.
*
* @param key
- * The key to insert into.
+ * The key to insert into.
*
* @param val
- * The value to insert.
+ * The value to insert.
*
* @return The old value of key, or null if such a value didn't exist.
*/
diff --git a/src/main/java/bjc/esodata/DoubleSided.java b/src/main/java/bjc/esodata/DoubleSided.java
index 6ecbdcf..8ac6684 100644
--- a/src/main/java/bjc/esodata/DoubleSided.java
+++ b/src/main/java/bjc/esodata/DoubleSided.java
@@ -2,7 +2,7 @@ package bjc.esodata;
/**
* Interface for a double-sided object.
- *
+ *
* @author bjculkin
*
*/
@@ -10,8 +10,7 @@ public interface DoubleSided {
/**
* Flips the object.
*
- * The active side becomes inactive, and the inactive side becomes
- * active.
+ * The active side becomes inactive, and the inactive side becomes active.
*/
void flip();
diff --git a/src/main/java/bjc/esodata/DoubleTape.java b/src/main/java/bjc/esodata/DoubleTape.java
index c36fcff..cc7cdb9 100644
--- a/src/main/java/bjc/esodata/DoubleTape.java
+++ b/src/main/java/bjc/esodata/DoubleTape.java
@@ -20,7 +20,7 @@ package bjc.esodata;
* Flip refers to the entire tape for 'obvious' reasons.
*
* @param <T>
- * The element type of the tape.
+ * The element type of the tape.
*
* @author bjculkin
*/
@@ -42,7 +42,8 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
* auto-extension policy.
*
* @param autoExtnd
- * Whether or not to auto-extend the tape to the right w/ nulls.
+ * Whether or not to auto-extend the tape to the right w/
+ * nulls.
*/
public DoubleTape(final boolean autoExtnd) {
front = new SingleTape<>(autoExtnd);
@@ -111,7 +112,7 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
public boolean left(final int amt) {
final boolean succ = front.left(amt);
- if(succ) {
+ if (succ) {
back.right(amt);
}
@@ -127,13 +128,14 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
public boolean right(final int amt) {
final boolean succ = front.right(amt);
- if(succ) {
+ if (succ) {
back.left(amt);
}
return succ;
}
+ @Override
public boolean seekTo(int tgtPos) {
return front.seekTo(tgtPos);
}
@@ -165,19 +167,26 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof DoubleTape<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof DoubleTape<?>))
+ return false;
final DoubleTape<?> other = (DoubleTape<?>) obj;
- if(back == null) {
- if(other.back != null) return false;
- } else if(!back.equals(other.back)) return false;
-
- if(front == null) {
- if(other.front != null) return false;
- } else if(!front.equals(other.front)) return false;
+ if (back == null) {
+ if (other.back != null)
+ return false;
+ } else if (!back.equals(other.back))
+ return false;
+
+ if (front == null) {
+ if (other.front != null)
+ return false;
+ } else if (!front.equals(other.front))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/esodata/MapSet.java b/src/main/java/bjc/esodata/MapSet.java
index cbb5d34..a80c482 100644
--- a/src/main/java/bjc/esodata/MapSet.java
+++ b/src/main/java/bjc/esodata/MapSet.java
@@ -8,13 +8,13 @@ import java.util.Set;
/**
* A string-keyed set of maps.
- *
+ *
* @author bjculkin
*
* @param <KeyType>
- * The key type of the maps.
+ * The key type of the maps.
* @param <ValueType>
- * The value type of the maps.
+ * The value type of the maps.
*/
public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType> {
private Map<String, Map<KeyType, ValueType>> backing;
@@ -30,9 +30,9 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Create a new set of maps, with the specified set of maps.
- *
+ *
* @param back
- * The set of maps to use.
+ * The set of maps to use.
*/
public MapSet(Map<String, Map<KeyType, ValueType>> back) {
backing = back;
@@ -40,11 +40,11 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Add a keyed map.
- *
+ *
* @param key
- * The key for the map.
+ * The key for the map.
* @param map
- * The map itself.
+ * The map itself.
*/
public void addMap(String key, Map<KeyType, ValueType> map) {
backing.put(key, map);
@@ -61,9 +61,9 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Check if there is a map attached to the specified key.
- *
+ *
* @param key
- * The key to look for.
+ * The key to look for.
* @return Whether or not there is anything attached to the key.
*/
public boolean containsMap(String key) {
@@ -72,9 +72,9 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Get the map attached to a specified key.
- *
+ *
* @param key
- * The key to look for.
+ * The key to look for.
* @return The map attached to the key.
*/
public Map<KeyType, ValueType> getMap(String key) {
@@ -83,7 +83,7 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Get all of the backing entries.
- *
+ *
* @return The backing entries.
*/
public Set<Map.Entry<String, Map<KeyType, ValueType>>> getMapEntries() {
@@ -92,7 +92,7 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Get all of the keys.
- *
+ *
* @return The keys currently in use.
*/
public Set<String> getMapKeys() {
@@ -101,7 +101,7 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Get all of the keyed maps.
- *
+ *
* @return The keyed maps.
*/
public Collection<Map<KeyType, ValueType>> getMapValues() {
@@ -110,13 +110,14 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Set the current map.
- *
+ *
* @param key
- * The key to use as the current map.
+ * 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;
+ if (!backing.containsKey(key))
+ return false;
currentMap = backing.get(key);
@@ -124,11 +125,11 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
}
/**
- * Sets the current map, or creates a new one if there isn't one
- * attached to that key.
- *
+ * 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.
+ * The key to use as the current map.
*/
public void setCreateMap(String key) {
if (!backing.containsKey(key)) {
@@ -144,11 +145,11 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
/**
* Set the current map, or bind a map to it.
- *
+ *
* @param key
- * The key to set or bind.
+ * The key to set or bind.
* @param map
- * The map to bind to the key if it isn't present.
+ * 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)) {
@@ -164,14 +165,16 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
@Override
public Set<Map.Entry<KeyType, ValueType>> entrySet() {
- if (currentMap == null) throw new NullPointerException("Current map is not set");
+ if (currentMap == null)
+ throw new NullPointerException("Current map is not set");
return currentMap.entrySet();
}
@Override
public ValueType put(KeyType key, ValueType value) {
- if (currentMap == null) throw new NullPointerException("Current map is not set");
+ if (currentMap == null)
+ throw new NullPointerException("Current map is not set");
return currentMap.put(key, value);
}
diff --git a/src/main/java/bjc/esodata/Multimap.java b/src/main/java/bjc/esodata/Multimap.java
index 5706db3..f0876db 100644
--- a/src/main/java/bjc/esodata/Multimap.java
+++ b/src/main/java/bjc/esodata/Multimap.java
@@ -5,9 +5,10 @@ import java.util.*;
/**
* A map that has support for multiple values for a given key.
*
- * Whenever you give another value for a key, that is then returned for that key. About the only
- * somewhat complex thing, is that, if you add the same key-value pair multiple times, it will only
- * show up once. However, you will have to remove that pair as many times as you added it.
+ * Whenever you give another value for a key, that is then returned for that
+ * key. About the only somewhat complex thing, is that, if you add the same
+ * key-value pair multiple times, it will only show up once. However, you will
+ * have to remove that pair as many times as you added it.
*
* @author Ben Culkin
*/
@@ -25,14 +26,14 @@ public class Multimap<KeyType, ValueType> {
* Add a key-value mapping to the map.
*
* @param key
- * The key to store the value under.
+ * The key to store the value under.
*
* @param value
- * The value to store.
+ * The value to store.
*/
public void add(KeyType key, ValueType value) {
- ThresholdSet<ValueType> container = backing.computeIfAbsent(key,
- (k) -> new ThresholdSet<>());
+ ThresholdSet<ValueType> container
+ = backing.computeIfAbsent(key, k -> new ThresholdSet<>());
container.add(value);
}
@@ -41,14 +42,15 @@ public class Multimap<KeyType, ValueType> {
* Delete a particular key-value mapping from the map.
*
* @param key
- * The key of the mapping to remove.
+ * The key of the mapping to remove.
*
* @param value
- * The value of the mapping to remove.
+ * The value of the mapping to remove.
*/
public void remove(KeyType key, ValueType value) {
// We have no values for that key; bail.
- if (!backing.containsKey(key)) return;
+ if (!backing.containsKey(key))
+ return;
backing.get(key).remove(value);
}
@@ -57,7 +59,7 @@ public class Multimap<KeyType, ValueType> {
* Delete all of the values associated with a particular key.
*
* @param key
- * The key to remove values for.
+ * The key to remove values for.
*/
public void remove(KeyType key) {
backing.remove(key);
@@ -67,12 +69,13 @@ public class Multimap<KeyType, ValueType> {
* Get a set containing all of the values that are recorded for that key.
*
* @param key
- * The key to look up values for.
+ * The key to look up values for.
*
* @return A set containing all of the values that have been mapped to that key.
*/
public Set<ValueType> get(KeyType key) {
- if (!backing.containsKey(key)) return new HashSet<>();
+ if (!backing.containsKey(key))
+ return new HashSet<>();
return backing.get(key).values();
}
@@ -81,8 +84,8 @@ public class Multimap<KeyType, ValueType> {
* Check if there is at least one value mapped to the given key.
*
* @param key
- * The key to check for mappings for.
- *
+ * The key to check for mappings for.
+ *
* @return Whether or not there is at least one value mapped to the key.
*/
public boolean contains(KeyType key) {
@@ -93,15 +96,17 @@ public class Multimap<KeyType, ValueType> {
* Check if there is at least one instance of a particular key-value mapping.
*
* @param key
- * The key to check for mappings for.
+ * The key to check for mappings for.
*
* @param value
- * The value to check for mappings for.
- *
- * @return Whether or not there is at least one instance of the given key-value mapping.
+ * The value to check for mappings for.
+ *
+ * @return Whether or not there is at least one instance of the given key-value
+ * mapping.
*/
public boolean contains(KeyType key, ValueType value) {
- if (!backing.containsKey(key)) return false;
+ if (!backing.containsKey(key))
+ return false;
return backing.get(key).contains(value) > 0;
}
diff --git a/src/main/java/bjc/esodata/PushdownMap.java b/src/main/java/bjc/esodata/PushdownMap.java
index 5db5f05..54ae939 100644
--- a/src/main/java/bjc/esodata/PushdownMap.java
+++ b/src/main/java/bjc/esodata/PushdownMap.java
@@ -17,10 +17,10 @@ import bjc.funcdata.IMap;
* @author EVE
*
* @param <KeyType>
- * The key of the map.
+ * The key of the map.
*
* @param <ValueType>
- * The values in the map.
+ * The values in the map.
*/
public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType> {
/* Our backing storage. */
@@ -84,16 +84,15 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType>
@Override
public <V2> IMap<KeyType, V2> transform(final Function<ValueType, V2> transformer) {
/*
- * @NOTE Can and should we support this? More to the point,
- * maybe this should be a map sub-type that does what it needs
- * to?
+ * @NOTE Can and should we support this? More to the point, maybe this should be
+ * a map sub-type that does what it needs to?
*/
throw new UnsupportedOperationException("Cannot transform pushdown maps.");
}
@Override
public ValueType put(final KeyType key, final ValueType val) {
- if(backing.containsKey(key)) {
+ if (backing.containsKey(key)) {
final Stack<ValueType> stk = backing.get(key);
final ValueType vl = stk.top();
@@ -114,7 +113,7 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType>
public ValueType remove(final KeyType key) {
final Stack<ValueType> stk = backing.get(key);
- if(stk.size() > 1) {
+ if (stk.size() > 1) {
return stk.pop();
}
@@ -138,15 +137,20 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType>
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof PushdownMap<?, ?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof PushdownMap<?, ?>))
+ return false;
final PushdownMap<?, ?> other = (PushdownMap<?, ?>) obj;
- if(backing == null) {
- if(other.backing != null) return false;
- } else if(!backing.equals(other.backing)) return false;
+ if (backing == null) {
+ if (other.backing != null)
+ return false;
+ } else if (!backing.equals(other.backing))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/esodata/QueueStack.java b/src/main/java/bjc/esodata/QueueStack.java
index 55c6fc4..c40721a 100644
--- a/src/main/java/bjc/esodata/QueueStack.java
+++ b/src/main/java/bjc/esodata/QueueStack.java
@@ -5,11 +5,11 @@ import java.util.LinkedList;
/**
* A FIFO implementation of a stack.
- *
+ *
* Basically, a stack that actually acts like a queue.
*
* @param <T>
- * The datatype stored in the stack.
+ * The datatype stored in the stack.
*
* @author Ben Culkin
*/
@@ -29,14 +29,16 @@ public class QueueStack<T> extends Stack<T> {
@Override
public T pop() {
- if(backing.isEmpty()) throw new StackUnderflow();
+ if (backing.isEmpty())
+ throw new StackUnderflow();
return backing.remove();
}
@Override
public T top() {
- if(backing.isEmpty()) throw new StackUnderflow();
+ if (backing.isEmpty())
+ throw new StackUnderflow();
return backing.peek();
}
@@ -74,15 +76,20 @@ public class QueueStack<T> extends Stack<T> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof QueueStack<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof QueueStack<?>))
+ return false;
final QueueStack<?> other = (QueueStack<?>) obj;
- if(backing == null) {
- if(other.backing != null) return false;
- } else if(!backing.equals(other.backing)) return false;
+ if (backing == null) {
+ if (other.backing != null)
+ return false;
+ } else if (!backing.equals(other.backing))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/esodata/SimpleDirectory.java b/src/main/java/bjc/esodata/SimpleDirectory.java
index 8ac19cf..672d92f 100644
--- a/src/main/java/bjc/esodata/SimpleDirectory.java
+++ b/src/main/java/bjc/esodata/SimpleDirectory.java
@@ -11,10 +11,10 @@ import bjc.funcdata.IMap;
* @author EVE
*
* @param <K>
- * The key type of the directory.
+ * The key type of the directory.
*
* @param <V>
- * The value type of the directory.
+ * The value type of the directory.
*/
public class SimpleDirectory<K, V> implements Directory<K, V> {
/* Our sub-directories. */
@@ -71,19 +71,26 @@ public class SimpleDirectory<K, V> implements Directory<K, V> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof SimpleDirectory<?, ?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof SimpleDirectory<?, ?>))
+ return false;
final SimpleDirectory<?, ?> other = (SimpleDirectory<?, ?>) obj;
- if(children == null) {
- if(other.children != null) return false;
- } else if(!children.equals(other.children)) return false;
-
- if(data == null) {
- if(other.data != null) return false;
- } else if(!data.equals(other.data)) return false;
+ if (children == null) {
+ if (other.children != null)
+ return false;
+ } else if (!children.equals(other.children))
+ return false;
+
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/esodata/SimpleStack.java b/src/main/java/bjc/esodata/SimpleStack.java
index dc6566c..b50521e 100644
--- a/src/main/java/bjc/esodata/SimpleStack.java
+++ b/src/main/java/bjc/esodata/SimpleStack.java
@@ -7,7 +7,7 @@ import java.util.LinkedList;
* Simple implementation of a stack.
*
* @param <T>
- * The datatype stored in the stack.
+ * The datatype stored in the stack.
*
* @author Ben Culkin
*/
@@ -27,14 +27,16 @@ public class SimpleStack<T> extends Stack<T> {
@Override
public T pop() {
- if(backing.isEmpty()) throw new StackUnderflow();
+ if (backing.isEmpty())
+ throw new StackUnderflow();
return backing.pop();
}
@Override
public T top() {
- if(backing.isEmpty()) throw new StackUnderflow();
+ if (backing.isEmpty())
+ throw new StackUnderflow();
return backing.peek();
}
@@ -67,15 +69,20 @@ public class SimpleStack<T> extends Stack<T> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof SimpleStack<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof SimpleStack<?>))
+ return false;
final SimpleStack<?> other = (SimpleStack<?>) obj;
- if(backing == null) {
- if(other.backing != null) return false;
- } else if(!backing.equals(other.backing)) return false;
+ if (backing == null) {
+ if (other.backing != null)
+ return false;
+ } else if (!backing.equals(other.backing))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/esodata/SingleTape.java b/src/main/java/bjc/esodata/SingleTape.java
index c2957a6..f6f87be 100644
--- a/src/main/java/bjc/esodata/SingleTape.java
+++ b/src/main/java/bjc/esodata/SingleTape.java
@@ -15,7 +15,7 @@ import java.util.ArrayList;
* policy.
*
* @param <T>
- * The element type of the tape.
+ * The element type of the tape.
*
* @author bjculkin
*/
@@ -28,11 +28,10 @@ public class SingleTape<T> implements Tape<T> {
protected boolean autoExtend;
/**
- * Create a new tape with the specified contents that doesn't
- * autoextend.
- *
+ * Create a new tape with the specified contents that doesn't autoextend.
+ *
* @param vals
- * The values to put on the tape.
+ * The values to put on the tape.
*/
@SafeVarargs
public SingleTape(T... vals) {
@@ -40,7 +39,7 @@ public class SingleTape<T> implements Tape<T> {
backing = new ArrayList<>(vals.length);
- for(T val : vals) {
+ for (T val : vals) {
backing.add(val);
}
}
@@ -52,24 +51,24 @@ public class SingleTape<T> implements Tape<T> {
/**
* Create a new tape with values taken from an iterable.
- *
+ *
* @param itr
- * The iterable to get values from.
+ * The iterable to get values from.
*/
public SingleTape(Iterable<T> itr) {
this(false);
- for(T itm : itr) {
+ for (T itm : itr) {
backing.add(itm);
}
}
/**
- * Create a new empty tape that follows the specified auto-extension
- * policy.
+ * Create a new empty tape that follows the specified auto-extension policy.
*
* @param autoExtnd
- * Whether or not to auto-extend the tape to the right w/ nulls.
+ * Whether or not to auto-extend the tape to the right w/
+ * nulls.
*/
public SingleTape(final boolean autoExtnd) {
autoExtend = autoExtnd;
@@ -79,7 +78,8 @@ public class SingleTape<T> implements Tape<T> {
@Override
public T item() {
- if (pos < 0 || pos >= backing.size()) return null;
+ if (pos < 0 || pos >= backing.size())
+ return null;
return backing.get(pos);
}
@@ -106,7 +106,7 @@ public class SingleTape<T> implements Tape<T> {
@Override
public void insertAfter(final T itm) {
- if(pos == backing.size() - 1) {
+ if (pos == backing.size() - 1) {
backing.add(itm);
} else {
backing.add(pos + 1, itm);
@@ -116,7 +116,7 @@ public class SingleTape<T> implements Tape<T> {
@Override
public T remove() {
final T res = backing.remove(pos);
- if(pos != 0) {
+ if (pos != 0) {
pos -= 1;
}
return res;
@@ -139,7 +139,8 @@ public class SingleTape<T> implements Tape<T> {
@Override
public boolean left(final int amt) {
- if(pos - amt < 0) return false;
+ if (pos - amt < 0)
+ return false;
pos -= amt;
return true;
@@ -152,25 +153,27 @@ public class SingleTape<T> implements Tape<T> {
@Override
public boolean right(final int amt) {
- if(pos + amt > backing.size()) {
- if(autoExtend) {
- while(pos + amt >= backing.size() - 1) {
+ if (pos + amt > backing.size()) {
+ if (autoExtend) {
+ while (pos + amt >= backing.size() - 1) {
backing.add(null);
}
- } else return false;
+ } else
+ return false;
}
pos += amt;
return true;
}
+ @Override
public boolean seekTo(int tgtPos) {
- if(tgtPos < 0)
+ if (tgtPos < 0)
return false;
- if(tgtPos >= backing.size() - 1)
- if(autoExtend)
- while(tgtPos >= backing.size() - 1)
+ if (tgtPos >= backing.size() - 1)
+ if (autoExtend)
+ while (tgtPos >= backing.size() - 1)
backing.add(null);
else
return false;
@@ -184,7 +187,7 @@ public class SingleTape<T> implements Tape<T> {
public void append(T itm) {
backing.add(itm);
}
-
+
@Override
public int hashCode() {
final int prime = 31;
@@ -197,21 +200,27 @@ public class SingleTape<T> implements Tape<T> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof SingleTape<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof SingleTape<?>))
+ return false;
final SingleTape<?> other = (SingleTape<?>) obj;
- if(backing == null) {
- if(other.backing != null) return false;
- } else if(!backing.equals(other.backing)) return false;
+ if (backing == null) {
+ if (other.backing != null)
+ return false;
+ } else if (!backing.equals(other.backing))
+ return false;
return true;
}
@Override
public String toString() {
- return String.format("SingleTape [backing=%s, pos=%s, autoExtend=%s]", backing, pos, autoExtend);
+ return String.format("SingleTape [backing=%s, pos=%s, autoExtend=%s]", backing,
+ pos, autoExtend);
}
}
diff --git a/src/main/java/bjc/esodata/SpaghettiStack.java b/src/main/java/bjc/esodata/SpaghettiStack.java
index 1b7af25..fc3e154 100644
--- a/src/main/java/bjc/esodata/SpaghettiStack.java
+++ b/src/main/java/bjc/esodata/SpaghettiStack.java
@@ -8,7 +8,7 @@ import java.util.stream.Stream;
* parent stack.
*
* @param <T>
- * The datatype stored in the stack.
+ * The datatype stored in the stack.
*
* @author Ben Culkin
*/
@@ -22,7 +22,7 @@ class SpaghettiStack<T> extends Stack<T> {
* Create a new empty spaghetti stack, off of the specified parent.
*
* @param par
- * The parent stack
+ * The parent stack
*/
public SpaghettiStack(final Stack<T> par) {
backing = new SimpleStack<>();
@@ -37,14 +37,16 @@ class SpaghettiStack<T> extends Stack<T> {
@Override
public T pop() {
- if(backing.isEmpty()) return parent.pop();
+ if (backing.isEmpty())
+ return parent.pop();
return backing.pop();
}
@Override
public T top() {
- if(backing.isEmpty()) return parent.top();
+ if (backing.isEmpty())
+ return parent.top();
return backing.top();
}
@@ -62,7 +64,9 @@ class SpaghettiStack<T> extends Stack<T> {
@SuppressWarnings("unchecked")
@Override
public T[] toArray() {
- return (T[]) Stream.concat(Arrays.stream(parent.toArray()), Arrays.stream(backing.toArray())).toArray();
+ return (T[]) Stream
+ .concat(Arrays.stream(parent.toArray()), Arrays.stream(backing.toArray()))
+ .toArray();
}
@Override
@@ -78,19 +82,26 @@ class SpaghettiStack<T> extends Stack<T> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof SpaghettiStack<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof SpaghettiStack<?>))
+ return false;
final SpaghettiStack<?> other = (SpaghettiStack<?>) obj;
- if(backing == null) {
- if(other.backing != null) return false;
- } else if(!backing.equals(other.backing)) return false;
-
- if(parent == null) {
- if(other.parent != null) return false;
- } else if(!parent.equals(other.parent)) return false;
+ if (backing == null) {
+ if (other.backing != null)
+ return false;
+ } else if (!backing.equals(other.backing))
+ return false;
+
+ if (parent == null) {
+ if (other.parent != null)
+ return false;
+ } else if (!parent.equals(other.parent))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/esodata/Stack.java b/src/main/java/bjc/esodata/Stack.java
index 31c92f1..f2e00e3 100644
--- a/src/main/java/bjc/esodata/Stack.java
+++ b/src/main/java/bjc/esodata/Stack.java
@@ -16,20 +16,20 @@ import java.util.function.*;
* <h2>Stack underflow</h2>
* <p>
* NOTE: In general, using any operation that attempts to remove more data from
- * the stack than exists will cause a {@link StackUnderflow} to be
- * thrown. Check the size of the stack if you want to avoid this.
+ * the stack than exists will cause a {@link StackUnderflow} to be thrown. Check
+ * the size of the stack if you want to avoid this.
* <p>
* </p>
*
* @param <T>
- * The datatype stored in the stack.
+ * The datatype stored in the stack.
*
* @author Ben Culkin
*/
public abstract class Stack<T> {
/**
- * The exception thrown when attempting to access an element from the
- * stack that isn't there.
+ * The exception thrown when attempting to access an element from the stack that
+ * isn't there.
*
* @author EVE
*/
@@ -42,7 +42,7 @@ public abstract class Stack<T> {
* Push an element onto the stack.
*
* @param elm
- * The element to insert.
+ * The element to insert.
*/
public abstract void push(T elm);
@@ -54,8 +54,7 @@ public abstract class Stack<T> {
public abstract T pop();
/**
- * Retrieve the top element of this stack without removing it from the
- * stack.
+ * Retrieve the top element of this stack without removing it from the stack.
*
* @return The top element of this stack.
*/
@@ -94,7 +93,7 @@ public abstract class Stack<T> {
* Push multiple elements onto the stack.
*
* @param elms
- * The elements to insert.
+ * The elements to insert.
*/
public void pushAll(T... elms) {
for (T elm : elms) {
@@ -106,7 +105,7 @@ public abstract class Stack<T> {
* Push multiple elements onto the stack.
*
* @param elms
- * The elements to insert.
+ * The elements to insert.
*/
public void pushAll(List<T> elms) {
for (T elm : elms) {
@@ -118,7 +117,7 @@ public abstract class Stack<T> {
* Pop n items off of the stack and return them.
*
* @param n
- * The number of items to pop off of the stack.
+ * The number of items to pop off of the stack.
*
* @return A list of the popped items, in the order they were popped.
*/
@@ -136,7 +135,7 @@ public abstract class Stack<T> {
* Pop n items off of the stack and return them.
*
* @param n
- * The number of items to pop off of the stack.
+ * The number of items to pop off of the stack.
*
* @return A list of the popped items, in the reverse order they were popped.
*/
@@ -158,10 +157,10 @@ public abstract class Stack<T> {
* Drop n items from the stack.
*
* @param n
- * The number of items to drop.
+ * The number of items to drop.
*/
public void drop(final int n) {
- for(int i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
pop();
}
}
@@ -175,7 +174,7 @@ public abstract class Stack<T> {
* Delete n items below the current one.
*
* @param n
- * The number of items below the top to delete.
+ * The number of items below the top to delete.
*/
public void nip(final int n) {
final T elm = pop();
@@ -194,15 +193,15 @@ public abstract class Stack<T> {
* Replicate the top n items of the stack m times.
*
* @param n
- * The number of items to duplicate.
+ * The number of items to duplicate.
*
* @param m
- * The number of times to duplicate items.
+ * The number of times to duplicate items.
*/
public void multidup(final int n, final int m) {
List<T> lst = multipoprev(n);
- for(int i = 0; i <= m; i++) {
+ for (int i = 0; i <= m; i++) {
pushAll(lst);
}
}
@@ -211,7 +210,7 @@ public abstract class Stack<T> {
* Duplicate the top n items of the stack.
*
* @param n
- * The number of items to duplicate.
+ * The number of items to duplicate.
*/
public void dup(final int n) {
multidup(n, 1);
@@ -226,23 +225,23 @@ public abstract class Stack<T> {
* Replicate the n elements below the top one m times.
*
* @param n
- * The number of items to duplicate.
+ * The number of items to duplicate.
*
* @param m
- * The number of times to duplicate items.
+ * The number of times to duplicate items.
*/
public void multiover(final int n, final int m) {
T elm = pop();
List<T> lst = multipoprev(n);
- for(final T nelm : lst) {
+ for (final T nelm : lst) {
push(nelm);
}
push(elm);
- for(int i = 0; i < m; i++) {
+ for (int i = 0; i < m; i++) {
pushAll(lst);
}
}
@@ -251,7 +250,7 @@ public abstract class Stack<T> {
* Duplicate the n elements below the top one.
*
* @param n
- * The number of items to duplicate.
+ * The number of items to duplicate.
*/
public void over(final int n) {
multiover(n, 1);
@@ -278,12 +277,12 @@ public abstract class Stack<T> {
* Rotate the n items m deep on the stack i positions.
*
* @param n
- * The number of items to rotate.
+ * The number of items to rotate.
* @param m
- * The number of positions the item is down in the stack.
+ * The number of positions the item is down in the stack.
* @param i
- * The number of steps to rotate. Pass a negative number to rotate things in the opposite
- * direction.
+ * The number of steps to rotate. Pass a negative number to rotate
+ * things in the opposite direction.
*/
public void deepmultirot(int n, int m, int i) {
List<T> kep = multipoprev(m);
@@ -300,10 +299,10 @@ public abstract class Stack<T> {
* Rotate the n items on top of the stack i positions.
*
* @param n
- * The number of items to rotate.
+ * The number of items to rotate.
* @param i
- * The number of steps to rotate. Pass a negative number to rotate things in the opposite
- * direction.
+ * The number of steps to rotate. Pass a negative number to rotate
+ * things in the opposite direction.
*/
public void multirot(int n, int i) {
deepmultirot(n, 0, i);
@@ -329,8 +328,8 @@ public abstract class Stack<T> {
deepmultirot(2, 1, 1);
}
- /**
- * Rotate the top three items on the stack
+ /**
+ * Rotate the top three items on the stack
*/
public void rot() {
final T z = pop();
@@ -361,10 +360,10 @@ public abstract class Stack<T> {
* Hides the top n elements on the stack from an action.
*
* @param n
- * The number of elements to hide.
+ * The number of elements to hide.
*
* @param action
- * The action to hide the elements from
+ * The action to hide the elements from
*/
public void dip(final int n, final Consumer<Stack<T>> action) {
List<T> elms = multipoprev(n);
@@ -378,21 +377,20 @@ public abstract class Stack<T> {
* Hide the top element of the stack from an action.
*
* @param action
- * The action to hide the top from
+ * The action to hide the top from
*/
public void dip(final Consumer<Stack<T>> action) {
dip(1, action);
}
/**
- * Copy the top n elements on the stack, replacing them once an action
- * is done.
+ * Copy the top n elements on the stack, replacing them once an action is done.
*
* @param n
- * The number of elements to copy.
+ * The number of elements to copy.
*
* @param action
- * The action to execute.
+ * The action to execute.
*/
public void keep(final int n, final Consumer<Stack<T>> action) {
dup(n);
@@ -401,11 +399,10 @@ public abstract class Stack<T> {
}
/**
- * Copy the first element on the stack, replacing them once an action
- * is done.
+ * Copy the first element on the stack, replacing them once an action is done.
*
* @param action
- * The action to execute.
+ * The action to execute.
*/
public void keep(final Consumer<Stack<T>> action) {
keep(1, action);
@@ -415,15 +412,15 @@ public abstract class Stack<T> {
* Apply all the actions in a list to the top n elements of the stack.
*
* @param n
- * The number of elements to give to cons.
+ * The number of elements to give to cons.
*
* @param actions
- * The actions to execute.
+ * The actions to execute.
*/
public void multicleave(final int n, final List<Consumer<Stack<T>>> actions) {
List<T> elms = multipoprev(n);
- for(final Consumer<Stack<T>> action : actions) {
+ for (final Consumer<Stack<T>> action : actions) {
pushAll(elms);
action.accept(this);
@@ -434,15 +431,15 @@ public abstract class Stack<T> {
* Apply all the actions in a list to the top n elements of the stack.
*
* @param n
- * The number of elements to give to cons.
+ * The number of elements to give to cons.
*
* @param actions
- * The actions to execute.
+ * The actions to execute.
*/
public void multicleave(final int n, final Consumer<Stack<T>>... actions) {
List<T> elms = multipoprev(n);
- for(final Consumer<Stack<T>> action : actions) {
+ for (final Consumer<Stack<T>> action : actions) {
pushAll(elms);
action.accept(this);
@@ -453,7 +450,7 @@ public abstract class Stack<T> {
* Apply all the actions in a list to the top element of the stack.
*
* @param actions
- * The actions to execute.
+ * The actions to execute.
*/
public void cleave(final List<Consumer<Stack<T>>> actions) {
multicleave(1, actions);
@@ -463,7 +460,7 @@ public abstract class Stack<T> {
* Apply all the actions in a list to the top element of the stack.
*
* @param actions
- * The actions to execute.
+ * The actions to execute.
*/
public void cleave(final Consumer<Stack<T>>... actions) {
multicleave(1, actions);
@@ -473,10 +470,10 @@ public abstract class Stack<T> {
* Apply every action in a list of actions to n arguments.
*
* @param n
- * The number of parameters each action takes.
+ * The number of parameters each action takes.
*
* @param actions
- * The actions to execute.
+ * The actions to execute.
*/
public void multispread(final int n, final List<Consumer<Stack<T>>> actions) {
List<List<T>> nelms = new LinkedList<>();
@@ -488,7 +485,7 @@ public abstract class Stack<T> {
}
Iterator<Consumer<Stack<T>>> itr = actions.iterator();
- for(final List<T> elms : nelms) {
+ for (final List<T> elms : nelms) {
pushAll(elms);
itr.next().accept(this);
@@ -499,10 +496,10 @@ public abstract class Stack<T> {
* Apply every action in a list of actions to n arguments.
*
* @param n
- * The number of parameters each action takes.
+ * The number of parameters each action takes.
*
* @param actions
- * The actions to execute.
+ * The actions to execute.
*/
public void multispread(final int n, final Consumer<Stack<T>>... actions) {
List<List<T>> nelms = new LinkedList<>();
@@ -514,7 +511,7 @@ public abstract class Stack<T> {
}
int i = 0;
- for(final List<T> elms : nelms) {
+ for (final List<T> elms : nelms) {
pushAll(elms);
actions[i++].accept(this);
@@ -522,22 +519,22 @@ public abstract class Stack<T> {
}
/**
- * Apply the actions in a list of actions to corresponding elements from
- * the stack.
+ * Apply the actions in a list of actions to corresponding elements from the
+ * stack.
*
* @param conses
- * The actions to execute.
+ * The actions to execute.
*/
public void spread(final List<Consumer<Stack<T>>> conses) {
multispread(1, conses);
}
/**
- * Apply the actions in a list of actions to corresponding elements from
- * the stack.
+ * Apply the actions in a list of actions to corresponding elements from the
+ * stack.
*
* @param conses
- * The actions to execute.
+ * The actions to execute.
*/
public void spread(final Consumer<Stack<T>>... conses) {
multispread(1, conses);
@@ -547,18 +544,18 @@ public abstract class Stack<T> {
* Apply an action to the first m groups of n arguments.
*
* @param n
- * The number of arguments cons takes.
+ * The number of arguments cons takes.
*
* @param m
- * The number of time to call cons.
+ * The number of time to call cons.
*
* @param action
- * The action to execute.
+ * The action to execute.
*/
public void multiapply(final int n, final int m, final Consumer<Stack<T>> action) {
final List<Consumer<Stack<T>>> actions = new ArrayList<>(m);
- for(int i = 0; i < m; i++) {
+ for (int i = 0; i < m; i++) {
actions.add(action);
}
@@ -569,10 +566,10 @@ public abstract class Stack<T> {
* Apply an action n times to the corresponding elements in the stack.
*
* @param n
- * The number of times to execute cons.
+ * The number of times to execute cons.
*
* @param action
- * The action to execute.
+ * The action to execute.
*/
public void apply(final int n, final Consumer<Stack<T>> action) {
multiapply(1, n, action);
diff --git a/src/main/java/bjc/esodata/Tape.java b/src/main/java/bjc/esodata/Tape.java
index 7d5fd9a..134ba62 100644
--- a/src/main/java/bjc/esodata/Tape.java
+++ b/src/main/java/bjc/esodata/Tape.java
@@ -8,7 +8,7 @@ package bjc.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);
@@ -86,11 +86,11 @@ public interface Tape<T> {
/**
* Move the cursor the specified amount left.
*
- * The cursor can't go past zero. Attempts to move the cursor by amounts
- * that would exceed zero don't move the cursor at all.
+ * The cursor can't go past zero. Attempts to move the cursor by amounts 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,7 +107,7 @@ 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.
*/
@@ -115,37 +115,40 @@ public interface Tape<T> {
/**
* Seek to an absolute position on the tape.
- *
+ *
* @param pos
- * The position to seek to.
+ * 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();
}
-
+
/**
* Append an item to the tape.
+ *
+ * By default, uses a fairly non-performant implementation. Should be overidden
+ * in subclasses to be more performant.
*
- * By default, uses a fairly non-performant implementation. Should be overidden in subclasses to be more performant.
- * @param itm The item to append.
+ * @param itm
+ * The item to append.
*/
default void append(T itm) {
int pos = position();
-
+
last();
-
+
insertAfter(itm);
-
+
seekTo(pos);
}
}
diff --git a/src/main/java/bjc/esodata/ThresholdSet.java b/src/main/java/bjc/esodata/ThresholdSet.java
index 6076a2a..50d95d0 100644
--- a/src/main/java/bjc/esodata/ThresholdSet.java
+++ b/src/main/java/bjc/esodata/ThresholdSet.java
@@ -7,16 +7,18 @@ import java.util.*;
*
* More specifically, this is a set/map combo type.
*
- * Initially, when you add an item, it will go into the set. Attempting to add a duplicate item to
- * that set will cause the entry to be removed from the set, and added to the map, which will count
- * the number of times that particular item has been added to the set. If you remove enough copies
- * of that item to put it back down to 1 copy, that copy will be removed from the map, and readded
- * to the set.
+ * Initially, when you add an item, it will go into the set. Attempting to add a
+ * duplicate item to that set will cause the entry to be removed from the set,
+ * and added to the map, which will count the number of times that particular
+ * item has been added to the set. If you remove enough copies of that item to
+ * put it back down to 1 copy, that copy will be removed from the map, and
+ * readded to the set.
*
- * The iterator that this type gives by default is an iterator over all of the values in the set,
- * not including any of those in the map.
+ * The iterator that this type gives by default is an iterator over all of the
+ * values in the set, not including any of those in the map.
*
- * @param <KeyType> The value being counted.
+ * @param <KeyType>
+ * The value being counted.
*
* @author Ben Culkin
*/
@@ -24,30 +26,33 @@ public class ThresholdSet<KeyType> {
// View of this class as a java.util.Set
private class SetView extends AbstractSet<KeyType> {
/*
- * This is technically not a valid implementation of add, because it does not guarantee that
- * the set will contain key after it returns (as a matter of fact, attempting to add the
- * component might actually cause it to be removed from the collection).
+ * This is technically not a valid implementation of add, because it does not
+ * guarantee that the set will contain key after it returns (as a matter of
+ * fact, attempting to add the component might actually cause it to be removed
+ * from the collection).
*/
@Override
public boolean add(KeyType key) {
// Qualified-this; allows us to reference the 'this' of our enclosing type.
int ret = ThresholdSet.this.add(key);
-
+
// No change to set contents
- if (ret > 2) return false;
+ if (ret > 2)
+ return false;
return true;
}
-
+
@Override
public boolean remove(Object o) {
// Will throw a ClassCastException if you give us something bad.
- KeyType k = (KeyType)o;
+ KeyType k = (KeyType) o;
int ret = ThresholdSet.this.remove(k);
// We removed the element.
- if (ret == 0) return true;
+ if (ret == 0)
+ return true;
return false;
}
@@ -55,12 +60,13 @@ public class ThresholdSet<KeyType> {
@Override
public boolean contains(Object o) {
// Will throw a ClassCastException if you give us something bad.
- KeyType k = (KeyType)o;
+ KeyType k = (KeyType) o;
int ret = ThresholdSet.this.contains(k);
// The object is set-visible
- if (ret == 1) return true;
+ if (ret == 1)
+ return true;
return false;
}
@@ -80,7 +86,8 @@ public class ThresholdSet<KeyType> {
private Set<KeyType> keySet;
// @TODO :CountMap Ben Culkin 6/19/2019
- // Replace this with a CountSet or some equivalent concept, whenever that gets written, if that
+ // Replace this with a CountSet or some equivalent concept, whenever that gets
+ // written, if that
// gets written
private Map<KeyType, Integer> keyMap;
@@ -95,8 +102,8 @@ public class ThresholdSet<KeyType> {
/**
* Add multiple keys at once to the map.
*
- * @param keys
- * The keys to add.
+ * @param keys
+ * The keys to add.
*
* @return An array containing the results of adding the keys.
*/
@@ -114,9 +121,10 @@ public class ThresholdSet<KeyType> {
* Add a key to the collection.
*
* @param key
- * The key to add to the collection.
+ * The key to add to the collection.
*
- * @return The number of times that key now exists in the collection. Should always be &lt; 0.
+ * @return The number of times that key now exists in the collection. Should
+ * always be &lt; 0.
*/
public int add(KeyType key) {
if (keySet.contains(key)) {
@@ -145,7 +153,7 @@ public class ThresholdSet<KeyType> {
* Remove a bunch of keys from the collection.
*
* @param keys
- * The keys to remove from the collection.
+ * The keys to remove from the collection.
*
* @return The results from removing the keys.
*/
@@ -163,10 +171,10 @@ public class ThresholdSet<KeyType> {
* Remove a key from the collection.
*
* @param key
- * The key to remove from the collection.
+ * The key to remove from the collection.
*
- * @return The number of times that key now exists in the collection. Returns -1 if that key
- * wasn't in the collection beforehand.
+ * @return The number of times that key now exists in the collection. Returns -1
+ * if that key wasn't in the collection beforehand.
*/
public int remove(KeyType key) {
if (keySet.contains(key)) {
@@ -200,7 +208,7 @@ public class ThresholdSet<KeyType> {
* Get the number of times the set contains a set of given keys.
*
* @param keys
- * The keys to look for.
+ * The keys to look for.
*
* @return The containment counts for each key.
*/
@@ -218,13 +226,15 @@ public class ThresholdSet<KeyType> {
* Get the number of times the set contains a given key.
*
* @param key
- * The key to look for.
+ * The key to look for.
*
* @return The number of times the key occurs; -1 if it doesn't occur.
*/
public int contains(KeyType key) {
- if (keySet.contains(key)) return 1;
- if (!keyMap.containsKey(key)) return -1;
+ if (keySet.contains(key))
+ return 1;
+ if (!keyMap.containsKey(key))
+ return -1;
return keyMap.get(key);
}
@@ -256,7 +266,7 @@ public class ThresholdSet<KeyType> {
* Static threshold set constructor.
*
* @param keys
- * The initial keys to add to the threshold set.
+ * The initial keys to add to the threshold set.
*/
@SafeVarargs
public static <KType> ThresholdSet<KType> TS(KType... keys) {
diff --git a/src/main/java/bjc/esodata/UnifiedDirectory.java b/src/main/java/bjc/esodata/UnifiedDirectory.java
index dec940f..2221615 100644
--- a/src/main/java/bjc/esodata/UnifiedDirectory.java
+++ b/src/main/java/bjc/esodata/UnifiedDirectory.java
@@ -11,10 +11,10 @@ import bjc.funcdata.IMap;
* @author EVE
*
* @param <K>
- * The key type of the directory.
+ * The key type of the directory.
*
* @param <V>
- * The value type of the directory.
+ * The value type of the directory.
*/
public class UnifiedDirectory<K, V> implements Directory<K, V> {
/* Our directory children. */
@@ -40,7 +40,7 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> {
@Override
public Directory<K, V> putSubdirectory(final K key, final Directory<K, V> val) {
- if(data.containsKey(key)) {
+ if (data.containsKey(key)) {
final String msg = String.format("Key %s is already used for data", key);
throw new IllegalArgumentException(msg);
@@ -61,8 +61,9 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> {
@Override
public V putKey(final K key, final V val) {
- if(children.containsKey(key)) {
- final String msg = String.format("Key %s is already used for sub-directories.", key);
+ if (children.containsKey(key)) {
+ final String msg
+ = String.format("Key %s is already used for sub-directories.", key);
throw new IllegalArgumentException(msg);
}
@@ -81,19 +82,26 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof UnifiedDirectory<?, ?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof UnifiedDirectory<?, ?>))
+ return false;
final UnifiedDirectory<?, ?> other = (UnifiedDirectory<?, ?>) obj;
- if(children == null) {
- if(other.children != null) return false;
- } else if(!children.equals(other.children)) return false;
-
- if(data == null) {
- if(other.data != null) return false;
- } else if(!data.equals(other.data)) return false;
+ if (children == null) {
+ if (other.children != null)
+ return false;
+ } else if (!children.equals(other.children))
+ return false;
+
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
return true;
}