From df94066e3af02ff02d5ab4d033a3d603f743234c Mon Sep 17 00:00:00 2001 From: bjculkin Date: Mon, 12 Feb 2018 22:45:04 -0500 Subject: Formatting pass --- .../src/main/java/bjc/utils/esodata/AbbrevMap.java | 4 +- .../src/main/java/bjc/utils/esodata/Directory.java | 221 ++++++++++----------- .../main/java/bjc/utils/esodata/DoubleTape.java | 30 +-- .../main/java/bjc/utils/esodata/PushdownMap.java | 27 ++- .../main/java/bjc/utils/esodata/QueueStack.java | 18 +- .../java/bjc/utils/esodata/SimpleDirectory.java | 24 +-- .../main/java/bjc/utils/esodata/SimpleStack.java | 18 +- .../main/java/bjc/utils/esodata/SingleTape.java | 43 ++-- .../java/bjc/utils/esodata/SpaghettiStack.java | 26 +-- base/src/main/java/bjc/utils/esodata/Stack.java | 118 +++++------ base/src/main/java/bjc/utils/esodata/Tape.java | 39 ++-- .../main/java/bjc/utils/esodata/TapeChanger.java | 79 ++++---- .../main/java/bjc/utils/esodata/TapeLibrary.java | 77 ++++--- .../java/bjc/utils/esodata/UnifiedDirectory.java | 26 +-- 14 files changed, 359 insertions(+), 391 deletions(-) (limited to 'base/src/main/java/bjc/utils/esodata') diff --git a/base/src/main/java/bjc/utils/esodata/AbbrevMap.java b/base/src/main/java/bjc/utils/esodata/AbbrevMap.java index 64f542a..59888c0 100644 --- a/base/src/main/java/bjc/utils/esodata/AbbrevMap.java +++ b/base/src/main/java/bjc/utils/esodata/AbbrevMap.java @@ -168,7 +168,9 @@ public class AbbrevMap { */ public String[] deabbrev(final String abbrev) { if(abbrevMap.containsKey(abbrev)) { - return new String[] { abbrevMap.get(abbrev) }; + return new String[] { + abbrevMap.get(abbrev) + }; } return ambMap.get(abbrev).toArray(new String[0]); diff --git a/base/src/main/java/bjc/utils/esodata/Directory.java b/base/src/main/java/bjc/utils/esodata/Directory.java index 4b25cda..b0abd7c 100644 --- a/base/src/main/java/bjc/utils/esodata/Directory.java +++ b/base/src/main/java/bjc/utils/esodata/Directory.java @@ -1,114 +1,107 @@ -package bjc.utils.esodata; - -/** - * Represents a hierarchical map. - * - * What's useful about this is that you can hand sub-directories to people and - * be able to ensure that they can't write outside of it. - * - * @param - * The key type of the map. - * @param - * The value type of the map. - */ -public interface Directory { - /** - * Retrieves a given sub-directory. - * - * @param key - * 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. - */ - Directory getSubdirectory(K key); - - /** - * Check if a given sub-directory exists. - * - * @param key - * The key to look for the sub-directory under. - * - * @return - * Whether or not a sub-directory of that name exists. - */ - boolean hasSubdirectory(K key); - - /** - * Insert a sub-directory into the dictionary. - * - * @param key - * The name of the new sub-directory - * @param value - * The sub-directory to insert - * - * @return - * The old sub-directory attached to this key, or null if such a - * sub-directory didn't exist - */ - Directory putSubdirectory(K key, Directory value); - - /** - * Create a new sub-directory. - * - * Will fail if a sub-directory of that name already exists. - * - * @param key - * The name of the new sub-directory. - * - * @return - * The new sub-directory, or null if one by that name already - * exists. - */ - default Directory newSubdirectory(final K key) { - if (hasSubdirectory(key)) return null; - - final Directory dir = new SimpleDirectory<>(); - - putSubdirectory(key, dir); - - return dir; - } - - /** - * Check if the directory contains a data-item under the given key. - * - * @param key - * The key to check for. - * - * @return - * Whether or not there is a data item for the given key. - */ - boolean containsKey(K key); - - /** - * Retrieve a given data-item from the directory. - * - * @param key - * The key to retrieve data for. - * - * @return - * The value for the given key. - * - * @throws IllegalArgumentException - * If no value exists for the given key. - */ - V getKey(K key); - - /** - * Insert a data-item into the directory. - * - * @param key - * The key to insert into. - * - * @param val - * The value to insert. - * - * @return - * The old value of key, or null if such a value didn't exist. - */ - V putKey(K key, V val); -} +package bjc.utils.esodata; + +/** + * Represents a hierarchical map. + * + * What's useful about this is that you can hand sub-directories to people and + * be able to ensure that they can't write outside of it. + * + * @param + * The key type of the map. + * @param + * The value type of the map. + */ +public interface Directory { + /** + * Retrieves a given sub-directory. + * + * @param key + * 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. + */ + Directory getSubdirectory(K key); + + /** + * Check if a given sub-directory exists. + * + * @param key + * The key to look for the sub-directory under. + * + * @return Whether or not a sub-directory of that name exists. + */ + boolean hasSubdirectory(K key); + + /** + * Insert a sub-directory into the dictionary. + * + * @param key + * The name of the new sub-directory + * @param value + * The sub-directory to insert + * + * @return The old sub-directory attached to this key, or null if such a + * sub-directory didn't exist + */ + Directory putSubdirectory(K key, Directory value); + + /** + * Create a new sub-directory. + * + * Will fail if a sub-directory of that name already exists. + * + * @param key + * The name of the new sub-directory. + * + * @return The new sub-directory, or null if one by that name already + * exists. + */ + default Directory newSubdirectory(final K key) { + if(hasSubdirectory(key)) return null; + + final Directory dir = new SimpleDirectory<>(); + + putSubdirectory(key, dir); + + return dir; + } + + /** + * Check if the directory contains a data-item under the given key. + * + * @param key + * The key to check for. + * + * @return Whether or not there is a data item for the given key. + */ + boolean containsKey(K key); + + /** + * Retrieve a given data-item from the directory. + * + * @param key + * The key to retrieve data for. + * + * @return The value for the given key. + * + * @throws IllegalArgumentException + * If no value exists for the given key. + */ + V getKey(K key); + + /** + * Insert a data-item into the directory. + * + * @param key + * The key to insert into. + * + * @param val + * The value to insert. + * + * @return The old value of key, or null if such a value didn't exist. + */ + V putKey(K key, V val); +} diff --git a/base/src/main/java/bjc/utils/esodata/DoubleTape.java b/base/src/main/java/bjc/utils/esodata/DoubleTape.java index a0031ec..bfc58a4 100644 --- a/base/src/main/java/bjc/utils/esodata/DoubleTape.java +++ b/base/src/main/java/bjc/utils/esodata/DoubleTape.java @@ -20,15 +20,15 @@ package bjc.utils.esodata; * Flip refers to the entire tape for 'obvious' reasons. * * @param - * The element type of the tape. + * The element type of the tape. * * @author bjculkin */ public class DoubleTape implements Tape { /* The front-side of the tape. */ - private Tape front; + private Tape front; /* The back-side of the tape. */ - private Tape back; + private Tape back; /** Create a new empty double-sided tape that doesn't autoextend. */ public DoubleTape() { @@ -40,7 +40,7 @@ public class DoubleTape implements Tape { * 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); @@ -107,7 +107,7 @@ public class DoubleTape implements Tape { public boolean left(final int amt) { final boolean succ = front.left(amt); - if (succ) { + if(succ) { back.right(amt); } @@ -123,7 +123,7 @@ public class DoubleTape implements Tape { public boolean right(final int amt) { final boolean succ = front.right(amt); - if (succ) { + if(succ) { back.left(amt); } @@ -160,19 +160,19 @@ public class DoubleTape implements Tape { @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(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(front == null) { + if(other.front != null) return false; + } else if(!front.equals(other.front)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/esodata/PushdownMap.java b/base/src/main/java/bjc/utils/esodata/PushdownMap.java index 18a9b46..e010fee 100644 --- a/base/src/main/java/bjc/utils/esodata/PushdownMap.java +++ b/base/src/main/java/bjc/utils/esodata/PushdownMap.java @@ -17,10 +17,10 @@ import bjc.utils.funcdata.IMap; * @author EVE * * @param - * The key of the map. + * The key of the map. * * @param - * The values in the map. + * The values in the map. */ public class PushdownMap implements IMap { /* Our backing storage. */ @@ -84,17 +84,16 @@ public class PushdownMap implements IMap @Override public IMap transform(final Function 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 stk = backing.get(key); final ValueType vl = stk.top(); @@ -115,7 +114,7 @@ public class PushdownMap implements IMap public ValueType remove(final KeyType key) { final Stack stk = backing.get(key); - if (stk.size() > 1) { + if(stk.size() > 1) { return stk.pop(); } else { return backing.remove(key).top(); @@ -139,15 +138,15 @@ public class PushdownMap implements IMap @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/base/src/main/java/bjc/utils/esodata/QueueStack.java b/base/src/main/java/bjc/utils/esodata/QueueStack.java index be393a3..c0cbc7d 100644 --- a/base/src/main/java/bjc/utils/esodata/QueueStack.java +++ b/base/src/main/java/bjc/utils/esodata/QueueStack.java @@ -9,7 +9,7 @@ import java.util.LinkedList; * Basically, a stack that actually acts like a queue. * * @param - * The datatype stored in the stack. + * The datatype stored in the stack. * * @author Ben Culkin */ @@ -29,14 +29,14 @@ public class QueueStack extends Stack { @Override public T pop() { - if (backing.isEmpty()) throw new StackUnderflowException(); + if(backing.isEmpty()) throw new StackUnderflowException(); return backing.remove(); } @Override public T top() { - if (backing.isEmpty()) throw new StackUnderflowException(); + if(backing.isEmpty()) throw new StackUnderflowException(); return backing.peek(); } @@ -74,15 +74,15 @@ public class QueueStack extends Stack { @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/base/src/main/java/bjc/utils/esodata/SimpleDirectory.java b/base/src/main/java/bjc/utils/esodata/SimpleDirectory.java index 5e7f480..a3e0a96 100644 --- a/base/src/main/java/bjc/utils/esodata/SimpleDirectory.java +++ b/base/src/main/java/bjc/utils/esodata/SimpleDirectory.java @@ -11,10 +11,10 @@ import bjc.utils.funcdata.IMap; * @author EVE * * @param - * The key type of the directory. + * The key type of the directory. * * @param - * The value type of the directory. + * The value type of the directory. */ public class SimpleDirectory implements Directory { /* Our sub-directories. */ @@ -25,7 +25,7 @@ public class SimpleDirectory implements Directory { /** Create a new directory. */ public SimpleDirectory() { children = new FunctionalMap<>(); - data = new FunctionalMap<>(); + data = new FunctionalMap<>(); } @Override @@ -71,19 +71,19 @@ public class SimpleDirectory implements Directory { @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(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(data == null) { + if(other.data != null) return false; + } else if(!data.equals(other.data)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/esodata/SimpleStack.java b/base/src/main/java/bjc/utils/esodata/SimpleStack.java index 72fb343..8bc7e1e 100644 --- a/base/src/main/java/bjc/utils/esodata/SimpleStack.java +++ b/base/src/main/java/bjc/utils/esodata/SimpleStack.java @@ -7,7 +7,7 @@ import java.util.LinkedList; * Simple implementation of a stack. * * @param - * The datatype stored in the stack. + * The datatype stored in the stack. * * @author Ben Culkin */ @@ -27,14 +27,14 @@ public class SimpleStack extends Stack { @Override public T pop() { - if (backing.isEmpty()) throw new StackUnderflowException(); + if(backing.isEmpty()) throw new StackUnderflowException(); return backing.pop(); } @Override public T top() { - if (backing.isEmpty()) throw new StackUnderflowException(); + if(backing.isEmpty()) throw new StackUnderflowException(); return backing.peek(); } @@ -67,15 +67,15 @@ public class SimpleStack extends Stack { @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/base/src/main/java/bjc/utils/esodata/SingleTape.java b/base/src/main/java/bjc/utils/esodata/SingleTape.java index ae9b746..57ee99a 100644 --- a/base/src/main/java/bjc/utils/esodata/SingleTape.java +++ b/base/src/main/java/bjc/utils/esodata/SingleTape.java @@ -15,20 +15,20 @@ import java.util.ArrayList; * policy. * * @param - * The element type of the tape. + * The element type of the tape. * * @author bjculkin */ public class SingleTape implements Tape { - /* @NOTE - * Does this stuff still need to be protected? We're not trying to - * use inheritance to implement tape types any more, so I don't see - * any reason to not have it be private. + /* + * @NOTE Does this stuff still need to be protected? We're not trying to + * use inheritance to implement tape types any more, so I don't see any + * reason to not have it be private. */ /* Our backing store. */ - protected ArrayList backing; + protected ArrayList backing; /* Our position in the list. */ - protected int pos; + protected int pos; /* Whether to auto-extend the list on the left with nulls. */ protected boolean autoExtend; @@ -57,7 +57,7 @@ public class SingleTape implements Tape { * 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; @@ -92,7 +92,7 @@ public class SingleTape implements Tape { @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); @@ -102,7 +102,7 @@ public class SingleTape implements Tape { @Override public T remove() { final T res = backing.remove(pos); - if (pos != 0) { + if(pos != 0) { pos -= 1; } return res; @@ -125,7 +125,7 @@ public class SingleTape implements Tape { @Override public boolean left(final int amt) { - if (pos - amt < 0) return false; + if(pos - amt < 0) return false; pos -= amt; return true; @@ -138,12 +138,13 @@ public class SingleTape implements Tape { @Override public boolean right(final int amt) { - if (pos + amt >= backing.size() - 1) { - if (autoExtend) { - while (pos + amt >= backing.size() - 1) { + if(pos + amt >= backing.size() - 1) { + if(autoExtend) { + while(pos + amt >= backing.size() - 1) { backing.add(null); } - } else return false; + } else + return false; } pos += amt; @@ -167,15 +168,15 @@ public class SingleTape implements Tape { @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; } diff --git a/base/src/main/java/bjc/utils/esodata/SpaghettiStack.java b/base/src/main/java/bjc/utils/esodata/SpaghettiStack.java index f445f75..8f2924b 100644 --- a/base/src/main/java/bjc/utils/esodata/SpaghettiStack.java +++ b/base/src/main/java/bjc/utils/esodata/SpaghettiStack.java @@ -8,7 +8,7 @@ import java.util.stream.Stream; * parent stack. * * @param - * The datatype stored in the stack. + * The datatype stored in the stack. * * @author Ben Culkin */ @@ -22,7 +22,7 @@ class SpaghettiStack extends Stack { * Create a new empty spaghetti stack, off of the specified parent. * * @param par - * The parent stack + * The parent stack */ public SpaghettiStack(final Stack par) { backing = new SimpleStack<>(); @@ -37,14 +37,14 @@ class SpaghettiStack extends Stack { @Override public T pop() { - if (backing.empty()) return parent.pop(); + if(backing.empty()) return parent.pop(); return backing.pop(); } @Override public T top() { - if (backing.empty()) return parent.top(); + if(backing.empty()) return parent.top(); return backing.top(); } @@ -78,19 +78,19 @@ class SpaghettiStack extends Stack { @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(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(parent == null) { + if(other.parent != null) return false; + } else if(!parent.equals(other.parent)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/esodata/Stack.java b/base/src/main/java/bjc/utils/esodata/Stack.java index 9bb61dc..5c923c3 100644 --- a/base/src/main/java/bjc/utils/esodata/Stack.java +++ b/base/src/main/java/bjc/utils/esodata/Stack.java @@ -21,7 +21,7 @@ import java.util.function.Consumer; *

* * @param - * The datatype stored in the stack. + * The datatype stored in the stack. * * @author Ben Culkin */ @@ -41,15 +41,14 @@ public abstract class Stack { * Push an element onto the stack. * * @param elm - * The element to insert. + * The element to insert. */ public abstract void push(T elm); /** * Pop an element off of the stack. * - * @return - * The element on top of the stack. + * @return The element on top of the stack. */ public abstract T pop(); @@ -57,32 +56,28 @@ public abstract class Stack { * Retrieve the top element of this stack without removing it from the * stack. * - * @return - * The top element of this stack. + * @return The top element of this stack. */ public abstract T top(); /** * Get the number of elements in the stack. * - * @return - * the number of elements in the stack. + * @return the number of elements in the stack. */ public abstract int size(); /** * Check if the stack is empty. * - * @return - * Whether or not the stack is empty. + * @return Whether or not the stack is empty. */ public abstract boolean empty(); /** * Create a spaghetti stack branching off of this one. * - * @return - * A spaghetti stack with this stack as a parent. + * @return A spaghetti stack with this stack as a parent. */ public Stack spaghettify() { return new SpaghettiStack<>(this); @@ -96,10 +91,10 @@ public abstract class Stack { * 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(); } } @@ -113,7 +108,7 @@ public abstract class Stack { * 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(); @@ -132,20 +127,20 @@ public abstract class Stack { * 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) { final List lst = new ArrayList<>(n); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for (int i = 0; i < m; i++) { - for (final T elm : lst) { + for(int i = 0; i < m; i++) { + for(final T elm : lst) { push(elm); } } @@ -155,7 +150,7 @@ public abstract class Stack { * 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, 2); @@ -170,27 +165,27 @@ public abstract class Stack { * 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) { final List lst = new ArrayList<>(n); final T elm = pop(); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for (final T nelm : lst) { + for(final T nelm : lst) { push(nelm); } push(elm); - for (int i = 1; i < m; i++) { - for (final T nelm : lst) { + for(int i = 1; i < m; i++) { + for(final T nelm : lst) { push(nelm); } } @@ -200,7 +195,7 @@ public abstract class Stack { * 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, 2); @@ -275,9 +270,8 @@ public abstract class Stack { push(y); } - /* - * :StackCombinators - * Add a general rotate/roll operator. + /* + * :StackCombinators Add a general rotate/roll operator. */ /* @@ -288,21 +282,21 @@ public abstract class Stack { * 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> action) { final List elms = new ArrayList<>(n); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { elms.set(i - 1, pop()); } action.accept(this); - for (final T elm : elms) { + for(final T elm : elms) { push(elm); } } @@ -311,26 +305,25 @@ public abstract class Stack { * 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> 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> action) { /* - * @NOTE - * Is this correct? + * @NOTE Is this correct? */ dup(n); dip(n, action); @@ -340,20 +333,20 @@ public abstract class Stack { * 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>> actions) { final List elms = new ArrayList<>(n); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { elms.set(i - 1, pop()); } - for (final Consumer> action : actions) { - for (final T elm : elms) { + for(final Consumer> action : actions) { + for(final T elm : elms) { push(elm); } @@ -365,7 +358,7 @@ public abstract class Stack { * 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>> actions) { multicleave(1, actions); @@ -375,18 +368,18 @@ public abstract class Stack { * 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>> actions) { final List> nelms = new ArrayList<>(actions.size()); - for (int i = actions.size(); i > 0; i--) { + for(int i = actions.size(); i > 0; i--) { final List elms = new ArrayList<>(n); - for (int j = n; j > 0; j--) { + for(int j = n; j > 0; j--) { elms.set(j, pop()); } @@ -394,8 +387,8 @@ public abstract class Stack { } int i = 0; - for (final List elms : nelms) { - for (final T elm : elms) { + for(final List elms : nelms) { + for(final T elm : elms) { push(elm); } @@ -409,7 +402,7 @@ public abstract class Stack { * the stack. * * @param conses - * The actions to execute. + * The actions to execute. */ public void spread(final List>> conses) { multispread(1, conses); @@ -419,18 +412,18 @@ public abstract class Stack { * 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> action) { final List>> actions = new ArrayList<>(m); - for (int i = 0; i < m; i++) { + for(int i = 0; i < m; i++) { actions.add(action); } @@ -441,10 +434,10 @@ public abstract class Stack { * 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> action) { multiapply(1, n, action); @@ -457,8 +450,7 @@ public abstract class Stack { /** * Get an array representing this stack. * - * @return - * The stack as an array. + * @return The stack as an array. */ public abstract T[] toArray(); } diff --git a/base/src/main/java/bjc/utils/esodata/Tape.java b/base/src/main/java/bjc/utils/esodata/Tape.java index dab027f..91a404a 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 - * The element type of the tape. + * The element type of the tape. * * @author bjculkin */ @@ -16,8 +16,7 @@ public interface Tape { /** * Get the item the tape is currently on. * - * @return - * The item the tape is on. + * @return The item the tape is on. */ T item(); @@ -25,23 +24,21 @@ public interface Tape { * 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); /** * Get the current number of elements in the tape. * - * @return - * The current number of elements in the tape. + * @return The current number of elements in the tape. */ int size(); /** * Get the position of the current item. * - * @return - * The position of the current item. + * @return The position of the current item. */ int position(); @@ -49,7 +46,7 @@ public interface Tape { * Insert an element before the current item. * * @param itm - * The item to add. + * The item to add. */ void insertBefore(T itm); @@ -57,7 +54,7 @@ public interface Tape { * Insert an element after the current item. * * @param itm - * The item to insert. + * The item to insert. */ void insertAfter(T itm); @@ -67,8 +64,7 @@ public interface Tape { * Also moves the cursor back one step if possible to maintain relative * position. * - * @return - * The removed item. + * @return The removed item. */ T remove(); @@ -83,8 +79,7 @@ public interface Tape { * * The cursor can't go past zero. * - * @return - * True if the cursor was moved left. + * @return True if the cursor was moved left. */ boolean left(); @@ -95,18 +90,16 @@ public interface Tape { * 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. + * @return True if the cursor was moved left. */ boolean left(int amt); /** * Move the cursor one space right. * - * @return - * Whether the cursor was moved right. + * @return Whether the cursor was moved right. */ boolean right(); @@ -114,18 +107,16 @@ public interface Tape { * 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. + * @return Whether the cursor was moved right. */ boolean right(int amt); /** * Is this tape double sided? * - * @return - * Whether or not this tape is double-sided. + * @return Whether or not this tape is double-sided. */ boolean isDoubleSided(); } diff --git a/base/src/main/java/bjc/utils/esodata/TapeChanger.java b/base/src/main/java/bjc/utils/esodata/TapeChanger.java index 08f56c1..2623ad3 100644 --- a/base/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/base/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -10,13 +10,13 @@ package bjc.utils.esodata; * either return null/false. * * @param - * The element type of the tapes. + * The element type of the tapes. */ public class TapeChanger implements Tape { /* Our list of tapes. */ private Tape> tapes; /* The current tape. */ - private Tape currentTape; + private Tape currentTape; /** Create a new empty tape changer. */ public TapeChanger() { @@ -27,10 +27,10 @@ public class TapeChanger implements Tape { * Create a new tape changer with the specified tapes. * * @param current - * The tape to mount first. + * The tape to mount first. * * @param others - * The tapes to put in this tape changer. + * The tapes to put in this tape changer. */ @SafeVarargs public TapeChanger(final Tape current, final Tape... others) { @@ -38,7 +38,7 @@ public class TapeChanger implements Tape { tapes.insertBefore(current); - for (final Tape tp : others) { + for(final Tape tp : others) { tapes.insertAfter(tp); tapes.right(); } @@ -49,63 +49,63 @@ public class TapeChanger implements Tape { @Override public T item() { - if (currentTape == null) return null; + if(currentTape == null) return null; return currentTape.item(); } @Override public void item(final T itm) { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.item(itm); } @Override public int size() { - if (currentTape == null) return 0; + if(currentTape == null) return 0; return currentTape.size(); } @Override public int position() { - if (currentTape == null) return 0; + if(currentTape == null) return 0; return currentTape.position(); } @Override public void insertBefore(final T itm) { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.insertBefore(itm); } @Override public void insertAfter(final T itm) { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.insertAfter(itm); } @Override public T remove() { - if (currentTape == null) return null; + if(currentTape == null) return null; return currentTape.remove(); } @Override public void first() { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.first(); } @Override public void last() { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.last(); } @@ -117,7 +117,7 @@ public class TapeChanger implements Tape { @Override public boolean left(final int amt) { - if (currentTape == null) return false; + if(currentTape == null) return false; return currentTape.left(amt); } @@ -129,7 +129,7 @@ public class TapeChanger implements Tape { @Override public boolean right(final int amt) { - if (currentTape == null) return false; + if(currentTape == null) return false; return currentTape.right(amt); } @@ -143,16 +143,16 @@ public class TapeChanger implements Tape { * If the current tape is not double-sided, does nothing. */ public void flip() { - if (currentTape == null) return; + if(currentTape == null) return; - if (currentTape.isDoubleSided()) { + if(currentTape.isDoubleSided()) { ((DoubleTape) currentTape).flip(); } } @Override public boolean isDoubleSided() { - if (currentTape == null) return false; + if(currentTape == null) return false; return currentTape.isDoubleSided(); } @@ -160,8 +160,7 @@ public class TapeChanger implements Tape { /** * Check if a tape is currently loaded. * - * @return - * Whether or not a tape is loaded. + * @return Whether or not a tape is loaded. */ public boolean isLoaded() { return currentTape != null; @@ -173,13 +172,12 @@ public class TapeChanger implements Tape { * Attempting to load a tape that isn't there won't eject the current * tape. * - * @return - * Whether or not the next tape was loaded. + * @return Whether or not the next tape was loaded. */ public boolean nextTape() { final boolean succ = tapes.right(); - if (succ) { + if(succ) { currentTape = tapes.item(); } @@ -192,13 +190,12 @@ public class TapeChanger implements Tape { * Attempting to load a tape that isn't there won't eject the current * tape. * - * @return - * Whether or not the previous tape was loaded. + * @return Whether or not the previous tape was loaded. */ public boolean prevTape() { final boolean succ = tapes.left(); - if (succ) { + if(succ) { currentTape = tapes.item(); } @@ -213,7 +210,7 @@ public class TapeChanger implements Tape { * The specified tape is loaded. * * @param tp - * The tape to insert and load. + * The tape to insert and load. */ public void insertTape(final Tape tp) { tapes.insertAfter(tp); @@ -229,11 +226,10 @@ public class TapeChanger implements Tape { * * Loads the previous tape, if there is one. * - * @return - * The removed tape. + * @return The removed tape. */ public Tape removeTape() { - if (currentTape == null) return null; + if(currentTape == null) return null; final Tape tp = tapes.remove(); currentTape = tapes.item(); @@ -253,8 +249,7 @@ public class TapeChanger implements Tape { /** * Get how many tapes are currently in the changer. * - * @return - * How many tapes are currently in the changer. + * @return How many tapes are currently in the changer. */ public int tapeCount() { return tapes.size(); @@ -271,19 +266,19 @@ public class TapeChanger implements Tape { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof TapeChanger)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof TapeChanger)) return false; final TapeChanger other = (TapeChanger) obj; - if (currentTape == null) { - if (other.currentTape != null) return false; - } else if (!currentTape.equals(other.currentTape)) return false; + if(currentTape == null) { + if(other.currentTape != null) return false; + } else if(!currentTape.equals(other.currentTape)) return false; - if (tapes == null) { - if (other.tapes != null) return false; - } else if (!tapes.equals(other.tapes)) return false; + if(tapes == null) { + if(other.tapes != null) return false; + } else if(!tapes.equals(other.tapes)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/esodata/TapeLibrary.java b/base/src/main/java/bjc/utils/esodata/TapeLibrary.java index 00e2e99..4ebfd6c 100644 --- a/base/src/main/java/bjc/utils/esodata/TapeLibrary.java +++ b/base/src/main/java/bjc/utils/esodata/TapeLibrary.java @@ -13,13 +13,13 @@ import java.util.Map; * either return null/false. * * @param - * The element type of the tapes. + * The element type of the tapes. */ public class TapeLibrary implements Tape { /* Our backing store of tapes. */ private final Map> tapes; /* The current tape. */ - private Tape currentTape; + private Tape currentTape; /** Create a new empty tape library. */ public TapeLibrary() { @@ -28,63 +28,63 @@ public class TapeLibrary implements Tape { @Override public T item() { - if (currentTape == null) return null; + if(currentTape == null) return null; return currentTape.item(); } @Override public void item(final T itm) { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.item(itm); } @Override public int size() { - if (currentTape == null) return 0; + if(currentTape == null) return 0; return currentTape.size(); } @Override public int position() { - if (currentTape == null) return 0; + if(currentTape == null) return 0; return currentTape.position(); } @Override public void insertBefore(final T itm) { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.insertBefore(itm); } @Override public void insertAfter(final T itm) { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.insertAfter(itm); } @Override public T remove() { - if (currentTape == null) return null; + if(currentTape == null) return null; return currentTape.remove(); } @Override public void first() { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.first(); } @Override public void last() { - if (currentTape == null) return; + if(currentTape == null) return; currentTape.last(); } @@ -96,7 +96,7 @@ public class TapeLibrary implements Tape { @Override public boolean left(final int amt) { - if (currentTape == null) return false; + if(currentTape == null) return false; return currentTape.left(amt); } @@ -108,7 +108,7 @@ public class TapeLibrary implements Tape { @Override public boolean right(final int amt) { - if (currentTape == null) return false; + if(currentTape == null) return false; return currentTape.right(amt); } @@ -122,16 +122,16 @@ public class TapeLibrary implements Tape { * If the current tape is not double-sided, does nothing. */ public void flip() { - if (currentTape == null) return; + if(currentTape == null) return; - if (currentTape.isDoubleSided()) { + if(currentTape.isDoubleSided()) { ((DoubleTape) currentTape).flip(); } } @Override public boolean isDoubleSided() { - if (currentTape == null) return false; + if(currentTape == null) return false; return currentTape.isDoubleSided(); } @@ -139,8 +139,7 @@ public class TapeLibrary implements Tape { /** * Check if a tape is currently loaded. * - * @return - * Whether or not a tape is loaded. + * @return Whether or not a tape is loaded. */ public boolean isLoaded() { return currentTape != null; @@ -153,13 +152,12 @@ public class TapeLibrary implements Tape { * tape. * * @param label - * The label of the tape to load. + * The label of the tape to load. * - * @return - * Whether or not the next tape was loaded. + * @return Whether or not the next tape was loaded. */ public boolean switchTape(final String label) { - if (tapes.containsKey(label)) { + if(tapes.containsKey(label)) { currentTape = tapes.get(label); return true; } @@ -177,10 +175,10 @@ public class TapeLibrary implements Tape { * Adding a duplicate tape will overwrite any existing types. * * @param label - * The label of the tape to add. + * The label of the tape to add. * * @param tp - * The tape to insert and load. + * The tape to insert and load. */ public void insertTape(final String label, final Tape tp) { tapes.put(label, tp); @@ -194,10 +192,9 @@ public class TapeLibrary implements Tape { * Does nothing if there is not a tape of that name loaded. * * @param label - * The tape to remove. + * The tape to remove. * - * @return - * The removed tape. + * @return The removed tape. */ public Tape removeTape(final String label) { return tapes.remove(label); @@ -215,8 +212,7 @@ public class TapeLibrary implements Tape { /** * Get how many tapes are currently in the library. * - * @return - * How many tapes are currently in the library. + * @return How many tapes are currently in the library. */ public int tapeCount() { return tapes.size(); @@ -226,10 +222,9 @@ public class TapeLibrary implements Tape { * Check if a specific tape is loaded into the library. * * @param label - * The tape to check for. + * The tape to check for. * - * @return - * Whether or not a tape of that name exists + * @return Whether or not a tape of that name exists */ public boolean hasTape(final String label) { return tapes.containsKey(label); @@ -248,19 +243,19 @@ public class TapeLibrary implements Tape { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof TapeLibrary)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof TapeLibrary)) return false; final TapeLibrary other = (TapeLibrary) obj; - if (currentTape == null) { - if (other.currentTape != null) return false; - } else if (!currentTape.equals(other.currentTape)) return false; + if(currentTape == null) { + if(other.currentTape != null) return false; + } else if(!currentTape.equals(other.currentTape)) return false; - if (tapes == null) { - if (other.tapes != null) return false; - } else if (!tapes.equals(other.tapes)) return false; + if(tapes == null) { + if(other.tapes != null) return false; + } else if(!tapes.equals(other.tapes)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/esodata/UnifiedDirectory.java b/base/src/main/java/bjc/utils/esodata/UnifiedDirectory.java index ed71512..75d3440 100644 --- a/base/src/main/java/bjc/utils/esodata/UnifiedDirectory.java +++ b/base/src/main/java/bjc/utils/esodata/UnifiedDirectory.java @@ -11,10 +11,10 @@ import bjc.utils.funcdata.IMap; * @author EVE * * @param - * The key type of the directory. + * The key type of the directory. * * @param - * The value type of the directory. + * The value type of the directory. */ public class UnifiedDirectory implements Directory { /* Our directory children. */ @@ -40,7 +40,7 @@ public class UnifiedDirectory implements Directory { @Override public Directory putSubdirectory(final K key, final Directory 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,7 +61,7 @@ public class UnifiedDirectory implements Directory { @Override public V putKey(final K key, final V val) { - if (children.containsKey(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 +81,19 @@ public class UnifiedDirectory implements Directory { @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(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(data == null) { + if(other.data != null) return false; + } else if(!data.equals(other.data)) return false; return true; } -- cgit v1.2.3