From cb7671a1e5d171cc4002b07d832a5fd8afcc107e Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Thu, 14 Sep 2017 16:14:11 -0300 Subject: Add position access to tapes --- .../src/main/java/bjc/utils/esodata/DoubleTape.java | 5 +++++ .../src/main/java/bjc/utils/esodata/SingleTape.java | 18 ++++++++++++++++++ BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java | 7 +++++++ .../src/main/java/bjc/utils/esodata/TapeChanger.java | 7 +++++++ .../src/main/java/bjc/utils/esodata/TapeLibrary.java | 6 ++++++ 5 files changed, 43 insertions(+) (limited to 'BJC-Utils2') 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 0faaabf..5c463c6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java @@ -78,6 +78,11 @@ public class DoubleTape implements Tape { return front.size(); } + @Override + public int position() { + return front.position(); + } + /** * Insert an element before the current item. * 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 a3e5462..c50be92 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java @@ -25,6 +25,19 @@ public class SingleTape implements Tape { protected boolean autoExtend; + /** + * Create a new tape with the specified contents that doesn't + * autoextend. + */ + public SingleTape(T... vals) { + autoExtend = false; + + backing = new ArrayList(vals.length); + + for(T val : vals) { + backing.add(val); + } + } /** * Create a new empty tape that doesn't autoextend. */ @@ -77,6 +90,11 @@ public class SingleTape implements Tape { return backing.size(); } + @Override + public int position() { + return pos; + } + /** * Insert an element before the current item. * 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 5f4c3a5..b6a2c01 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java @@ -35,6 +35,13 @@ public interface Tape { */ int size(); + /** + * Get the position of the current item. + * + * @return The position of the current item. + */ + int position(); + /** * Insert an element before the current item. * 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 8b8613f..dc885bc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -83,6 +83,13 @@ public class TapeChanger implements Tape { return currentTape.size(); } + @Override + public int position() { + if (currentTape == null) return 0; + + return currentTape.position(); + } + /** * Insert an element before the current 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 4a5add6..2dbc70b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java @@ -63,6 +63,12 @@ public class TapeLibrary implements Tape { return currentTape.size(); } + @Override + public int position() { + if (currentTape == null) return 0; + + return currentTape.position(); + } /** * Insert an element before the current item. * -- cgit v1.2.3