From 9052ed6da37af23ea82588d248f409e60a33c6cb Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sun, 12 Apr 2020 13:13:42 -0400 Subject: Finish up extraction This applies the changes that were necessary to complete the extraction of these packages from bjc-utils --- src/main/java/bjc/esodata/SingleTape.java | 5 +++++ src/main/java/bjc/esodata/Tape.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'src/main/java/bjc/esodata') diff --git a/src/main/java/bjc/esodata/SingleTape.java b/src/main/java/bjc/esodata/SingleTape.java index 28dca2a..c2957a6 100644 --- a/src/main/java/bjc/esodata/SingleTape.java +++ b/src/main/java/bjc/esodata/SingleTape.java @@ -180,6 +180,11 @@ public class SingleTape implements Tape { return true; } + @Override + public void append(T itm) { + backing.add(itm); + } + @Override public int hashCode() { final int prime = 31; diff --git a/src/main/java/bjc/esodata/Tape.java b/src/main/java/bjc/esodata/Tape.java index 080e216..7d5fd9a 100644 --- a/src/main/java/bjc/esodata/Tape.java +++ b/src/main/java/bjc/esodata/Tape.java @@ -132,4 +132,20 @@ public interface Tape { default boolean atEnd() { return position() == size(); } + + /** + * Append an item to the tape. + * + * By default, uses a fairly non-performant implementation. Should be overidden in subclasses to be more performant. + * @param itm The item to append. + */ + default void append(T itm) { + int pos = position(); + + last(); + + insertAfter(itm); + + seekTo(pos); + } } -- cgit v1.2.3