diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java | 64 |
1 files changed, 38 insertions, 26 deletions
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 { |
