diff options
| author | EVE <EVE@EVE-PC> | 2017-03-13 16:42:21 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-13 16:42:21 -0400 |
| commit | 27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd (patch) | |
| tree | 847fb52acb091c1c613d37b8477094d5762c6988 /BJC-Utils2/src/main/java/bjc/utils/esodata | |
| parent | aa807a96cae2c47259fb38f710640883060339e9 (diff) | |
Formatting
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata')
10 files changed, 319 insertions, 205 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java index 734bbd8..3d02c9c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java @@ -9,8 +9,10 @@ import bjc.utils.funcdata.IMap; * 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 K The key type of the map. - * @param V The value type of the map. + * @param K + * The key type of the map. + * @param V + * The value type of the map. */ public class Directory<K, V> { private IMap<K, Directory<K, V>> children; @@ -22,7 +24,7 @@ public class Directory<K, V> { */ public Directory() { children = new FunctionalMap<>(); - data = new FunctionalMap<>(); + data = new FunctionalMap<>(); } /** @@ -30,13 +32,15 @@ public class Directory<K, V> { * * Will fail if a sub-directory of that name already exists. * - * @param key The name of the new sub-directory. + * @param key + * The name of the new sub-directory. * * @return The new sub-directory, or null if one by that name already - * exists. + * exists. */ public Directory<K, V> newSubdirectory(K key) { - if(children.containsKey(key)) return null; + if (children.containsKey(key)) + return null; Directory<K, V> kid = new Directory<>(); children.put(key, kid); @@ -46,7 +50,8 @@ public class Directory<K, V> { /** * Check if a given sub-directory exists. * - * @param key The key to look for the sub-directory under. + * @param key + * The key to look for the sub-directory under. * * @return Whether or not a sub-directory of that name exists. */ @@ -57,12 +62,13 @@ public class Directory<K, V> { /** * Retrieves a given sub-directory. * - * @param key The key to retrieve the sub-directory for. + * @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. + * @throws IllegalArgumentException + * If the given sub-directory doesn't exist. */ public Directory<K, V> getSubdirectory(K key) { return children.get(key); @@ -71,8 +77,10 @@ public class Directory<K, V> { /** * Insert a data-item into the directory. * - * @param key The key to insert into. - * @param val The value to insert. + * @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. */ @@ -83,7 +91,8 @@ public class Directory<K, V> { /** * Check if the directory contains a data-item under the given key. * - * @param key The key to check for. + * @param key + * The key to check for. * * @return Whether or not there is a data item for the given key. */ @@ -94,12 +103,13 @@ public class Directory<K, V> { /** * Retrive a given data-item from the directory. * - * @param key The key to retrieve data for. + * @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. + * @throws IllegalArgumentException + * If no value exists for the given key. */ public V get(K key) { return data.get(key); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java index bc8ac51..85abbdc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java @@ -1,22 +1,26 @@ package bjc.utils.esodata; /** - * Double-sided tape is essentially two tapes stuck together with a shared cursor. + * Double-sided tape is essentially two tapes stuck together with a shared + * cursor. * - * The main way a double-sided tape differs is that it can be flipped, allowing access to - * another set of data. + * The main way a double-sided tape differs is that it can be flipped, allowing + * access to another set of data. * - * However, there is only one cursor, and the position of the cursor on one side is the inverse - * of the position on the other side. + * However, there is only one cursor, and the position of the cursor on one side + * is the inverse of the position on the other side. * - * When one side is extended, a null will be inserted into the inactive side regardless of the - * auto-extension policy of the tape. The policy will still be respected for the active side. + * When one side is extended, a null will be inserted into the inactive side + * regardless of the auto-extension policy of the tape. The policy will still be + * respected for the active side. * - * All operations that refer to the tape refer to the currently active side of the tape, except for flip. + * All operations that refer to the tape refer to the currently active side of + * the tape, except for flip. * * Flip refers to the entire tape for 'obvious' reasons. * - * @param T The element type of the tape. + * @param T + * The element type of the tape. * @author bjculkin */ public class DoubleTape<T> implements Tape<T> { @@ -31,14 +35,16 @@ public class DoubleTape<T> implements Tape<T> { } /** - * Create a new empty double-sided tape that follows the specified auto-extension policy. + * Create a new empty double-sided tape that follows the specified + * auto-extension policy. * - * @param autoExtnd Whether or not to auto-extend the tape to the right - * w/ nulls. + * @param autoExtnd + * Whether or not to auto-extend the tape to the right w/ + * nulls. */ public DoubleTape(boolean autoExtnd) { front = new SingleTape<>(autoExtnd); - back = new SingleTape<>(autoExtnd); + back = new SingleTape<>(autoExtnd); } /** @@ -53,7 +59,8 @@ public class DoubleTape<T> implements Tape<T> { /** * Set the item the tape is currently on. * - * @param itm The new value for the tape item. + * @param itm + * The new value for the tape item. */ public void item(T itm) { front.item(itm); @@ -71,7 +78,8 @@ public class DoubleTape<T> implements Tape<T> { /** * Insert an element before the current item. * - * @param itm The item to add. + * @param itm + * The item to add. */ public void insertBefore(T itm) { front.insertBefore(itm); @@ -89,8 +97,8 @@ public class DoubleTape<T> implements Tape<T> { /** * Remove the current element. * - * Also moves the cursor back one step if possible to maintain - * relative position, and removes the corresponding item from the non-active side + * Also moves the cursor back one step if possible to maintain relative + * position, and removes the corresponding item from the non-active side * * @return The removed item from the active side. */ @@ -130,23 +138,23 @@ public class DoubleTape<T> implements 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. + * @param amt + * The amount to attempt to move the cursor left. * * @return True if the cursor was moved left. */ public boolean left(int amt) { boolean succ = front.left(amt); - if(succ) back.right(amt); + if (succ) + back.right(amt); return succ; } - /** * Move the cursor one space right. * @@ -163,14 +171,16 @@ public class DoubleTape<T> implements Tape<T> { * * Moving the cursor right will auto-extend the tape if that is enabled. * - * @param amt The amount to move the cursor right by. + * @param amt + * The amount to move the cursor right by. * * @return Whether the cursor was moved right. */ public boolean right(int amt) { boolean succ = front.right(amt); - if(succ) back.left(amt); + if (succ) + back.left(amt); return succ; } @@ -178,7 +188,8 @@ public class DoubleTape<T> implements Tape<T> { /** * Flips the tape. * - * The active side becomes inactive, and the inactive side becomes active. + * The active side becomes inactive, and the inactive side becomes + * active. */ public void flip() { Tape<T> tmp = front; diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java index 00b1555..c1a21b6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/QueueStack.java @@ -6,7 +6,8 @@ import java.util.LinkedList; /** * A FIFO implementation of a stack. * - * @param T The datatype stored in the stack. + * @param T + * The datatype stored in the stack. * @author Ben Culkin */ public class QueueStack<T> extends Stack<T> { diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java index 5f86ecc..1344754 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleStack.java @@ -6,7 +6,8 @@ import java.util.LinkedList; /** * Simple implementation of a stack. * - * @param T The datatype stored in the stack. + * @param T + * The datatype stored in the stack. * @author Ben Culkin */ public class SimpleStack<T> extends Stack<T> { diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java index 0e0deb2..a323ba4 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java @@ -3,16 +3,19 @@ package bjc.utils.esodata; import java.util.ArrayList; /** - * A tape is a one-dimensional array that can only be accessed in one position at a time. + * A tape is a one-dimensional array that can only be accessed in one position + * at a time. * - * A tape is essentially a 1D array with a cursor attached to it, and you can only - * affect elements at that cursor. The size of the array is theoretically unbounded - * to the right, but in practice bounded by available memory. + * A tape is essentially a 1D array with a cursor attached to it, and you can + * only affect elements at that cursor. The size of the array is theoretically + * unbounded to the right, but in practice bounded by available memory. * - * You can choose whether or not you want the tape to automatically extend itself to the - * right with null elements by specifiying its auto-extension policy. + * You can choose whether or not you want the tape to automatically extend + * itself to the right with null elements by specifiying its auto-extension + * policy. * - * @param T The element type of the tape. + * @param T + * The element type of the tape. * @author bjculkin */ public class SingleTape<T> implements Tape<T> { @@ -29,10 +32,12 @@ public class SingleTape<T> implements Tape<T> { } /** - * 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. + * @param autoExtnd + * Whether or not to auto-extend the tape to the right w/ + * nulls. */ public SingleTape(boolean autoExtnd) { autoExtend = autoExtnd; @@ -52,7 +57,8 @@ public class SingleTape<T> implements Tape<T> { /** * Set the item the tape is currently on. * - * @param itm The new value for the tape item. + * @param itm + * The new value for the tape item. */ public void item(T itm) { backing.set(pos, itm); @@ -70,7 +76,8 @@ public class SingleTape<T> implements Tape<T> { /** * Insert an element before the current item. * - * @param itm The item to add. + * @param itm + * The item to add. */ public void insertBefore(T itm) { backing.add(pos, itm); @@ -80,21 +87,24 @@ public class SingleTape<T> implements Tape<T> { * Insert an element after the current item. */ public void insertAfter(T itm) { - if(pos == (backing.size() - 1)) backing.add(itm); - else backing.add(pos+1, itm); + if (pos == (backing.size() - 1)) + backing.add(itm); + else + backing.add(pos + 1, itm); } /** * Remove the current element. * - * Also moves the cursor back one step if possible to maintain - * relative position. + * Also moves the cursor back one step if possible to maintain relative + * position. * * @return The removed item. */ public T remove() { T res = backing.remove(pos); - if(pos != 0) pos -= 1; + if (pos != 0) + pos -= 1; return res; } @@ -126,16 +136,17 @@ public class SingleTape<T> implements 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. + * @param amt + * The amount to attempt to move the cursor left. * * @return True if the cursor was moved left. */ public boolean left(int amt) { - if((pos - amt) < 0) return false; + if ((pos - amt) < 0) + return false; pos -= amt; return true; @@ -157,14 +168,15 @@ public class SingleTape<T> implements Tape<T> { * * Moving the cursor right will auto-extend the tape if that is enabled. * - * @param amt The amount to move the cursor right by. + * @param amt + * The amount to move the cursor right by. * * @return Whether the cursor was moved right. */ public boolean right(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 { diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java index e5b1422..c650cdc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java @@ -15,7 +15,8 @@ class SpaghettiStack<T> extends Stack<T> { /** * Create a new empty spaghetti stack, off of the specified parent. * - * @param par The parent stack + * @param par + * The parent stack */ public SpaghettiStack(Stack<T> par) { backing = new SimpleStack<>(); @@ -30,7 +31,7 @@ class SpaghettiStack<T> extends Stack<T> { @Override public T pop() { - if(backing.empty()) { + if (backing.empty()) { return parent.pop(); } @@ -39,7 +40,7 @@ class SpaghettiStack<T> extends Stack<T> { @Override public T top() { - if(backing.empty()) { + if (backing.empty()) { return parent.top(); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java index 1fc644e..21a922d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java @@ -9,14 +9,16 @@ import java.util.function.Consumer; * * A FILO stack with support for forth/factor style combinators. * - * @param T The datatype stored in the stack. + * @param T + * The datatype stored in the stack. * @author Ben Culkin */ public abstract class Stack<T> { /** * Push an element onto the stack. * - * @param elm The element to insert. + * @param elm + * The element to insert. */ public abstract void push(T elm); @@ -36,7 +38,8 @@ public abstract class Stack<T> { */ public abstract int size(); - /** Check if the stack is empty. + /** + * Check if the stack is empty. * * @return Whether or not the stack is empty. */ @@ -54,14 +57,15 @@ public abstract class Stack<T> { /* * Basic combinators */ - + /** * Drop n items from the stack. * - * @param n The number of items to drop. + * @param n + * The number of items to drop. */ public void drop(int n) { - for(int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { pop(); } } @@ -76,7 +80,8 @@ public abstract class Stack<T> { /** * Delete n items below the current one. * - * @param n The number of items below the top to delete. + * @param n + * The number of items below the top to delete. */ public void nip(int n) { T elm = pop(); @@ -96,18 +101,20 @@ public abstract class Stack<T> { /** * Replicate the top n items of the stack m times. * - * @param n The number of items to duplicate. - * @param m The number of times to duplicate items. + * @param n + * The number of items to duplicate. + * @param m + * The number of times to duplicate items. */ public void multidup(int n, int m) { List<T> 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(T elm : lst) { + + for (int i = 0; i < m; i++) { + for (T elm : lst) { push(elm); } } @@ -116,7 +123,8 @@ public abstract class Stack<T> { /** * Duplicate the top n items of the stack. * - * @param n The number of items to duplicate. + * @param n + * The number of items to duplicate. */ public void dup(int n) { multidup(n, 2); @@ -132,25 +140,27 @@ public abstract class Stack<T> { /** * Replicate the n elements below the top one m times. * - * @param n The number of items to duplicate. - * @param m The number of times to duplicate items. + * @param n + * The number of items to duplicate. + * @param m + * The number of times to duplicate items. */ public void multiover(int n, int m) { List<T> lst = new ArrayList<>(n); T elm = pop(); - for(int i = n; i > 0; i--) { + for (int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for(T nelm : lst) { + for (T nelm : lst) { push(nelm); } push(elm); - for(int i = 1; i < m; i++) { - for(T nelm : lst) { + for (int i = 1; i < m; i++) { + for (T nelm : lst) { push(nelm); } } @@ -159,7 +169,8 @@ public abstract class Stack<T> { /** * Duplicate the n elements below the top one. * - * @param n The number of items to duplicate. + * @param n + * The number of items to duplicate. */ public void over(int n) { multiover(n, 2); @@ -254,19 +265,21 @@ public abstract class Stack<T> { /** * Hides the top n elements on the stack from cons. * - * @param n The number of elements to hide. - * @param cons The action to hide the elements from + * @param n + * The number of elements to hide. + * @param cons + * The action to hide the elements from */ public void dip(int n, Consumer<Stack<T>> cons) { List<T> elms = new ArrayList<>(n); - for(int i = n; i > 0; i--) { + for (int i = n; i > 0; i--) { elms.set(i - 1, pop()); } cons.accept(this); - for(T elm : elms) { + for (T elm : elms) { push(elm); } } @@ -274,7 +287,8 @@ public abstract class Stack<T> { /** * Hide the top element of the stack from cons. * - * @param cons The action to hide the top from + * @param cons + * The action to hide the top from */ public void dip(Consumer<Stack<T>> cons) { dip(1, cons); @@ -284,8 +298,10 @@ public abstract class Stack<T> { * Copy the top n elements on the stack, replacing them once cons is * done. * - * @param n The number of elements to copy. - * @param cons The action to execute. + * @param n + * The number of elements to copy. + * @param cons + * The action to execute. */ public void keep(int n, Consumer<Stack<T>> cons) { dup(n); @@ -295,18 +311,20 @@ public abstract class Stack<T> { /** * Apply all the actions in conses to the top n elements of the stack. * - * @param n The number of elements to give to cons. - * @param conses The actions to execute. + * @param n + * The number of elements to give to cons. + * @param conses + * The actions to execute. */ public void multicleave(int n, List<Consumer<Stack<T>>> conses) { List<T> elms = new ArrayList<>(n); - for(int i = n; i > 0; i--) { + for (int i = n; i > 0; i--) { elms.set(i - 1, pop()); } - for(Consumer<Stack<T>> cons : conses) { - for(T elm : elms) { + for (Consumer<Stack<T>> cons : conses) { + for (T elm : elms) { push(elm); } @@ -317,7 +335,8 @@ public abstract class Stack<T> { /** * Apply all the actions in conses to the top element of the stack. * - * @param conses The actions to execute. + * @param conses + * The actions to execute. */ public void cleave(List<Consumer<Stack<T>>> conses) { multicleave(1, conses); @@ -326,16 +345,18 @@ public abstract class Stack<T> { /** * Apply every action in cons to n arguments. * - * @param n The number of parameters each action takes. - * @param conses The actions to execute. + * @param n + * The number of parameters each action takes. + * @param conses + * The actions to execute. */ public void multispread(int n, List<Consumer<Stack<T>>> conses) { List<List<T>> nelms = new ArrayList<>(conses.size()); - for(int i = conses.size(); i > 0; i--) { + for (int i = conses.size(); i > 0; i--) { List<T> elms = new ArrayList<>(n); - for(int j = n; j > 0; j--) { + for (int j = n; j > 0; j--) { elms.set(j, pop()); } @@ -343,8 +364,8 @@ public abstract class Stack<T> { } int i = 0; - for(List<T> elms : nelms) { - for(T elm : elms) { + for (List<T> elms : nelms) { + for (T elm : elms) { push(elm); } @@ -365,14 +386,17 @@ public abstract class Stack<T> { /** * Apply the action in cons to the first m groups of n arguments. * - * @param n The number of arguments cons takes. - * @param m The number of time to call cons. - * @param cons The action to execute. + * @param n + * The number of arguments cons takes. + * @param m + * The number of time to call cons. + * @param cons + * The action to execute. */ public void multiapply(int n, int m, Consumer<Stack<T>> cons) { List<Consumer<Stack<T>>> conses = new ArrayList<>(m); - for(int i = 0; i < m; i++) { + for (int i = 0; i < m; i++) { conses.add(cons); } @@ -382,8 +406,10 @@ public abstract class Stack<T> { /** * Apply cons n times to the corresponding elements in the stack. * - * @param n The number of times to execute cons. - * @param cons The action to execute. + * @param n + * The number of times to execute cons. + * @param cons + * The action to execute. */ public void apply(int n, Consumer<Stack<T>> cons) { multiapply(1, n, cons); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java index 425feb0..3d4e0b1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java @@ -3,11 +3,12 @@ package bjc.utils.esodata; /** * Interface for something that acts like a tape. * - * A tape is essentially a 1D array with a cursor attached to it, and you can only - * affect elements at that cursor. The size of the array is theoretically unbounded - * to the right, but in practice bounded by available memory. + * A tape is essentially a 1D array with a cursor attached to it, and you can + * only affect elements at that cursor. The size of the array is theoretically + * unbounded to the right, but in practice bounded by available memory. * - * @param T The element type of the tape. + * @param T + * The element type of the tape. * @author bjculkin */ public interface Tape<T> { @@ -21,7 +22,8 @@ public interface Tape<T> { /** * Set the item the tape is currently on. * - * @param itm The new value for the tape item. + * @param itm + * The new value for the tape item. */ void item(T itm); @@ -35,7 +37,8 @@ public interface Tape<T> { /** * Insert an element before the current item. * - * @param itm The item to add. + * @param itm + * The item to add. */ void insertBefore(T itm); @@ -47,8 +50,8 @@ public interface Tape<T> { /** * Remove the current element. * - * Also moves the cursor back one step if possible to maintain - * relative position. + * Also moves the cursor back one step if possible to maintain relative + * position. * * @return The removed item. */ @@ -76,11 +79,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. + * @param amt + * The amount to attempt to move the cursor left. * * @return True if the cursor was moved left. */ @@ -96,7 +99,8 @@ public interface Tape<T> { /** * Move the cursor the specified amount right. * - * @param amt The amount to move the cursor right by. + * @param amt + * The amount to move the cursor right by. * * @return Whether the cursor was moved right. */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java index 790e3fd..4030960 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -3,15 +3,18 @@ package bjc.utils.esodata; /** * A tape changer is essentially a tape of tapes. * - * It has a current tape that you can do operations to, but also operations to add/remove other tapes. + * It has a current tape that you can do operations to, but also operations to + * add/remove other tapes. * - * If there is no tape currently loaded into the changer, all the methods will either return null/false. + * If there is no tape currently loaded into the changer, all the methods will + * either return null/false. * - * @param T The element type of the tapes. + * @param T + * The element type of the tapes. */ public class TapeChanger<T> implements Tape<T> { private Tape<Tape<T>> tapes; - private Tape<T> currentTape; + private Tape<T> currentTape; /** * Create a new empty tape changer. @@ -25,7 +28,8 @@ public class TapeChanger<T> implements Tape<T> { * * The first tape in the list will be mounted. * - * @param taps The tapes to put in this tape changer. + * @param taps + * The tapes to put in this tape changer. */ @SafeVarargs public TapeChanger(Tape<T> current, Tape<T>... others) { @@ -33,7 +37,7 @@ public class TapeChanger<T> implements Tape<T> { tapes.insertBefore(current); - for(Tape<T> tp : others) { + for (Tape<T> tp : others) { tapes.insertAfter(tp); tapes.right(); } @@ -48,7 +52,8 @@ public class TapeChanger<T> implements Tape<T> { * @return The item the tape is on. */ public T item() { - if(currentTape == null) return null; + if (currentTape == null) + return null; return currentTape.item(); } @@ -56,10 +61,12 @@ public class TapeChanger<T> implements Tape<T> { /** * Set the item the tape is currently on. * - * @param itm The new value for the tape item. + * @param itm + * The new value for the tape item. */ public void item(T itm) { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.item(itm); } @@ -70,7 +77,8 @@ public class TapeChanger<T> implements Tape<T> { * @return The current number of elements in the tape. */ public int size() { - if(currentTape == null) return 0; + if (currentTape == null) + return 0; return currentTape.size(); } @@ -78,10 +86,12 @@ public class TapeChanger<T> implements Tape<T> { /** * Insert an element before the current item. * - * @param itm The item to add. + * @param itm + * The item to add. */ public void insertBefore(T itm) { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.insertBefore(itm); } @@ -90,7 +100,8 @@ public class TapeChanger<T> implements Tape<T> { * Insert an element after the current item. */ public void insertAfter(T itm) { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.insertAfter(itm); } @@ -98,13 +109,14 @@ public class TapeChanger<T> implements Tape<T> { /** * Remove the current element. * - * Also moves the cursor back one step if possible to maintain - * relative position, and removes the corresponding item from the non-active side + * Also moves the cursor back one step if possible to maintain relative + * position, and removes the corresponding item from the non-active side * * @return The removed item from the active side. */ public T remove() { - if(currentTape == null) return null; + if (currentTape == null) + return null; return currentTape.remove(); } @@ -113,7 +125,8 @@ public class TapeChanger<T> implements Tape<T> { * Move the cursor to the left-most position. */ public void first() { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.first(); } @@ -122,7 +135,8 @@ public class TapeChanger<T> implements Tape<T> { * Move the cursor the right-most position. */ public void last() { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.last(); } @@ -141,21 +155,21 @@ public class TapeChanger<T> implements 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. + * @param amt + * The amount to attempt to move the cursor left. * * @return True if the cursor was moved left. */ public boolean left(int amt) { - if(currentTape == null) return false; + if (currentTape == null) + return false; return currentTape.left(amt); } - /** * Move the cursor one space right. * @@ -172,12 +186,14 @@ public class TapeChanger<T> implements Tape<T> { * * Moving the cursor right will auto-extend the tape if that is enabled. * - * @param amt The amount to move the cursor right by. + * @param amt + * The amount to move the cursor right by. * * @return Whether the cursor was moved right. */ public boolean right(int amt) { - if(currentTape == null) return false; + if (currentTape == null) + return false; return currentTape.right(amt); } @@ -185,21 +201,24 @@ public class TapeChanger<T> implements Tape<T> { /** * Flips the tape. * - * The active side becomes inactive, and the inactive side becomes active. + * The active side becomes inactive, and the inactive side becomes + * active. * * If the current tape is not double-sided, does nothing. */ public void flip() { - if(currentTape == null) return; + if (currentTape == null) + return; - if(currentTape.isDoubleSided()) { - ((DoubleTape<T>)currentTape).flip(); + if (currentTape.isDoubleSided()) { + ((DoubleTape<T>) currentTape).flip(); } } @Override public boolean isDoubleSided() { - if(currentTape == null) return false; + if (currentTape == null) + return false; return currentTape.isDoubleSided(); } @@ -216,14 +235,16 @@ public class TapeChanger<T> implements Tape<T> { /** * Move to the next tape in the changer. * - * Attempting to load a tape that isn't there won't eject the current 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. */ public boolean nextTape() { boolean succ = tapes.right(); - if(succ) currentTape = tapes.item(); + if (succ) + currentTape = tapes.item(); return succ; } @@ -231,14 +252,16 @@ public class TapeChanger<T> implements Tape<T> { /** * Move to the previous tape in the changer. * - * Attempting to load a tape that isn't there won't eject the current 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. */ public boolean prevTape() { boolean succ = tapes.left(); - if(succ) currentTape = tapes.item(); + if (succ) + currentTape = tapes.item(); return succ; } @@ -250,12 +273,13 @@ public class TapeChanger<T> implements Tape<T> { * * The specified tape is loaded. * - * @param The tape to insert and load. + * @param The + * tape to insert and load. */ public void insertTape(Tape<T> tp) { tapes.insertAfter(tp); tapes.right(); - + currentTape = tapes.item(); } @@ -269,7 +293,8 @@ public class TapeChanger<T> implements Tape<T> { * @return The removed tape. */ public Tape<T> removeTape() { - if(currentTape == null) return null; + if (currentTape == null) + return null; Tape<T> tp = tapes.remove(); currentTape = tapes.item(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java index 711c15e..3a49175 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java @@ -6,15 +6,18 @@ import java.util.Map; /** * A tape changer is essentially a map of tapes. * - * It has a current tape that you can do operations to, but also operations to add/remove other tapes. + * It has a current tape that you can do operations to, but also operations to + * add/remove other tapes. * - * If there is no tape currently loaded into the changer, all the methods will either return null/false. + * If there is no tape currently loaded into the changer, all the methods will + * either return null/false. * - * @param T The element type of the tapes. + * @param T + * The element type of the tapes. */ public class TapeLibrary<T> implements Tape<T> { private Map<String, Tape<T>> tapes; - private Tape<T> currentTape; + private Tape<T> currentTape; /** * Create a new empty tape library. @@ -29,7 +32,8 @@ public class TapeLibrary<T> implements Tape<T> { * @return The item the tape is on. */ public T item() { - if(currentTape == null) return null; + if (currentTape == null) + return null; return currentTape.item(); } @@ -37,10 +41,12 @@ public class TapeLibrary<T> implements Tape<T> { /** * Set the item the tape is currently on. * - * @param itm The new value for the tape item. + * @param itm + * The new value for the tape item. */ public void item(T itm) { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.item(itm); } @@ -51,7 +57,8 @@ public class TapeLibrary<T> implements Tape<T> { * @return The current number of elements in the tape. */ public int size() { - if(currentTape == null) return 0; + if (currentTape == null) + return 0; return currentTape.size(); } @@ -59,10 +66,12 @@ public class TapeLibrary<T> implements Tape<T> { /** * Insert an element before the current item. * - * @param itm The item to add. + * @param itm + * The item to add. */ public void insertBefore(T itm) { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.insertBefore(itm); } @@ -71,7 +80,8 @@ public class TapeLibrary<T> implements Tape<T> { * Insert an element after the current item. */ public void insertAfter(T itm) { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.insertAfter(itm); } @@ -79,13 +89,14 @@ public class TapeLibrary<T> implements Tape<T> { /** * Remove the current element. * - * Also moves the cursor back one step if possible to maintain - * relative position, and removes the corresponding item from the non-active side + * Also moves the cursor back one step if possible to maintain relative + * position, and removes the corresponding item from the non-active side * * @return The removed item from the active side. */ public T remove() { - if(currentTape == null) return null; + if (currentTape == null) + return null; return currentTape.remove(); } @@ -94,7 +105,8 @@ public class TapeLibrary<T> implements Tape<T> { * Move the cursor to the left-most position. */ public void first() { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.first(); } @@ -103,7 +115,8 @@ public class TapeLibrary<T> implements Tape<T> { * Move the cursor the right-most position. */ public void last() { - if(currentTape == null) return; + if (currentTape == null) + return; currentTape.last(); } @@ -122,21 +135,21 @@ public class TapeLibrary<T> implements 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. + * @param amt + * The amount to attempt to move the cursor left. * * @return True if the cursor was moved left. */ public boolean left(int amt) { - if(currentTape == null) return false; + if (currentTape == null) + return false; return currentTape.left(amt); } - /** * Move the cursor one space right. * @@ -153,12 +166,14 @@ public class TapeLibrary<T> implements Tape<T> { * * Moving the cursor right will auto-extend the tape if that is enabled. * - * @param amt The amount to move the cursor right by. + * @param amt + * The amount to move the cursor right by. * * @return Whether the cursor was moved right. */ public boolean right(int amt) { - if(currentTape == null) return false; + if (currentTape == null) + return false; return currentTape.right(amt); } @@ -166,21 +181,24 @@ public class TapeLibrary<T> implements Tape<T> { /** * Flips the tape. * - * The active side becomes inactive, and the inactive side becomes active. + * The active side becomes inactive, and the inactive side becomes + * active. * * If the current tape is not double-sided, does nothing. */ public void flip() { - if(currentTape == null) return; + if (currentTape == null) + return; - if(currentTape.isDoubleSided()) { - ((DoubleTape<T>)currentTape).flip(); + if (currentTape.isDoubleSided()) { + ((DoubleTape<T>) currentTape).flip(); } } @Override public boolean isDoubleSided() { - if(currentTape == null) return false; + if (currentTape == null) + return false; return currentTape.isDoubleSided(); } @@ -197,14 +215,16 @@ public class TapeLibrary<T> implements Tape<T> { /** * Move to the specified tape in the library. * - * Attempting to load a tape that isn't there won't eject the current tape. + * Attempting to load a tape that isn't there won't eject the current + * tape. * - * @param label The label of the tape to load. + * @param label + * The label of the tape to load. * * @return Whether or not the next tape was loaded. */ public boolean switchTape(String label) { - if(tapes.containsKey(label)) { + if (tapes.containsKey(label)) { currentTape = tapes.get(label); return true; } @@ -221,7 +241,8 @@ public class TapeLibrary<T> implements Tape<T> { * * Adding a duplicate tape will overwrite any existing types. * - * @param The tape to insert and load. + * @param The + * tape to insert and load. */ public void insertTape(String label, Tape<T> tp) { tapes.put(label, tp); @@ -234,7 +255,8 @@ public class TapeLibrary<T> implements Tape<T> { * * Does nothing if there is not a tape of that name loaded. * - * @param label The tape to remove. + * @param label + * The tape to remove. * * @return The removed tape. */ @@ -263,7 +285,8 @@ public class TapeLibrary<T> implements Tape<T> { /** * Check if a specific tape is loaded into the library. * - * @param label The tape to check for. + * @param label + * The tape to check for. * * @return Whether or not a tape of that name exists */ |
