summaryrefslogtreecommitdiff
path: root/base/src/main
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-04-07 21:03:53 -0400
committerBen Culkin <scorpress@gmail.com>2020-04-07 21:03:53 -0400
commit002516bd03b2ea3f731c8139c9a5f716902ab702 (patch)
tree4b45260e0b411dd070ae5d2f45e8f2795bf91b79 /base/src/main
parentd6afd99961aacd6ce915629773723cb6c6e145a7 (diff)
Finish remove utils.data
utils.data now lives in the esodata project; not in this one
Diffstat (limited to 'base/src/main')
-rw-r--r--base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java2
-rw-r--r--base/src/main/java/bjc/utils/components/FileComponentRepository.java4
-rw-r--r--base/src/main/java/bjc/utils/data/ArrayIterator.java39
-rw-r--r--base/src/main/java/bjc/utils/data/BooleanToggle.java77
-rw-r--r--base/src/main/java/bjc/utils/data/CircularIterator.java79
-rw-r--r--base/src/main/java/bjc/utils/data/Either.java191
-rw-r--r--base/src/main/java/bjc/utils/data/GeneratingIterator.java60
-rw-r--r--base/src/main/java/bjc/utils/data/IHolder.java163
-rw-r--r--base/src/main/java/bjc/utils/data/IPair.java241
-rw-r--r--base/src/main/java/bjc/utils/data/ITree.java278
-rw-r--r--base/src/main/java/bjc/utils/data/Identity.java112
-rw-r--r--base/src/main/java/bjc/utils/data/Lazy.java201
-rw-r--r--base/src/main/java/bjc/utils/data/LazyPair.java249
-rw-r--r--base/src/main/java/bjc/utils/data/ListHolder.java105
-rw-r--r--base/src/main/java/bjc/utils/data/OneWayToggle.java53
-rw-r--r--base/src/main/java/bjc/utils/data/Option.java93
-rw-r--r--base/src/main/java/bjc/utils/data/Pair.java142
-rw-r--r--base/src/main/java/bjc/utils/data/QueuedIterator.java229
-rw-r--r--base/src/main/java/bjc/utils/data/SingleIterator.java42
-rw-r--r--base/src/main/java/bjc/utils/data/SingleSupplier.java76
-rw-r--r--base/src/main/java/bjc/utils/data/Toggle.java34
-rw-r--r--base/src/main/java/bjc/utils/data/TopDownTransformIterator.java272
-rw-r--r--base/src/main/java/bjc/utils/data/TopDownTransformResult.java22
-rw-r--r--base/src/main/java/bjc/utils/data/TransformIterator.java46
-rw-r--r--base/src/main/java/bjc/utils/data/Tree.java432
-rw-r--r--base/src/main/java/bjc/utils/data/ValueToggle.java60
-rw-r--r--base/src/main/java/bjc/utils/data/internals/BoundLazy.java137
-rw-r--r--base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java228
-rw-r--r--base/src/main/java/bjc/utils/data/internals/BoundListHolder.java81
-rw-r--r--base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java177
-rw-r--r--base/src/main/java/bjc/utils/data/internals/WrappedLazy.java83
-rw-r--r--base/src/main/java/bjc/utils/data/internals/WrappedOption.java96
-rw-r--r--base/src/main/java/bjc/utils/funcdata/FunctionalList.java8
-rw-r--r--base/src/main/java/bjc/utils/funcdata/FunctionalMap.java2
-rw-r--r--base/src/main/java/bjc/utils/funcdata/IList.java2
-rw-r--r--base/src/main/java/bjc/utils/funcutils/CollectorUtils.java4
-rw-r--r--base/src/main/java/bjc/utils/funcutils/CompoundCollector.java8
-rw-r--r--base/src/main/java/bjc/utils/funcutils/IteratorUtils.java2
-rw-r--r--base/src/main/java/bjc/utils/funcutils/StringUtils.java2
-rw-r--r--base/src/main/java/bjc/utils/funcutils/TreeUtils.java2
-rw-r--r--base/src/main/java/bjc/utils/gen/WeightedGrammar.java4
-rw-r--r--base/src/main/java/bjc/utils/gen/WeightedRandom.java4
-rw-r--r--base/src/main/java/bjc/utils/graph/AdjacencyMap.java4
-rw-r--r--base/src/main/java/bjc/utils/graph/Graph.java4
-rw-r--r--base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java2
-rw-r--r--base/src/main/java/bjc/utils/ioutils/RegexStringEditor.java4
-rw-r--r--base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java8
-rw-r--r--base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java2
-rw-r--r--base/src/main/java/bjc/utils/parserutils/TokenTransformer.java8
-rw-r--r--base/src/main/java/bjc/utils/parserutils/TreeConstructor.java10
-rw-r--r--base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java2
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java8
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java4
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java6
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java2
55 files changed, 54 insertions, 4152 deletions
diff --git a/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java b/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java
index 8ddad15..0dbd2a4 100644
--- a/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java
+++ b/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java
@@ -10,7 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.Scanner;
-import bjc.utils.data.ITree;
+import bjc.data.ITree;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
import bjc.utils.funcutils.StringUtils;
diff --git a/base/src/main/java/bjc/utils/components/FileComponentRepository.java b/base/src/main/java/bjc/utils/components/FileComponentRepository.java
index cbf5aa9..0ca2b5e 100644
--- a/base/src/main/java/bjc/utils/components/FileComponentRepository.java
+++ b/base/src/main/java/bjc/utils/components/FileComponentRepository.java
@@ -9,8 +9,8 @@ import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Identity;
+import bjc.data.IHolder;
+import bjc.data.Identity;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IList;
import bjc.utils.funcdata.IMap;
diff --git a/base/src/main/java/bjc/utils/data/ArrayIterator.java b/base/src/main/java/bjc/utils/data/ArrayIterator.java
deleted file mode 100644
index 1592901..0000000
--- a/base/src/main/java/bjc/utils/data/ArrayIterator.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package bjc.utils.data;
-
-import java.util.Iterator;
-/**
- * Represents an iterator over an array of values.
- *
- * @param <T> The type of values in the array.
- *
- * @author Ben Culkin
- */
-public class ArrayIterator<T> implements Iterator<T> {
- private Object[] arr;
- private int idx;
-
- /**
- * Create a new array iterator.
- *
- * @param elms
- * The array that will be iterated over.
- */
- @SafeVarargs
- public ArrayIterator(T... elms) {
- arr = elms;
- idx = 0;
- }
-
- @Override
- public boolean hasNext() {
- return idx < arr.length;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T next() {
- if (idx >= arr.length) return null;
-
- return (T)(arr[idx++]);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/BooleanToggle.java b/base/src/main/java/bjc/utils/data/BooleanToggle.java
deleted file mode 100644
index 542d2b6..0000000
--- a/base/src/main/java/bjc/utils/data/BooleanToggle.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package bjc.utils.data;
-
-/**
- * A simple {@link ValueToggle} that swaps between true and false.
- *
- * @author EVE
- *
- */
-public class BooleanToggle implements Toggle<Boolean> {
- /* The contained value. */
- private boolean val;
-
- /**
- * Create a new, initially false, flip-flop.
- */
- public BooleanToggle() {
- this(false);
- }
-
- /**
- * Create a flip-flop with the specified initial value.
- *
- * @param initial
- * The initial value of the flip-flop.
- */
- public BooleanToggle(final boolean initial) {
- val = initial;
- }
-
- @Override
- public Boolean get() {
- final boolean res = val;
-
- val = !res;
-
- return res;
- }
-
- @Override
- public Boolean peek() {
- return val;
- }
-
- @Override
- public void set(final boolean vl) {
- val = vl;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
-
- int result = 1;
-
- result = prime * result + (val ? 1231 : 1237);
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof BooleanToggle)) return false;
-
- final BooleanToggle other = (BooleanToggle) obj;
-
- if(val != other.val) return false;
-
- return true;
- }
-
- @Override
- public String toString() {
- return String.format("BooleanToggle [val=%s]", val);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/CircularIterator.java b/base/src/main/java/bjc/utils/data/CircularIterator.java
deleted file mode 100644
index 9af4d87..0000000
--- a/base/src/main/java/bjc/utils/data/CircularIterator.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package bjc.utils.data;
-
-import java.util.Iterator;
-
-/**
- * An iterator that repeats elements from a provided iterable.
- *
- * @author EVE
- *
- * @param <E>
- * The type of the iterable.
- */
-public class CircularIterator<E> implements Iterator<E> {
- /* The iterable, and our current iterator into it. */
- private Iterable<E> source;
- private Iterator<E> curr;
-
- /* Our current element. */
- private E curElm;
-
- /*
- * Should we actually get new iterators, or just repeat the last
- * element?
- */
- private boolean doCircle;
-
- /**
- * Create a new circular iterator.
- *
- * @param src
- * The iterable to iterate from.
- *
- * @param circ
- * Should we actually do circular iteration, or just
- * repeat the terminal element?
- */
- public CircularIterator(final Iterable<E> src, final boolean circ) {
- source = src;
- curr = source.iterator();
-
- doCircle = circ;
- }
-
- /**
- * Create a new circular iterator that does actual circular iteration.
- *
- * @param src
- * The iterable to iterate from.
- */
- public CircularIterator(final Iterable<E> src) {
- this(src, true);
- }
-
- @Override
- public boolean hasNext() {
- /* We always have something. */
- return true;
- }
-
- @Override
- public E next() {
- if (!curr.hasNext()) {
- if (!doCircle) {
- return curElm;
- }
-
- curr = source.iterator();
- }
-
- curElm = curr.next();
-
- return curElm;
- }
-
- @Override
- public void remove() {
- curr.remove();
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/Either.java b/base/src/main/java/bjc/utils/data/Either.java
deleted file mode 100644
index 6023b60..0000000
--- a/base/src/main/java/bjc/utils/data/Either.java
+++ /dev/null
@@ -1,191 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-
-/**
- * Represents a pair where only one side has a value.
- *
- * @author ben
- *
- * @param <LeftType>
- * The type that could be on the left.
- *
- * @param <RightType>
- * The type that could be on the right.
- *
- */
-public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
- /**
- * Create a new either with the left value occupied.
- *
- * @param <LeftType>
- * The type of the left value.
- *
- * @param <RightType>
- * The type of the empty right value.
- *
- * @param left
- * The value to put on the left.
- *
- * @return An either with the left side occupied.
- */
- public static <LeftType, RightType> Either<LeftType, RightType> left(final LeftType left) {
- return new Either<>(left, null);
- }
-
- /**
- * Create a new either with the right value occupied.
- *
- * @param <LeftType>
- * The type of the empty left value.
- *
- * @param <RightType>
- * The type of the right value.
- *
- * @param right
- * The value to put on the right.
- *
- * @return An either with the right side occupied.
- */
- public static <LeftType, RightType> Either<LeftType, RightType> right(final RightType right) {
- return new Either<>(null, right);
- }
-
- /* The left value of the either. */
- private LeftType leftVal;
- /* The right value of the either. */
- private RightType rightVal;
- /* Whether the left value is the one filled out. */
- private boolean isLeft;
-
- /* Create a new either with specifed values. */
- private Either(final LeftType left, final RightType right) {
- if(left == null) {
- rightVal = right;
- } else {
- leftVal = left;
-
- isLeft = true;
- }
- }
-
- @Override
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- if(binder == null) throw new NullPointerException("Binder must not be null");
-
- return binder.apply(leftVal, rightVal);
- }
-
- @Override
- public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
- final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if(leftBinder == null) throw new NullPointerException("Left binder must not be null");
-
- if(isLeft) return leftBinder.apply(leftVal);
-
- return new Either<>(null, rightVal);
- }
-
- @Override
- public <BoundRight> IPair<LeftType, BoundRight> bindRight(
- final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if(rightBinder == null) throw new NullPointerException("Right binder must not be null");
-
- if(isLeft) return new Either<>(leftVal, null);
-
- return rightBinder.apply(rightVal);
- }
-
- @Override
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- final IPair<OtherLeft, OtherRight> otherPair,
- final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
- if(otherPair == null) {
- throw new NullPointerException("Other pair must not be null");
- } else if(leftCombiner == null) {
- throw new NullPointerException("Left combiner must not be null");
- } else if(rightCombiner == null) {
- throw new NullPointerException("Right combiner must not be null");
- }
-
- if(isLeft) {
- return otherPair.bind((otherLeft, otherRight) -> {
- CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft);
-
- return new Either<>(cLeft, null);
- });
- }
-
- return otherPair.bind((otherLeft, otherRight) -> {
- CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
-
- return new Either<>(null, cRight);
- });
- }
-
- @Override
- public <NewLeft> IPair<NewLeft, RightType> mapLeft(final Function<LeftType, NewLeft> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- if(isLeft) return new Either<>(mapper.apply(leftVal), null);
-
- return new Either<>(null, rightVal);
- }
-
- @Override
- public <NewRight> IPair<LeftType, NewRight> mapRight(final Function<RightType, NewRight> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- if(isLeft) return new Either<>(leftVal, null);
-
- return new Either<>(null, mapper.apply(rightVal));
- }
-
- @Override
- public <MergedType> MergedType merge(final BiFunction<LeftType, RightType, MergedType> merger) {
- if(merger == null) throw new NullPointerException("Merger must not be null");
-
- return merger.apply(leftVal, rightVal);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
-
- int result = 1;
- result = prime * result + (isLeft ? 1231 : 1237);
- result = prime * result + (leftVal == null ? 0 : leftVal.hashCode());
- result = prime * result + (rightVal == null ? 0 : rightVal.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof Either<?, ?>)) return false;
-
- final Either<?, ?> other = (Either<?, ?>) obj;
-
- if(isLeft != other.isLeft) return false;
-
- if(leftVal == null) {
- if(other.leftVal != null) return false;
- } else if(!leftVal.equals(other.leftVal)) return false;
-
- if(rightVal == null) {
- if(other.rightVal != null) return false;
- } else if(!rightVal.equals(other.rightVal)) return false;
-
- return true;
- }
-
- @Override
- public String toString() {
- return String.format("Either [leftVal='%s', rightVal='%s', isLeft=%s]", leftVal, rightVal, isLeft);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/GeneratingIterator.java b/base/src/main/java/bjc/utils/data/GeneratingIterator.java
deleted file mode 100644
index 25d2d3d..0000000
--- a/base/src/main/java/bjc/utils/data/GeneratingIterator.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package bjc.utils.data;
-
-import java.util.Iterator;
-import java.util.function.Predicate;
-import java.util.function.UnaryOperator;
-
-/**
- * An iterator that generates a series of elements from a single element.
- *
- * @author bjculkin
- *
- * @param <E>
- * The type of element generated.
- */
-public class GeneratingIterator<E> implements Iterator<E> {
- /* Our current state. */
- private E state;
- /* The function to use to transition states. */
- private UnaryOperator<E> transtion;
- /* The predicate to indicate where to stop. */
- private Predicate<E> stpper;
-
- /**
- * Create a new generative iterator.
- *
- * @param initial
- * The initial state of the generator.
- *
- * @param transition
- * The function to apply to the state.
- *
- * @param stopper
- * The predicate applied to the current state to determine when
- * to stop.
- */
- public GeneratingIterator(E initial, UnaryOperator<E> transition, Predicate<E> stopper) {
- state = initial;
- transtion = transition;
- stpper = stopper;
- }
-
- @Override
- public boolean hasNext() {
- return stpper.test(state);
- }
-
- /*
- * @NOTE
- *
- * As this currently is, it only works correctly assuming that next() is
- * only called when hasNext() is true. Should we safeguard against
- * people who are not doing the right thing?
- */
- @Override
- public E next() {
- state = transtion.apply(state);
-
- return state;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/IHolder.java b/base/src/main/java/bjc/utils/data/IHolder.java
deleted file mode 100644
index 4d2ed2c..0000000
--- a/base/src/main/java/bjc/utils/data/IHolder.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.internals.BoundListHolder;
-import bjc.utils.data.internals.WrappedLazy;
-import bjc.utils.data.internals.WrappedOption;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.theory.Functor;
-
-/**
- * A holder of a single value.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type of value held.
- */
-public interface IHolder<ContainedType> extends Functor<ContainedType> {
- /**
- * Bind a function across the value in this container.
- *
- * @param <BoundType>
- * The type of value in this container.
- *
- * @param binder
- * The function to bind to the value.
- *
- * @return A holder from binding the value.
- */
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder);
-
- /**
- * Apply an action to the value.
- *
- * @param action
- * The action to apply to the value.
- */
- public default void doWith(final Consumer<? super ContainedType> action) {
- transform(value -> {
- action.accept(value);
-
- return value;
- });
- }
-
- @Override
- default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap(
- final Function<ArgType, ReturnType> func) {
- return argumentFunctor -> {
- if(!(argumentFunctor instanceof IHolder<?>)) {
- final String msg = "This functor only supports mapping over instances of IHolder";
-
- throw new IllegalArgumentException(msg);
- }
-
- final IHolder<ArgType> holder = (IHolder<ArgType>) argumentFunctor;
-
- return holder.map(func);
- };
- }
-
- @Override
- public default ContainedType getValue() {
- return unwrap(value -> value);
- }
-
- /**
- * Lifts a function to bind over this holder.
- *
- * @param <NewType>
- * The type of the functions return.
- *
- * @param func
- * The function to lift over the holder.
- *
- * @return The function lifted over the holder.
- */
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func);
-
- /**
- * Make this holder lazy.
- *
- * @return A lazy version of this holder.
- */
- public default IHolder<ContainedType> makeLazy() {
- return new WrappedLazy<>(this);
- }
-
- /**
- * Make this holder a list.
- *
- * @return A list version of this holder.
- */
- public default IHolder<ContainedType> makeList() {
- return new BoundListHolder<>(new FunctionalList<>(this));
- }
-
- /**
- * Make this holder optional.
- *
- * @return An optional version of this holder.
- */
- public default IHolder<ContainedType> makeOptional() {
- return new WrappedOption<>(this);
- }
-
- /**
- * Create a new holder with a mapped version of the value in this
- * holder.
- *
- * Does not change the internal state of this holder.
- *
- * @param <MappedType>
- * The type of the mapped value.
- *
- * @param mapper
- * The function to do mapping with.
- *
- * @return A holder with the mapped value
- */
- public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper);
-
- /**
- * Replace the held value with a new one.
- *
- * @param newValue
- * The value to hold instead.
- *
- * @return The holder itself.
- */
- public default IHolder<ContainedType> replace(final ContainedType newValue) {
- return transform(oldValue -> {
- return newValue;
- });
- }
-
- /**
- * Transform the value held in this holder.
- *
- * @param transformer
- * The function to transform the value with.
- *
- * @return The holder itself, for easy chaining.
- */
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer);
-
- /**
- * Unwrap the value contained in this holder so that it is no longer
- * held.
- *
- * @param <UnwrappedType>
- * The type of the unwrapped value.
- *
- * @param unwrapper
- * The function to use to unwrap the value.
- *
- * @return The unwrapped held value.
- */
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper);
-}
diff --git a/base/src/main/java/bjc/utils/data/IPair.java b/base/src/main/java/bjc/utils/data/IPair.java
deleted file mode 100644
index 886bf7c..0000000
--- a/base/src/main/java/bjc/utils/data/IPair.java
+++ /dev/null
@@ -1,241 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-
-import bjc.utils.funcdata.theory.Bifunctor;
-
-/**
- * Represents a pair of values.
- *
- * @author ben
- *
- * @param <LeftType>
- * The type of the left side of the pair.
- *
- * @param <RightType>
- * The type of the right side of the pair.
- *
- */
-public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightType> {
- /**
- * Bind a function across the values in this pair.
- *
- * @param <BoundLeft>
- * The type of the bound left.
- *
- * @param <BoundRight>
- * The type of the bound right.
- *
- * @param binder
- * The function to bind with.
- *
- * @return The bound pair.
- */
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder);
-
- /**
- * Bind a function to the left value in this pair.
- *
- * @param <BoundLeft>
- * The type of the bound value.
- *
- * @param leftBinder
- * The function to use to bind.
- *
- * @return A pair with the left type bound.
- */
- public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
- Function<LeftType, IPair<BoundLeft, RightType>> leftBinder);
-
- /**
- * Bind a function to the right value in this pair.
- *
- * @param <BoundRight>
- * The type of the bound value.
- *
- * @param rightBinder
- * The function to use to bind.
- *
- * @return A pair with the right type bound.
- */
- public <BoundRight> IPair<LeftType, BoundRight> bindRight(
- Function<RightType, IPair<LeftType, BoundRight>> rightBinder);
-
- /**
- * Pairwise combine two pairs together.
- *
- * @param <OtherLeft>
- * The left type of the other pair.
- *
- * @param <OtherRight>
- * The right type of the other pair.
- *
- * @param otherPair
- * The pair to combine with.
- *
- * @return The pairs, pairwise combined together.
- */
- public default <OtherLeft, OtherRight> IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> combine(
- final IPair<OtherLeft, OtherRight> otherPair) {
- return combine(otherPair, Pair<LeftType, OtherLeft>::new, Pair<RightType, OtherRight>::new);
- }
-
- /**
- * Combine the contents of two pairs together.
- *
- * @param <OtherLeft>
- * The type of the left value of the other pair.
- *
- * @param <OtherRight>
- * The type of the right value of the other pair.
- *
- * @param <CombinedLeft>
- * The type of the left value of the combined pair.
- *
- * @param <CombinedRight>
- * The type of the right value of the combined pair.
- *
- * @param otherPair
- * The other pair to combine with.
- *
- * @param leftCombiner
- * The function to combine the left values with.
- *
- * @param rightCombiner
- * The function to combine the right values with.
- *
- * @return A pair with its values combined.
- */
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<RightType, OtherRight, CombinedRight> rightCombiner);
-
- /**
- * Immediately perfom the specified action with the contents of this
- * pair.
- *
- * @param consumer
- * The action to perform on the pair.
- */
- public default void doWith(final BiConsumer<LeftType, RightType> consumer) {
- merge((leftValue, rightValue) -> {
- consumer.accept(leftValue, rightValue);
-
- return null;
- });
- }
-
- @Override
- default <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> fmapLeft(
- final Function<OldLeft, NewLeft> func) {
- return argumentPair -> {
- if (!(argumentPair instanceof IPair<?, ?>)) {
- final String msg = "This function can only be applied to instances of IPair";
-
- throw new IllegalArgumentException(msg);
- }
-
- final IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
-
- return argPair.mapLeft(func);
- };
- }
-
- @Override
- default <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight> fmapRight(
- final Function<OldRight, NewRight> func) {
- return argumentPair -> {
- if (!(argumentPair instanceof IPair<?, ?>)) {
- final String msg = "This function can only be applied to instances of IPair";
-
- throw new IllegalArgumentException(msg);
- }
-
- final IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
-
- return argPair.mapRight(func);
- };
- }
-
- /**
- * Get the value on the left side of the pair.
- *
- * @return The value on the left side of the pair.
- */
- @Override
- public default LeftType getLeft() {
- return merge((leftValue, rightValue) -> leftValue);
- }
-
- /**
- * Get the value on the right side of the pair.
- *
- * @return The value on the right side of the pair.
- */
- @Override
- public default RightType getRight() {
- return merge((leftValue, rightValue) -> rightValue);
- }
-
- /**
- * Transform the value on the left side of the pair.
- *
- * Doesn't modify the pair.
- *
- * @param <NewLeft>
- * The new type of the left part of the pair.
- *
- * @param mapper
- * The function to use to transform the left part of the
- * pair.
- *
- * @return The pair, with its left part transformed.
- */
- public <NewLeft> IPair<NewLeft, RightType> mapLeft(Function<LeftType, NewLeft> mapper);
-
- /**
- * Transform the value on the right side of the pair.
- *
- * Doesn't modify the pair.
- *
- * @param <NewRight>
- * The new type of the right part of the pair.
- *
- * @param mapper
- * The function to use to transform the right part of the
- * pair.
- *
- * @return The pair, with its right part transformed.
- */
- public <NewRight> IPair<LeftType, NewRight> mapRight(Function<RightType, NewRight> mapper);
-
- /**
- * Merge the two values in this pair into a single value.
- *
- * @param <MergedType>
- * The type of the single value.
- *
- * @param merger
- * The function to use for merging.
- *
- * @return The pair, merged into a single value.
- */
- public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger);
-
- /**
- * Static pair constructor.
- *
- * @param left
- * The left side of the pair.
- * @param right
- * The right side of the pair.
- * @return A pair, with the specified left/right side.
- */
- public static <T1, T2> IPair<T1, T2> pair(T1 left, T2 right) {
- return new Pair<>(left, right);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/ITree.java b/base/src/main/java/bjc/utils/data/ITree.java
deleted file mode 100644
index 8ccf50e..0000000
--- a/base/src/main/java/bjc/utils/data/ITree.java
+++ /dev/null
@@ -1,278 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.funcdata.IList;
-import bjc.utils.funcdata.bst.TreeLinearizationMethod;
-
-/**
- * A node in a homogeneous tree with a unlimited amount of children.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type of data contained in the tree nodes.
- *
- */
-public interface ITree<ContainedType> {
- /**
- * Append a child to this node.
- *
- * @param child
- * The child to append to this node.
- */
- void addChild(ITree<ContainedType> child);
-
- /**
- * Append a child to this node.
- *
- * @param child
- * The child to append to this node.
- */
- void addChild(ContainedType child);
-
- /**
- * Prepend a child to this node.
- *
- * @param child
- * The child to prepend to this node.
- */
- void prependChild(ITree<ContainedType> child);
-
- /**
- * Collapse a tree into a single version.
- *
- * @param <NewType>
- * The intermediate type being folded.
- *
- * @param <ReturnedType>
- * The type that is the end result.
- *
- * @param leafTransform
- * The function to use to convert leaf values.
- *
- * @param nodeCollapser
- * The function to use to convert internal nodes and their
- * children.
- *
- * @param resultTransformer
- * The function to use to convert a state to the returned
- * version.
- *
- * @return The final transformed state.
- */
- <NewType, ReturnedType> ReturnedType collapse(Function<ContainedType, NewType> leafTransform,
- BiFunction<ContainedType, IList<NewType>, NewType> nodeCollapser,
- Function<NewType, ReturnedType> resultTransformer);
-
- /**
- * Execute a given action for each of this tree's children.
- *
- * @param action
- * The action to execute for each child.
- */
- void doForChildren(Consumer<ITree<ContainedType>> action);
-
- /**
- * Expand the nodes of a tree into trees, and then merge the contents of
- * those trees into a single tree.
- *
- * @param mapper
- * The function to use to map values into trees.
- *
- * @return A tree, with some nodes expanded into trees.
- */
- default ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) {
- return topDownTransform(dat -> TopDownTransformResult.PUSHDOWN, node -> {
- if(node.getChildrenCount() > 0) {
- final ITree<ContainedType> parent = node.transformHead(mapper);
-
- node.doForChildren(parent::addChild);
-
- return parent;
- }
-
- return node.transformHead(mapper);
- });
- }
-
- /**
- * Get the specified child of this tree.
- *
- * @param childNo
- * The number of the child to get.
- *
- * @return The specified child of this tree.
- */
- default ITree<ContainedType> getChild(final int childNo) {
- return transformChild(childNo, child -> child);
- }
-
- /**
- * Get a count of the number of direct children this node has.
- *
- * @return The number of direct children this node has.
- */
- int getChildrenCount();
-
- /**
- * Get a count of the number of direct children this node has.
- *
- * @return The number of direct children this node has.
- */
- default int size() {
- return getChildrenCount();
- }
-
- /**
- * Get the data stored in this node.
- *
- * @return The data stored in this node.
- */
- default ContainedType getHead() {
- return transformHead(head -> head);
- }
-
- /**
- * Rebuild the tree with the same structure, but different nodes.
- *
- * @param <MappedType>
- * The type of the new tree.
- *
- * @param leafTransformer
- * The function to use to transform leaf tokens.
- *
- * @param internalTransformer
- * The function to use to transform internal tokens.
- *
- * @return The tree, with the nodes changed.
- */
- <MappedType> ITree<MappedType> rebuildTree(Function<ContainedType, MappedType> leafTransformer,
- Function<ContainedType, MappedType> internalTransformer);
-
- /**
- * Transform some of the nodes in this tree.
- *
- * @param nodePicker
- * The predicate to use to pick nodes to transform.
- *
- * @param transformer
- * The function to use to transform picked nodes.
- */
- void selectiveTransform(Predicate<ContainedType> nodePicker, UnaryOperator<ContainedType> transformer);
-
- /**
- * Do a top-down transform of the tree.
- *
- * @param transformPicker
- * The function to use to pick how to progress.
- *
- * @param transformer
- * The function used to transform picked subtrees.
- *
- * @return The tree with the transform applied to picked subtrees.
- */
- ITree<ContainedType> topDownTransform(Function<ContainedType, TopDownTransformResult> transformPicker,
- UnaryOperator<ITree<ContainedType>> transformer);
-
- /**
- * Transform one of this nodes children.
- *
- * @param <TransformedType>
- * The type of the transformed value.
- *
- * @param childNo
- * The number of the child to transform.
- *
- * @param transformer
- * The function to use to transform the value.
- *
- * @return The transformed value.
- *
- * @throws IllegalArgumentException
- * if the childNo is out of bounds (0 &lt;= childNo &lt;=
- * childCount()).
- */
- <TransformedType> TransformedType transformChild(int childNo,
- Function<ITree<ContainedType>, TransformedType> transformer);
-
- /**
- * Transform the value that is the head of this node.
- *
- * @param <TransformedType>
- * The type of the transformed value.
- *
- * @param transformer
- * The function to use to transform the value.
- *
- * @return The transformed value.
- */
- <TransformedType> TransformedType transformHead(Function<ContainedType, TransformedType> transformer);
-
- /**
- * Transform the tree into a tree with a different type of token.
- *
- * @param <MappedType>
- * The type of the new tree.
- *
- * @param transformer
- * The function to use to transform tokens.
- *
- * @return A tree with the token types transformed.
- */
- default <MappedType> ITree<MappedType> transformTree(final Function<ContainedType, MappedType> transformer) {
- return rebuildTree(transformer, transformer);
- }
-
- /**
- * Perform an action on each part of the tree.
- *
- * @param linearizationMethod
- * The way to traverse the tree.
- *
- * @param action
- * The action to perform on each tree node.
- */
- void traverse(TreeLinearizationMethod linearizationMethod, Consumer<ContainedType> action);
-
- /**
- * Find the farthest to right child that satisfies the given predicate.
- *
- * @param childPred
- * The predicate to satisfy.
- *
- * @return The index of the right-most child that satisfies the
- * predicate, or -1 if one doesn't exist.
- */
- int revFind(Predicate<ITree<ContainedType>> childPred);
-
- /**
- * Check if this tree contains any nodes that satisfy the predicate.
- *
- * @param pred
- * The predicate to look for.
- *
- * @return Whether or not any items satisfied the predicate.
- */
- default boolean containsMatching(Predicate<ContainedType> pred) {
- Toggle<Boolean> tog = new OneWayToggle<>(false, true);
-
- traverse(TreeLinearizationMethod.POSTORDER, (val) -> {
- if(pred.test(val)) tog.get();
- });
-
- return tog.get();
- }
-
- /**
- * Set the head of the tree.
- *
- * @param dat
- * The value to set as the head of the tree.
- */
- void setHead(ContainedType dat);
-}
diff --git a/base/src/main/java/bjc/utils/data/Identity.java b/base/src/main/java/bjc/utils/data/Identity.java
deleted file mode 100644
index 44ddc31..0000000
--- a/base/src/main/java/bjc/utils/data/Identity.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-/**
- * Simple implementation of IHolder that has no hidden behavior.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type contained in the holder.
- */
-public class Identity<ContainedType> implements IHolder<ContainedType> {
- /* The held value. */
- private ContainedType heldValue;
-
- /** Create a holder holding null */
- public Identity() {
- heldValue = null;
- }
-
- /**
- * Create a holder holding the specified value.
- *
- * @param value
- * The value to hold.
- */
- public Identity(final ContainedType value) {
- heldValue = value;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- return binder.apply(heldValue);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + (heldValue == null ? 0 : heldValue.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof Identity)) return false;
-
- final Identity<?> other = (Identity<?>) obj;
-
- if(heldValue == null) {
- if(other.heldValue != null) return false;
- } else if(!heldValue.equals(other.heldValue)) return false;
-
- return true;
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- return (val) -> {
- return new Identity<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- return new Identity<>(mapper.apply(heldValue));
- }
-
- @Override
- public String toString() {
- return String.format("Identity [heldValue=%s]", heldValue);
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- heldValue = transformer.apply(heldValue);
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- return unwrapper.apply(heldValue);
- }
-
- /**
- * Create a new identity container.
- *
- * @param val
- * The contained value.
- *
- * @return A new identity container.
- */
- public static <ContainedType> Identity<ContainedType> id(final ContainedType val) {
- return new Identity<>(val);
- }
-
- /**
- * Create a new empty identity container.
- *
- * @return A new empty identity container.
- */
- public static <ContainedType> Identity<ContainedType> id() {
- return new Identity<>();
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/Lazy.java b/base/src/main/java/bjc/utils/data/Lazy.java
deleted file mode 100644
index 4ffcead..0000000
--- a/base/src/main/java/bjc/utils/data/Lazy.java
+++ /dev/null
@@ -1,201 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.internals.BoundLazy;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
-/**
- * A holder that holds a means to create a value, but doesn't actually compute
- * the value until it's needed.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type of the value being held.
- */
-public class Lazy<ContainedType> implements IHolder<ContainedType> {
- /* The supplier of the type. */
- private Supplier<ContainedType> valueSupplier;
- /* The actual type value. */
- private ContainedType heldValue;
- /* Whether the value has been created. */
- private boolean valueMaterialized;
-
- /* The list of pending actions on the value. */
- private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>();
-
- /**
- * Create a new lazy value from the specified seed value.
- *
- * @param value
- * The seed value to use.
- */
- public Lazy(final ContainedType value) {
- heldValue = value;
-
- valueMaterialized = true;
- }
-
- /**
- * Create a new lazy value from the specified value source.
- *
- * @param supp
- * The source of a value to use.
- */
- public Lazy(final Supplier<ContainedType> supp) {
- valueSupplier = new SingleSupplier<>(supp);
-
- valueMaterialized = false;
- }
-
- /* Create a new value from a supplier and a list of actions. */
- private Lazy(final Supplier<ContainedType> supp, final IList<UnaryOperator<ContainedType>> pendingActions) {
- valueSupplier = supp;
-
- actions = pendingActions;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- final IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
-
- actions.forEach(pendingActions::add);
-
- final Supplier<ContainedType> supplier = () -> {
- if(valueMaterialized) return heldValue;
-
- return valueSupplier.get();
- };
-
- return new BoundLazy<>(() -> {
- return new Lazy<>(supplier, pendingActions);
- }, binder);
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- return val -> {
- return new Lazy<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- final IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
-
- actions.forEach(pendingActions::add);
-
- return new Lazy<>(() -> {
- ContainedType currVal = heldValue;
-
- if(!valueMaterialized) {
- currVal = valueSupplier.get();
- }
-
- return pendingActions.reduceAux(currVal, UnaryOperator<ContainedType>::apply,
- value -> mapper.apply(value));
- });
- }
-
- @Override
- public String toString() {
- if(valueMaterialized) {
- if(actions.isEmpty()) {
- return String.format("value[v='%s']", heldValue);
- }
-
- return String.format("value[v='%s'] (has pending transforms)", heldValue);
- }
-
- return "(unmaterialized)";
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- actions.add(transformer);
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- if(!valueMaterialized) {
- heldValue = valueSupplier.get();
-
- valueMaterialized = true;
- }
-
- actions.forEach(action -> {
- heldValue = action.apply(heldValue);
- });
-
- actions = new FunctionalList<>();
-
- return unwrapper.apply(heldValue);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + (actions == null ? 0 : actions.hashCode());
- result = prime * result + (heldValue == null ? 0 : heldValue.hashCode());
- result = prime * result + (valueMaterialized ? 1231 : 1237);
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof Lazy<?>)) return false;
-
- final Lazy<?> other = (Lazy<?>) obj;
-
- if(valueMaterialized != other.valueMaterialized) return false;
-
- if(valueMaterialized) {
- if(heldValue == null) {
- if(other.heldValue != null) return false;
- } else if(!heldValue.equals(other.heldValue)) return false;
- } else
- return false;
-
- if(actions == null) {
- if(other.actions != null) return false;
- } else if(actions.getSize() > 0 || other.actions.getSize() > 0) return false;
-
- return true;
- }
-
- /**
- * Create a new lazy container with an already present value.
- *
- * @param val
- * The value for the lazy container.
- *
- * @return A new lazy container holding that value.
- */
- public static <ContainedType> Lazy<ContainedType> lazy(final ContainedType val) {
- return new Lazy<>(val);
- }
-
- /**
- * Create a new lazy container with a suspended value.
- *
- * @param supp
- * The suspended value for the lazy container.
- *
- * @return A new lazy container that will un-suspend the value when
- * necessary.
- */
- public static <ContainedType> Lazy<ContainedType> lazy(final Supplier<ContainedType> supp) {
- return new Lazy<>(supp);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/LazyPair.java b/base/src/main/java/bjc/utils/data/LazyPair.java
deleted file mode 100644
index 0500486..0000000
--- a/base/src/main/java/bjc/utils/data/LazyPair.java
+++ /dev/null
@@ -1,249 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-import bjc.utils.data.internals.BoundLazyPair;
-import bjc.utils.data.internals.HalfBoundLazyPair;
-
-/**
- * A lazy implementation of a pair.
- *
- * @author ben
- *
- * @param <LeftType>
- * The type on the left side of the pair.
- *
- * @param <RightType>
- * The type on the right side of the pair.
- */
-public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> {
- /* The supplier for the left value. */
- private Supplier<LeftType> leftSupplier;
- /* The left value. */
- private LeftType leftValue;
- /* Whether the left value has been created. */
- private boolean leftMaterialized;
-
- /* The supplier for the right value. */
- private Supplier<RightType> rightSupplier;
- /* The right value. */
- private RightType rightValue;
- /* Whether the right value has been created. */
- private boolean rightMaterialized;
-
- /**
- * Create a new lazy pair, using the set values.
- *
- * @param leftVal
- * The value for the left side of the pair.
- *
- * @param rightVal
- * The value for the right side of the pair.
- */
- public LazyPair(final LeftType leftVal, final RightType rightVal) {
- leftValue = leftVal;
- rightValue = rightVal;
-
- leftMaterialized = true;
- rightMaterialized = true;
- }
-
- /**
- * Create a new lazy pair from the given value sources.
- *
- * @param leftSupp
- * The source for a value on the left side of the pair.
- *
- * @param rightSupp
- * The source for a value on the right side of the pair.
- */
- public LazyPair(final Supplier<LeftType> leftSupp, final Supplier<RightType> rightSupp) {
- /* Use single suppliers to catch double-instantiation bugs. */
- leftSupplier = new SingleSupplier<>(leftSupp);
- rightSupplier = new SingleSupplier<>(rightSupp);
-
- leftMaterialized = false;
- rightMaterialized = false;
- }
-
- @Override
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- return new BoundLazyPair<>(leftSupplier, rightSupplier, binder);
- }
-
- @Override
- public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
- final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- final Supplier<LeftType> leftSupp = () -> {
- if(leftMaterialized) return leftValue;
-
- return leftSupplier.get();
- };
-
- return new HalfBoundLazyPair<>(leftSupp, leftBinder);
- }
-
- @Override
- public <BoundRight> IPair<LeftType, BoundRight> bindRight(
- final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- final Supplier<RightType> rightSupp = () -> {
- if(rightMaterialized) return rightValue;
-
- return rightSupplier.get();
- };
-
- return new HalfBoundLazyPair<>(rightSupp, rightBinder);
- }
-
- @Override
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- final IPair<OtherLeft, OtherRight> otherPair,
- final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
- return otherPair.bind((otherLeft, otherRight) -> {
- return bind((leftVal, rightVal) -> {
- final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft);
- final CombinedRight right = rightCombiner.apply(rightVal, otherRight);
-
- return new LazyPair<>(left, right);
- });
- });
- }
-
- @Override
- public LeftType getLeft() {
- if(!leftMaterialized) {
- leftValue = leftSupplier.get();
-
- leftMaterialized = true;
- }
-
- return leftValue;
- }
-
- @Override
- public RightType getRight() {
- if(!rightMaterialized) {
- rightValue = rightSupplier.get();
-
- rightMaterialized = true;
- }
-
- return rightValue;
- }
-
- @Override
- public <NewLeft> IPair<NewLeft, RightType> mapLeft(final Function<LeftType, NewLeft> mapper) {
- final Supplier<NewLeft> leftSupp = () -> {
- if(leftMaterialized) return mapper.apply(leftValue);
-
- return mapper.apply(leftSupplier.get());
- };
-
- final Supplier<RightType> rightSupp = () -> {
- if(rightMaterialized) return rightValue;
-
- return rightSupplier.get();
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <NewRight> IPair<LeftType, NewRight> mapRight(final Function<RightType, NewRight> mapper) {
- final Supplier<LeftType> leftSupp = () -> {
- if(leftMaterialized) return leftValue;
-
- return leftSupplier.get();
- };
-
- final Supplier<NewRight> rightSupp = () -> {
- if(rightMaterialized) return mapper.apply(rightValue);
-
- return mapper.apply(rightSupplier.get());
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <MergedType> MergedType merge(final BiFunction<LeftType, RightType, MergedType> merger) {
- if(!leftMaterialized) {
- leftValue = leftSupplier.get();
-
- leftMaterialized = true;
- }
-
- if(!rightMaterialized) {
- rightValue = rightSupplier.get();
-
- rightMaterialized = true;
- }
-
- return merger.apply(leftValue, rightValue);
- }
-
- @Override
- public String toString() {
- String leftVal;
- String rightVal;
-
- if(leftMaterialized) {
- leftVal = leftValue.toString();
- } else {
- leftVal = "(un-materialized)";
- }
-
- if(rightMaterialized) {
- rightVal = rightValue.toString();
- } else {
- rightVal = "(un-materialized)";
- }
-
- return String.format("pair[l=%s,r=%s]", leftVal, rightVal);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + (leftMaterialized ? 1231 : 1237);
- result = prime * result + (leftValue == null ? 0 : leftValue.hashCode());
- result = prime * result + (rightMaterialized ? 1231 : 1237);
- result = prime * result + (rightValue == null ? 0 : rightValue.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof LazyPair<?, ?>)) return false;
-
- final LazyPair<?, ?> other = (LazyPair<?, ?>) obj;
-
- if(leftMaterialized != other.leftMaterialized) return false;
-
- if(leftMaterialized) {
- if(leftValue == null) {
- if(other.leftValue != null) return false;
- } else if(!leftValue.equals(other.leftValue)) return false;
- } else
- return false;
-
- if(rightMaterialized != other.rightMaterialized) return false;
- if(rightMaterialized) {
- if(rightValue == null) {
- if(other.rightValue != null) return false;
- } else if(!rightValue.equals(other.rightValue)) return false;
- } else
- return false;
-
- return true;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/ListHolder.java b/base/src/main/java/bjc/utils/data/ListHolder.java
deleted file mode 100644
index dbcdf6e..0000000
--- a/base/src/main/java/bjc/utils/data/ListHolder.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.internals.BoundListHolder;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
-/**
- * A holder that represents a set of non-deterministic computations.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type of contained value.
- */
-public class ListHolder<ContainedType> implements IHolder<ContainedType> {
- private IList<ContainedType> heldValues;
-
- /**
- * Create a new list holder.
- *
- * @param values
- * The possible values for the computation.
- */
- @SafeVarargs
- public ListHolder(final ContainedType... values) {
- heldValues = new FunctionalList<>();
-
- if(values != null) {
- for(final ContainedType containedValue : values) {
- heldValues.add(containedValue);
- }
- }
- }
-
- /* Create a new holder with values. */
- private ListHolder(final IList<ContainedType> toHold) {
- heldValues = toHold;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- final IList<IHolder<BoundType>> boundValues = heldValues.map(binder);
-
- return new BoundListHolder<>(boundValues);
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- return val -> {
- return new ListHolder<>(new FunctionalList<>(func.apply(val)));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- final IList<MappedType> mappedValues = heldValues.map(mapper);
-
- return new ListHolder<>(mappedValues);
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- heldValues = heldValues.map(transformer);
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- return unwrapper.apply(heldValues.randItem());
- }
-
- @Override
- public String toString() {
- return String.format("ListHolder [heldValues=%s]", heldValues);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + (heldValues == null ? 0 : heldValues.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof ListHolder<?>)) return false;
-
- final ListHolder<?> other = (ListHolder<?>) obj;
-
- if(heldValues == null) {
- if(other.heldValues != null) return false;
- } else if(!heldValues.equals(other.heldValues)) return false;
-
- return true;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/OneWayToggle.java b/base/src/main/java/bjc/utils/data/OneWayToggle.java
deleted file mode 100644
index edec4dd..0000000
--- a/base/src/main/java/bjc/utils/data/OneWayToggle.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package bjc.utils.data;
-
-/**
- * A toggle that will only give the first value once, only yielding the second
- * value afterwards.
- *
- * @author student
- *
- * @param <E>
- * The type of value stored
- */
-public class OneWayToggle<E> implements Toggle<E> {
- private E first;
- private E second;
-
- private boolean gotFirst;
-
- /**
- * Create a new one-way toggle
- *
- * @param first
- * The value to offer first, and only once
- * @param second
- * The value to offer second and repeatedly
- */
- public OneWayToggle(E first, E second) {
- this.first = first;
-
- this.second = second;
- }
-
- @Override
- public E get() {
- if (gotFirst)
- return second;
-
- gotFirst = true;
- return first;
- }
-
- @Override
- public E peek() {
- if (gotFirst)
- return second;
- return first;
- }
-
- @Override
- public void set(boolean gotFirst) {
- this.gotFirst = gotFirst;
- }
-
-}
diff --git a/base/src/main/java/bjc/utils/data/Option.java b/base/src/main/java/bjc/utils/data/Option.java
deleted file mode 100644
index 7869946..0000000
--- a/base/src/main/java/bjc/utils/data/Option.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-/**
- * A holder that may or may not contain a value.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type of the value that may or may not be held.
- */
-public class Option<ContainedType> implements IHolder<ContainedType> {
- private ContainedType held;
-
- /**
- * Create a new optional, using the given initial value.
- *
- * @param seed
- * The initial value for the optional.
- */
- public Option(final ContainedType seed) {
- held = seed;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- if(held == null) return new Option<>(null);
-
- return binder.apply(held);
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- return val -> {
- return new Option<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- if(held == null) return new Option<>(null);
-
- return new Option<>(mapper.apply(held));
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- if(held != null) {
- held = transformer.apply(held);
- }
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- if(held == null) return null;
-
- return unwrapper.apply(held);
- }
-
- @Override
- public String toString() {
- return String.format("Option [held='%s']", held);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
-
- int result = 1;
- result = prime * result + (held == null ? 0 : held.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof Option<?>)) return false;
-
- final Option<?> other = (Option<?>) obj;
-
- if(held == null) {
- if(other.held != null) return false;
- } else if(!held.equals(other.held)) return false;
-
- return true;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/Pair.java b/base/src/main/java/bjc/utils/data/Pair.java
deleted file mode 100644
index df7e199..0000000
--- a/base/src/main/java/bjc/utils/data/Pair.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-
-/**
- * A pair of values, with nothing special about them.
- *
- * @author ben
- *
- * @param <LeftType>
- * The type of the left value.
- *
- * @param <RightType>
- * The type of the right value.
- */
-public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
- /* The left value. */
- private LeftType leftValue;
- /* The right value. */
- private RightType rightValue;
-
- /** Create a new pair with both sides set to null. */
- public Pair() {
-
- }
-
- /**
- * Create a new pair with both sides set to the specified values.
- *
- * @param left
- * The value of the left side.
- *
- * @param right
- * The value of the right side.
- */
- public Pair(final LeftType left, final RightType right) {
- leftValue = left;
- rightValue = right;
- }
-
- @Override
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- if(binder == null) throw new NullPointerException("Binder must not be null.");
-
- return binder.apply(leftValue, rightValue);
- }
-
- @Override
- public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
- final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if(leftBinder == null) throw new NullPointerException("Binder must not be null");
-
- return leftBinder.apply(leftValue);
- }
-
- @Override
- public <BoundRight> IPair<LeftType, BoundRight> bindRight(
- final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if(rightBinder == null) throw new NullPointerException("Binder must not be null");
-
- return rightBinder.apply(rightValue);
- }
-
- @Override
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- final IPair<OtherLeft, OtherRight> otherPair,
- final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
- return otherPair.bind((otherLeft, otherRight) -> {
- final CombinedLeft left = leftCombiner.apply(leftValue, otherLeft);
- final CombinedRight right = rightCombiner.apply(rightValue, otherRight);
-
- return new Pair<>(left, right);
- });
- }
-
- @Override
- public <NewLeft> IPair<NewLeft, RightType> mapLeft(final Function<LeftType, NewLeft> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- return new Pair<>(mapper.apply(leftValue), rightValue);
- }
-
- @Override
- public <NewRight> IPair<LeftType, NewRight> mapRight(final Function<RightType, NewRight> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- return new Pair<>(leftValue, mapper.apply(rightValue));
- }
-
- @Override
- public <MergedType> MergedType merge(final BiFunction<LeftType, RightType, MergedType> merger) {
- if(merger == null) throw new NullPointerException("Merger must not be null");
-
- return merger.apply(leftValue, rightValue);
- }
-
- @Override
- public String toString() {
- return String.format("Pair [leftValue='%s', rightValue='%s']", leftValue, rightValue);
- }
-
- public LeftType getLeft() {
- return leftValue;
- }
-
- public RightType getRight() {
- return rightValue;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + (leftValue == null ? 0 : leftValue.hashCode());
- result = prime * result + (rightValue == null ? 0 : rightValue.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof Pair<?, ?>)) return false;
-
- final Pair<?, ?> other = (Pair<?, ?>) obj;
-
- if(leftValue == null) {
- if(other.leftValue != null) return false;
- } else if(!leftValue.equals(other.leftValue)) return false;
-
- if(rightValue == null) {
- if(other.rightValue != null) return false;
- } else if(!rightValue.equals(other.rightValue)) return false;
-
- return true;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/QueuedIterator.java b/base/src/main/java/bjc/utils/data/QueuedIterator.java
deleted file mode 100644
index 571f2b5..0000000
--- a/base/src/main/java/bjc/utils/data/QueuedIterator.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package bjc.utils.data;
-
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.Iterator;
-
-/**
- * An iterator that supports queuing elements after/before the current iterator;
- *
- * @author bjculkin
- *
- * @param <E> The type of element this iterator iterates over.
- */
-public class QueuedIterator<E> implements Iterator<E> {
- private Iterator<E> cur;
-
- private Deque<Iterator<E>> pending;
-
- /**
- * Static method for constructing iterators.
- *
- * @return A queued iterator.
- */
- public static <E> QueuedIterator<E> queued() {
- return new QueuedIterator<>();
- }
-
- /**
- * Static method for constructing iterators.
- *
- * @param vals
- * The values to iterate over.
- *
- * @return A queued iterator.
- */
- @SafeVarargs
- public static <E> QueuedIterator<E> queued(E... vals) {
- return new QueuedIterator<>(new ArrayIterator<>(vals));
- }
-
- /**
- * Static method for constructing iterators.
- *
- * @param itrs
- * The iterators to use.
- *
- * @return A queued iterator over the provided iterators.
- */
- @SafeVarargs
- public static <E> QueuedIterator<E> queued(Iterator<E>... itrs) {
- return new QueuedIterator<>(itrs);
- }
-
- /**
- * Static method for constructing iterators.
- *
- * @param itrs
- * The iterables to use.
- *
- * @return A queued iterator over the provided iterables.
- */
- @SafeVarargs
- public static <E> QueuedIterator<E> queued(Iterable<E>... itrs) {
- return new QueuedIterator<>(itrs);
- }
-
- /**
- * Create a new queued iterator that starts blank.
- */
- public QueuedIterator() {
- pending = new ArrayDeque<>();
- }
-
- /**
- * Create a new queued iterator with a set of initial sources.
- *
- * @param inits
- * The set of initial iterators to use.
- */
- @SafeVarargs
- public QueuedIterator(Iterator<E>... inits) {
- this();
-
- for (Iterator<E> init : inits) {
- pending.add(init);
- }
- }
-
- /**
- * Create a new queued iterator with a set of initial sources.
- *
- * @param inits
- * The set of initial iterables to use.
- */
- @SafeVarargs
- public QueuedIterator(Iterable<E>... inits) {
- this();
-
- for (Iterable<E> init : inits) {
- pending.add(init.iterator());
- }
- }
-
- /**
- * Create a new queued iterator with a set of initial values.
- *
- * @param vals
- * The set of initial values to use.
- */
- @SafeVarargs
- public QueuedIterator(E... vals) {
- this(new ArrayIterator<>(vals));
- }
-
- /**
- * Add a new iterator who we will iterate through first.
- *
- * @param itr
- * The iterator to go through first.
- */
- public void before(Iterator<E> itr) {
- pending.push(cur);
-
- cur = itr;
- }
-
- /**
- * Add a new iterable who we will iterate through first.
- *
- * @param itr
- * The iterable to go through first.
- */
- public void before(Iterable<E> itr) {
- before(itr.iterator());
- }
-
- /**
- * Add a new set of values who we will iterate through first.
- *
- * @param vals
- * Values to iterate over first.
- */
- public void before(@SuppressWarnings("unchecked") E... vals) {
- before(new ArrayIterator<>(vals));
- }
-
- /**
- * Add a new iterator who we will iterate through next.
- *
- * @param itr
- * The iterator to go through next.
- */
- public void after(Iterator<E> itr) {
- pending.push(itr);
- }
-
- /**
- * Add a new iterable who we will iterate through next.
- *
- * @param itr
- * The iterable to go through next.
- */
- public void after(Iterable<E> itr) {
- after(itr.iterator());
- }
-
- /**
- * Add a new set of values who we will iterate through next.
- *
- * @param vals
- * The values to iterate over next.
- */
- public void after(@SuppressWarnings("unchecked") E... vals) {
- after(new ArrayIterator<>(vals));
- }
-
- /**
- * Add a new iterator who we will iterate through last.
- *
- * @param itr
- * The iterator to go through last.
- */
- public void last(Iterator<E> itr) {
- pending.add(itr);
- }
-
- /**
- * Add a new iterable who we will iterate through last.
- *
- * @param itr
- * The iterable to go through last.
- */
- public void last(Iterable<E> itr) {
- last(itr.iterator());
- }
-
- /**
- * Add a new set of values who we will iterate through last.
- *
- * @param vals
- * The values we will iterate over.
- */
- public void last(@SuppressWarnings("unchecked") E... vals) {
- last(new ArrayIterator<>(vals));
- }
-
- @Override
- public boolean hasNext() {
- while (cur == null || !cur.hasNext()) {
- if (pending.isEmpty()) return false;
-
- cur = pending.pop();
- }
-
- return cur.hasNext();
- }
-
- @Override
- public E next() {
- while (cur == null || !cur.hasNext()) {
- if (pending.isEmpty()) return null;
-
- cur = pending.pop();
- }
-
- return cur.next();
- }
-
-}
diff --git a/base/src/main/java/bjc/utils/data/SingleIterator.java b/base/src/main/java/bjc/utils/data/SingleIterator.java
deleted file mode 100644
index 561cd0b..0000000
--- a/base/src/main/java/bjc/utils/data/SingleIterator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package bjc.utils.data;
-
-import java.util.Iterator;
-
-/**
- * An iterator that will only ever yield one item.
- *
- * @author EVE
- *
- * @param <T>
- * The type of the item.
- */
-public class SingleIterator<T> implements Iterator<T> {
- /* The item being held. */
- private final T itm;
- /* Whether we've yielded the item yet. */
- private boolean yielded;
-
- /**
- * Create a iterator that yields a single item.
- *
- * @param item
- * The item to yield.
- */
- public SingleIterator(final T item) {
- itm = item;
-
- yielded = false;
- }
-
- @Override
- public boolean hasNext() {
- return !yielded;
- }
-
- @Override
- public T next() {
- yielded = true;
-
- return itm;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/SingleSupplier.java b/base/src/main/java/bjc/utils/data/SingleSupplier.java
deleted file mode 100644
index 8054d33..0000000
--- a/base/src/main/java/bjc/utils/data/SingleSupplier.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Supplier;
-
-/**
- * A supplier that can only supply one value.
- *
- * Attempting to retrieve another value will cause an exception to be thrown.
- *
- * @author ben
- *
- * @param <T>
- * The supplied type
- */
-public class SingleSupplier<T> implements Supplier<T> {
- /* The next supplier ID. */
- private static long nextID = 0;
- /* The supplier to yield from. */
- private final Supplier<T> source;
- /* Whether this value has been retrieved yet. */
- private boolean gotten;
- /* The ID of this supplier. */
- private final long id;
-
- /*
- * The place where the supplier was instantiated.
- *
- * @NOTE This is both slow to create, and generally bad practice to keep
- * exceptions around without throwing them. However, it is very useful
- * to find where the first instantiation was.
- */
- private Exception instSite;
-
- /**
- * Create a new single supplier from an existing value.
- *
- * @param supp
- * The supplier to give a single value from.
- */
- public SingleSupplier(final Supplier<T> supp) {
- source = supp;
-
- gotten = false;
-
- id = nextID++;
- }
-
- @Override
- public T get() {
- if(gotten == true) {
- final String msg = String.format(
- "Attempted to retrieve value more than once from single supplier #%d", id);
-
- final IllegalStateException isex = new IllegalStateException(msg);
-
- isex.initCause(instSite);
-
- throw isex;
- }
-
- gotten = true;
-
- try {
- throw new IllegalStateException("Previous instantiation here.");
- } catch(final IllegalStateException isex) {
- instSite = isex;
- }
-
- return source.get();
- }
-
- @Override
- public String toString() {
- return String.format("SingleSupplier [source='%s', gotten=%s, id=%s]", source, gotten, id);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/Toggle.java b/base/src/main/java/bjc/utils/data/Toggle.java
deleted file mode 100644
index 4e7b7d8..0000000
--- a/base/src/main/java/bjc/utils/data/Toggle.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package bjc.utils.data;
-
-/**
- * A stateful holder that swaps between two values of the same type.
- *
- * @author EVE
- *
- * @param <E>
- * The value stored in the toggle.
- */
-public interface Toggle<E> {
- /**
- * Retrieve the currently-aligned value of this toggle, and swap the
- * value to the new one.
- *
- * @return The previously-aligned value.
- */
- E get();
-
- /**
- * Retrieve the currently-aligned value without altering the alignment.
- *
- * @return The currently-aligned value.
- */
- E peek();
-
- /**
- * Change the alignment of the toggle.
- *
- * @param isLeft
- * Whether the toggle should be left-aligned or not.
- */
- void set(boolean isLeft);
-}
diff --git a/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java b/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java
deleted file mode 100644
index f50ff68..0000000
--- a/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java
+++ /dev/null
@@ -1,272 +0,0 @@
-package bjc.utils.data;
-
-import static bjc.utils.data.TopDownTransformResult.RTRANSFORM;
-
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.NoSuchElementException;
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-/*
- * @TODO 10/11/17 Ben Culkin :TopDownStep
- *
- * Figure out what is broken with this, and fix it so that step-wise
- * iteration works correctly.
- */
-
-/**
- * An iterative top-down transform of a tree.
- *
- * @author EVE
- *
- * @param <ContainedType>
- * The type of the nodes in the tree.
- */
-public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<ContainedType>> {
- /**
- * Alias type for a tree transformation.
- *
- * @author student
- *
- * @param <ContainedType>
- * The type contained in the tree.
- */
- public interface TreeTransform<ContainedType>
- extends BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> {
-
- }
-
- /*
- * The function that picks how to transform a given node
- */
- private final Function<ContainedType, TopDownTransformResult> picker;
- /*
- * The transform to apply to a given node.
- */
- private final TreeTransform<ContainedType> transform;
-
- private ITree<ContainedType> preParent;
- private ITree<ContainedType> postParent;
-
- private final Deque<ITree<ContainedType>> preChildren;
- private final Deque<ITree<ContainedType>> postChildren;
-
- private TopDownTransformIterator<ContainedType> curChild;
-
- private boolean done;
- private boolean initial;
-
- private final Deque<Iterator<ITree<ContainedType>>> toYield;
- private Iterator<ITree<ContainedType>> currYield;
-
- /**
- * Create a new tree iterator.
- *
- * @param pickr
- * The function to use to pick how to process nodes.
- * @param transfrm
- * The transform to apply to the nodes.
- * @param tree
- * The tree to transform.
- */
- public TopDownTransformIterator(final Function<ContainedType, TopDownTransformResult> pickr,
- final TreeTransform<ContainedType> transfrm, final ITree<ContainedType> tree) {
- preParent = tree;
-
- preChildren = new LinkedList<>();
- postChildren = new LinkedList<>();
- toYield = new LinkedList<>();
-
- picker = pickr;
- transform = transfrm;
-
- done = false;
- initial = true;
- }
-
- /**
- * Add a set of nodes to yield.
- *
- * @param src
- * The nodes to yield.
- */
- public void addYield(final Iterator<ITree<ContainedType>> src) {
- if (currYield != null) {
- toYield.push(currYield);
- }
-
- currYield = src;
- }
-
- @Override
- public boolean hasNext() {
- return !done;
- }
-
- /**
- * Get the next yielded value.
- *
- * @param val
- * The sentinel value to yield.
- *
- * @return The next yielded value.
- */
- public ITree<ContainedType> flushYields(final ITree<ContainedType> val) {
- if (currYield != null) {
- /*
- * We have non-sentinel values to yield.
- */
-
- /*
- * Add the sentinel to yield later.
- */
- toYield.add(new SingleIterator<>(val));
-
- if (currYield.hasNext()) {
- return currYield.next();
- }
-
- while (toYield.size() != 0 && !currYield.hasNext()) {
- currYield = toYield.pop();
- }
-
- if (toYield.size() == 0 && !currYield.hasNext()) {
- currYield = null;
- return val;
- }
-
- return currYield.next();
- }
-
- return val;
- }
-
- @Override
- public ITree<ContainedType> next() {
- if (done)
- throw new NoSuchElementException();
-
- /*
- * Flush any values that need to be yielded.
- */
- if (currYield != null) {
- ITree<ContainedType> yeld = flushYields(null);
-
- if (yeld != null)
- return yeld;
- }
-
- if (initial) {
- /*
- * Get the way we are transforming.
- */
- final TopDownTransformResult res = picker.apply(preParent.getHead());
-
- switch (res) {
- case PASSTHROUGH:
- postParent = new Tree<>(preParent.getHead());
-
- if (preParent.getChildrenCount() != 0) {
- for (int i = 0; i < preParent.getChildrenCount(); i++) {
- preChildren.add(preParent.getChild(i));
- }
-
- // Return whatever the first child is
- break;
- }
-
- done = true;
- return flushYields(postParent);
- case SKIP:
- done = true;
- return flushYields(preParent);
- case TRANSFORM:
- done = true;
- return flushYields(transform.apply(preParent, this::addYield));
- case RTRANSFORM:
- preParent = transform.apply(preParent, this::addYield);
- return flushYields(preParent);
- case PUSHDOWN:
- if (preParent.getChildrenCount() != 0) {
- for (int i = 0; i < preParent.getChildrenCount(); i++) {
- preChildren.add(preParent.getChild(i));
- }
-
- // Return whatever the first child is
- break;
- }
-
- done = true;
- return flushYields(transform.apply(new Tree<>(preParent.getHead()), this::addYield));
- case PULLUP:
- final ITree<ContainedType> intRes = transform.apply(preParent, this::addYield);
-
- postParent = new Tree<>(intRes.getHead());
-
- if (intRes.getChildrenCount() != 0) {
- for (int i = 0; i < intRes.getChildrenCount(); i++) {
- preChildren.add(intRes.getChild(i));
- }
-
- // Return whatever the first child is
- break;
- }
-
- done = true;
- return flushYields(postParent);
- default:
- throw new IllegalArgumentException("Unknown result type " + res);
- }
-
- if (res != RTRANSFORM) {
- initial = false;
- }
- }
-
- if (curChild == null || !curChild.hasNext()) {
- if (preChildren.size() != 0) {
- curChild = new TopDownTransformIterator<>(picker, transform, preChildren.pop());
-
- final ITree<ContainedType> res = curChild.next();
- //System.out.println("\t\tTRACE: adding node " + res + " to children");
- postChildren.add(res);
-
- return flushYields(res);
- }
-
- ITree<ContainedType> res = null;
-
- if (postParent == null) {
- res = new Tree<>(preParent.getHead());
-
- //System.out.println("\t\tTRACE: adding nodes " + postChildren + " to " + res);
-
- for (final ITree<ContainedType> child : postChildren) {
- res.addChild(child);
- }
-
- // res = transform.apply(res,
- // this::addYield);
- } else {
- res = postParent;
-
- //System.out.println("\t\tTRACE: adding nodes " + postChildren + " to " + res);
- for (final ITree<ContainedType> child : postChildren) {
- res.addChild(child);
- }
- }
-
- done = true;
- return flushYields(res);
- }
-
- final ITree<ContainedType> res = curChild.next();
- //System.out.println("\t\tTRACE: adding node " + res + " to children");
- postChildren.add(res);
-
- return flushYields(res);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/TopDownTransformResult.java b/base/src/main/java/bjc/utils/data/TopDownTransformResult.java
deleted file mode 100644
index 3907df2..0000000
--- a/base/src/main/java/bjc/utils/data/TopDownTransformResult.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package bjc.utils.data;
-
-/**
- * Represents the results for doing a top-down transform of a tree.
- *
- * @author ben
- *
- */
-public enum TopDownTransformResult {
- /** Do not do anything to this node, and ignore its children. */
- SKIP,
- /** Transform this node, and don't touch its children. */
- TRANSFORM,
- /** Transform this node, then recursively transform the result. */
- RTRANSFORM,
- /** Ignore this node, and traverse its children. */
- PASSTHROUGH,
- /** Traverse the nodes of this children, then transform it. */
- PUSHDOWN,
- /** Transform this node, then traverse its children. */
- PULLUP;
-}
diff --git a/base/src/main/java/bjc/utils/data/TransformIterator.java b/base/src/main/java/bjc/utils/data/TransformIterator.java
deleted file mode 100644
index 9ce3b20..0000000
--- a/base/src/main/java/bjc/utils/data/TransformIterator.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package bjc.utils.data;
-
-import java.util.Iterator;
-import java.util.function.Function;
-
-/**
- * An iterator that transforms values from one type to another.
- *
- * @author EVE
- *
- * @param <S>
- * The source iterator type.
- *
- * @param <D>
- * The destination iterator type.
- */
-public class TransformIterator<S, D> implements Iterator<D> {
- /* Our source of values. */
- private final Iterator<S> source;
- /* Transform function. */
- private final Function<S, D> transform;
-
- /**
- * Create a new transform iterator.
- *
- * @param source
- * The source iterator to use.
- *
- * @param transform
- * The transform to apply.
- */
- public TransformIterator(final Iterator<S> source, final Function<S, D> transform) {
- this.source = source;
- this.transform = transform;
- }
-
- @Override
- public boolean hasNext() {
- return source.hasNext();
- }
-
- @Override
- public D next() {
- return transform.apply(source.next());
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/Tree.java b/base/src/main/java/bjc/utils/data/Tree.java
deleted file mode 100644
index 920ab80..0000000
--- a/base/src/main/java/bjc/utils/data/Tree.java
+++ /dev/null
@@ -1,432 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-import bjc.utils.funcdata.bst.TreeLinearizationMethod;
-
-/**
- * A node in a homogeneous tree.
- *
- * @author ben
- *
- * @param <ContainedType>
- * The type contained in the tree.
- */
-public class Tree<ContainedType> implements ITree<ContainedType> {
- /* The data/label for this node. */
- private ContainedType data;
-
- /* The children of this node. */
- private IList<ITree<ContainedType>> children;
-
- /* Whether this node has children. */
- /*
- * @NOTE Why have both this boolean and childCount? Why not just do a
- * childCount == 0 whenever you'd check hasChildren?
- * - Because hasChildren is set once and not reset, and really what
- * it indicates is that children has been allocated.
- */
- private boolean hasChildren;
- /* The number of children this node has. */
- private int childCount = 0;
-
- /* The ID of this node. */
- private int ID;
- /* The next ID to assign to a node. */
- private static int nextID = 0;
-
- /**
- * Create a new leaf node in a tree.
- */
- public Tree() {
- this(null);
- }
-
- /**
- * Create a new leaf node in a tree.
- *
- * @param leaf
- * The data to store as a leaf node.
- */
- public Tree(final ContainedType leaf) {
- data = leaf;
-
- hasChildren = false;
-
- ID = nextID++;
- }
-
- /**
- * Create a new tree node with the specified children.
- *
- * @param leaf
- * The data to hold in this node.
- *
- * @param childrn
- * A list of children for this node.
- */
- public Tree(final ContainedType leaf, final IList<ITree<ContainedType>> childrn) {
- this(leaf);
-
- hasChildren = true;
-
- childCount = childrn.getSize();
-
- children = childrn;
- }
-
- /**
- * Create a new tree node with the specified children.
- *
- * @param leaf
- * The data to hold in this node.
- *
- * @param childrn
- * A list of children for this node.
- */
- @SafeVarargs
- public Tree(final ContainedType leaf, final ITree<ContainedType>... childrn) {
- this(leaf);
-
- hasChildren = true;
-
- childCount = 0;
-
- children = new FunctionalList<>();
-
- for(final ITree<ContainedType> child : childrn) {
- children.add(child);
-
- childCount++;
- }
- }
-
- @Override
- public void addChild(final ContainedType child) {
- addChild(new Tree<>(child));
- }
-
- @Override
- public void addChild(final ITree<ContainedType> child) {
- if(hasChildren == false) {
- hasChildren = true;
-
- children = new FunctionalList<>();
- }
-
- childCount++;
-
- children.add(child);
- }
-
- @Override
- public void prependChild(final ITree<ContainedType> child) {
- if(hasChildren == false) {
- hasChildren = true;
-
- children = new FunctionalList<>();
- }
-
- childCount++;
-
- children.prepend(child);
- }
-
- @Override
- public void doForChildren(final Consumer<ITree<ContainedType>> action) {
- if(childCount > 0) {
- children.forEach(action);
- }
- }
-
- @Override
- public int getChildrenCount() {
- return childCount;
- }
-
- @Override
- public int revFind(final Predicate<ITree<ContainedType>> childPred) {
- if(childCount == 0) {
- return -1;
- }
-
- for(int i = childCount - 1; i >= 0; i--) {
- if(childPred.test(getChild(i))) return i;
- }
-
- return -1;
- }
-
- @Override
- public void traverse(final TreeLinearizationMethod linearizationMethod, final Consumer<ContainedType> action) {
- if(hasChildren) {
- switch(linearizationMethod) {
- case INORDER:
- if(childCount != 2) {
- final String msg = "Can only do in-order traversal for binary trees.";
-
- throw new IllegalArgumentException(msg);
- }
-
- children.getByIndex(0).traverse(linearizationMethod, action);
-
- action.accept(data);
-
- children.getByIndex(1).traverse(linearizationMethod, action);
- break;
- case POSTORDER:
- children.forEach((child) -> child.traverse(linearizationMethod, action));
-
- action.accept(data);
- break;
- case PREORDER:
- action.accept(data);
-
- children.forEach((child) -> child.traverse(linearizationMethod, action));
- break;
- default:
- break;
-
- }
- } else {
- action.accept(data);
- }
- }
-
- @Override
- public <NewType, ReturnedType> ReturnedType collapse(final Function<ContainedType, NewType> leafTransform,
- final BiFunction<ContainedType, IList<NewType>, NewType> nodeCollapser,
- final Function<NewType, ReturnedType> resultTransformer) {
- return resultTransformer.apply(internalCollapse(leafTransform, nodeCollapser));
- }
-
- @Override
- public ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) {
- if(hasChildren) {
- final ITree<ContainedType> flatMappedData = mapper.apply(data);
-
- final IList<ITree<ContainedType>> mappedChildren = children
- .map(child -> child.flatMapTree(mapper));
-
- mappedChildren.forEach(flatMappedData::addChild);
-
- return flatMappedData;
- }
-
- return mapper.apply(data);
- }
-
- /*
- * Do a collapse of this tree.
- *
- * @NOTE Why is this protected? I can't see any good reason someone'd
- * want to override it.
- */
-
- protected <NewType> NewType internalCollapse(final Function<ContainedType, NewType> leafTransform,
- final BiFunction<ContainedType, IList<NewType>, NewType> nodeCollapser) {
- if(hasChildren) {
- final IList<NewType> collapsedChildren = children.map(child -> {
- final NewType collapsed = child.collapse(leafTransform, nodeCollapser,
- subTreeVal -> subTreeVal);
-
- return collapsed;
- });
-
- return nodeCollapser.apply(data, collapsedChildren);
- }
-
- return leafTransform.apply(data);
- }
-
- protected void internalToString(final StringBuilder builder, final int indentLevel, final boolean initial) {
- if(!initial) {
- for(int i = 0; i < indentLevel; i++) {
- builder.append(">\t");
- }
- }
-
- builder.append("Node #");
- builder.append(ID);
- builder.append(": ");
- builder.append(data == null ? "(null)" : data.toString());
- builder.append("\n");
-
- if(hasChildren) {
- children.forEach(child -> {
- if(child instanceof Tree<?>) {
- final Tree<ContainedType> kid = (Tree<ContainedType>) child;
-
- kid.internalToString(builder, indentLevel + 1, false);
- } else {
- for(int i = 0; i < indentLevel + 1; i++) {
- builder.append(">\t");
- }
-
- builder.append("Unknown node of type ");
- builder.append(child.getClass().getName());
- builder.append("\n");
- }
- });
- }
- }
-
- @Override
- public <MappedType> ITree<MappedType> rebuildTree(final Function<ContainedType, MappedType> leafTransformer,
- final Function<ContainedType, MappedType> operatorTransformer) {
- if(hasChildren) {
- final IList<ITree<MappedType>> mappedChildren = children.map(child -> {
- return child.rebuildTree(leafTransformer, operatorTransformer);
- });
-
- final MappedType mapData = operatorTransformer.apply(data);
- return new Tree<>(mapData, mappedChildren);
- }
-
- return new Tree<>(leafTransformer.apply(data));
- }
-
- @Override
- public void selectiveTransform(final Predicate<ContainedType> nodePicker,
- final UnaryOperator<ContainedType> transformer) {
- if(hasChildren) {
- children.forEach(child -> child.selectiveTransform(nodePicker, transformer));
- } else {
- data = transformer.apply(data);
- }
- }
-
- @Override
- public ITree<ContainedType> topDownTransform(
- final Function<ContainedType, TopDownTransformResult> transformPicker,
- final UnaryOperator<ITree<ContainedType>> transformer) {
- final TopDownTransformResult transformResult = transformPicker.apply(data);
-
- switch(transformResult) {
- case PASSTHROUGH:
- ITree<ContainedType> result = new Tree<>(data);
-
- if(hasChildren) {
- children.forEach(child -> {
- final ITree<ContainedType> kid = child.topDownTransform(transformPicker,
- transformer);
-
- result.addChild(kid);
- });
- }
-
- return result;
- case SKIP:
- return this;
- case TRANSFORM:
- return transformer.apply(this);
- case RTRANSFORM:
- return transformer.apply(this).topDownTransform(transformPicker, transformer);
- case PUSHDOWN:
- result = new Tree<>(data);
-
- if(hasChildren) {
- children.forEach(child -> {
- final ITree<ContainedType> kid = child.topDownTransform(transformPicker,
- transformer);
-
- result.addChild(kid);
- });
- }
-
- return transformer.apply(result);
- case PULLUP:
- final ITree<ContainedType> intermediateResult = transformer.apply(this);
-
- result = new Tree<>(intermediateResult.getHead());
-
- intermediateResult.doForChildren(child -> {
- final ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer);
-
- result.addChild(kid);
- });
-
- return result;
- default:
- final String msg = String.format("Recieved unknown transform result type %s", transformResult);
-
- throw new IllegalArgumentException(msg);
- }
- }
-
- @Override
- public <TransformedType> TransformedType transformChild(final int childNo,
- final Function<ITree<ContainedType>, TransformedType> transformer) {
- if(childNo < 0 || childNo > childCount - 1) {
- final String msg = String.format("Child index #%d is invalid", childNo);
-
- throw new IllegalArgumentException(msg);
- }
-
- final ITree<ContainedType> selectedKid = children.getByIndex(childNo);
-
- return transformer.apply(selectedKid);
- }
-
- @Override
- public <TransformedType> TransformedType transformHead(
- final Function<ContainedType, TransformedType> transformer) {
- return transformer.apply(data);
- }
-
- @Override
- public void setHead(ContainedType dat) {
- this.data = dat;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + childCount;
- result = prime * result + (children == null ? 0 : children.hashCode());
- result = prime * result + (data == null ? 0 : data.hashCode());
-
- return result;
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
-
- internalToString(builder, 1, true);
-
- /* Delete a trailing nl. */
- builder.deleteCharAt(builder.length() - 1);
-
- return builder.toString();
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof Tree<?>)) return false;
-
- final Tree<?> other = (Tree<?>) obj;
-
- if(data == null) {
- if(other.data != null) return false;
- } else if(!data.equals(other.data)) return false;
-
- if(childCount != other.childCount) return false;
-
- if(children == null) {
- if(other.children != null) return false;
- } else if(!children.equals(other.children)) return false;
-
- return true;
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/ValueToggle.java b/base/src/main/java/bjc/utils/data/ValueToggle.java
deleted file mode 100644
index 0fddddf..0000000
--- a/base/src/main/java/bjc/utils/data/ValueToggle.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package bjc.utils.data;
-
-/**
- * A simple implementation of {@link Toggle}.
- *
- * @author EVE
- *
- * @param <E>
- * The type of value to toggle between.
- */
-public class ValueToggle<E> implements Toggle<E> {
- /* Our left value. */
- private final E lft;
- /* Our right value. */
- private final E rght;
- /* Our alignment. */
- private final BooleanToggle alignment;
-
- /**
- * Create a new toggle.
- *
- * All toggles start right-aligned.
- *
- * @param left
- * The value when the toggle is left-aligned.
- *
- * @param right
- * The value when the toggle is right-aligned.
- */
- public ValueToggle(final E left, final E right) {
- lft = left;
-
- rght = right;
-
- alignment = new BooleanToggle();
- }
-
- @Override
- public E get() {
- if(alignment.get()) {
- return lft;
- }
-
- return rght;
- }
-
- @Override
- public E peek() {
- if(alignment.peek()) {
- return lft;
- }
-
- return rght;
- }
-
- @Override
- public void set(final boolean isLeft) {
- alignment.set(isLeft);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/internals/BoundLazy.java b/base/src/main/java/bjc/utils/data/internals/BoundLazy.java
deleted file mode 100644
index f4e8f7e..0000000
--- a/base/src/main/java/bjc/utils/data/internals/BoundLazy.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package bjc.utils.data.internals;
-
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Lazy;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
-/**
- * Implements a lazy holder that has been bound.
- *
- * @author Ben Culkin
- */
-@SuppressWarnings("javadoc")
-public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundContainedType> {
- /* The old value. */
- private final Supplier<IHolder<OldType>> oldSupplier;
-
- /* The function to use to transform the old value into a new value. */
- private final Function<OldType, IHolder<BoundContainedType>> binder;
-
- /* The bound value being held. */
- private IHolder<BoundContainedType> boundHolder;
-
- /* Whether the bound value has been actualized or not. */
- private boolean holderBound;
-
- /* Transformations currently pending on the bound value. */
- private final IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>();
-
- /**
- * Create a new bound lazy value.
- *
- * @param supp
- * The supplier of the old value.
- *
- * @param binder
- * The function to use to bind the old value to the new one.
- */
- public BoundLazy(final Supplier<IHolder<OldType>> supp,
- final Function<OldType, IHolder<BoundContainedType>> binder) {
- oldSupplier = supp;
- this.binder = binder;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<BoundContainedType, IHolder<BoundType>> bindr) {
- if(bindr == null) throw new NullPointerException("Binder must not be null");
-
- /* Prepare a list of pending actions. */
- final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
- actions.forEach(pendingActions::add);
-
- /* Create the new supplier of a value. */
- final Supplier<IHolder<BoundContainedType>> typeSupplier = () -> {
- IHolder<BoundContainedType> oldHolder = boundHolder;
-
- /* Bind the value if it hasn't been bound before. */
- if(!holderBound) {
- oldHolder = oldSupplier.get().unwrap(binder);
- }
-
- /* Apply all the pending actions. */
- return pendingActions.reduceAux(oldHolder, (action, state) -> {
- return state.transform(action);
- }, (value) -> value);
- };
-
- return new BoundLazy<>(typeSupplier, bindr);
- }
-
- @Override
- public <NewType> Function<BoundContainedType, IHolder<NewType>> lift(
- final Function<BoundContainedType, NewType> func) {
- if(func == null) throw new NullPointerException("Function to lift must not be null");
-
- return (val) -> {
- return new Lazy<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<BoundContainedType, MappedType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- /* Prepare a list of pending actions. */
- final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
- actions.forEach(pendingActions::add);
-
- /* Prepare the new supplier. */
- final Supplier<MappedType> typeSupplier = () -> {
- IHolder<BoundContainedType> oldHolder = boundHolder;
-
- /* Bound the value if it hasn't been bound. */
- if(!holderBound) {
- oldHolder = oldSupplier.get().unwrap(binder);
- }
-
- /* Apply pending actions. */
- return pendingActions.reduceAux(oldHolder.getValue(), (action, state) -> {
- return action.apply(state);
- }, (value) -> mapper.apply(value));
- };
-
- return new Lazy<>(typeSupplier);
- }
-
- @Override
- public String toString() {
- if(holderBound) return boundHolder.toString();
-
- return "(unmaterialized)";
- }
-
- @Override
- public IHolder<BoundContainedType> transform(final UnaryOperator<BoundContainedType> transformer) {
- if(transformer == null) throw new NullPointerException("Transformer must not be null");
-
- actions.add(transformer);
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<BoundContainedType, UnwrappedType> unwrapper) {
- if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
-
- if(!holderBound) {
- boundHolder = oldSupplier.get().unwrap(binder::apply);
- }
-
- return boundHolder.unwrap(unwrapper);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java b/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
deleted file mode 100644
index 2ef0e4c..0000000
--- a/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
+++ /dev/null
@@ -1,228 +0,0 @@
-package bjc.utils.data.internals;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Identity;
-import bjc.utils.data.LazyPair;
-
-/**
- * Implements a lazy pair that has been bound.
- *
- * @author Ben Culkin
- */
-@SuppressWarnings("javadoc")
-public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPair<NewLeft, NewRight> {
- /* The supplier of the left value. */
- private final Supplier<OldLeft> leftSupplier;
- /* The supplier of the right value. */
- private final Supplier<OldRight> rightSupplier;
-
- /* The binder to transform values. */
- private final BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> binder;
-
- /* The bound pair. */
- private IPair<NewLeft, NewRight> boundPair;
-
- /* Whether the pair has been bound yet. */
- private boolean pairBound;
-
- /**
- * Create a new bound lazy pair.
- *
- * @param leftSupp
- * The supplier for the left value.
- *
- * @param rightSupp
- * The supplier for the right value.
- *
- * @param bindr
- * The function to use to bind the left and right into a new
- * pair.
- */
- public BoundLazyPair(final Supplier<OldLeft> leftSupp, final Supplier<OldRight> rightSupp,
- final BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) {
- leftSupplier = leftSupp;
- rightSupplier = rightSupp;
- binder = bindr;
- }
-
- @Override
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- final BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- if(bindr == null) throw new NullPointerException("Binder must not be null");
-
- final IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
- final IHolder<Boolean> newPairMade = new Identity<>(pairBound);
-
- final Supplier<NewLeft> leftSupp = () -> {
- if(!newPairMade.getValue()) {
- /*
- * If the pair hasn't been bound before, bind
- * it.
- */
- newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
-
- newPairMade.replace(true);
- }
-
- return newPair.unwrap((pair) -> pair.getLeft());
- };
-
- final Supplier<NewRight> rightSupp = () -> {
- if(!newPairMade.getValue()) {
- /*
- * If the pair hasn't been bound before, bind
- * it.
- */
- newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
-
- newPairMade.replace(true);
- }
-
- return newPair.unwrap((pair) -> pair.getRight());
- };
-
- return new BoundLazyPair<>(leftSupp, rightSupp, bindr);
- }
-
- @Override
- public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
- if(leftBinder == null) throw new NullPointerException("Left binder must not be null");
-
- final Supplier<NewLeft> leftSupp = () -> {
- IPair<NewLeft, NewRight> newPair = boundPair;
-
- if(!pairBound) {
- /*
- * If the pair hasn't been bound before, bind
- * it.
- */
- newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
- }
-
- return newPair.getLeft();
- };
-
- return new HalfBoundLazyPair<>(leftSupp, leftBinder);
- }
-
- @Override
- public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
- if(rightBinder == null) throw new NullPointerException("Right binder must not be null");
-
- final Supplier<NewRight> rightSupp = () -> {
- IPair<NewLeft, NewRight> newPair = boundPair;
-
- if(!pairBound) {
- /*
- * If the pair hasn't been bound before, bind
- * it.
- */
- newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
- }
-
- return newPair.getRight();
- };
-
- return new HalfBoundLazyPair<>(rightSupp, rightBinder);
- }
-
- @Override
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- final IPair<OtherLeft, OtherRight> otherPair,
- final BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
- final BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
- if(otherPair == null) {
- throw new NullPointerException("Other pair must not be null");
- } else if(leftCombiner == null) {
- throw new NullPointerException("Left combiner must not be null");
- } else if(rightCombiner == null) {
- throw new NullPointerException("Right combiner must not be null");
- }
-
- return otherPair.bind((otherLeft, otherRight) -> {
- return bind((leftVal, rightVal) -> {
- CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft);
- CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
-
- return new LazyPair<>(cLeft, cRight);
- });
- });
- }
-
- @Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- final Supplier<NewLeftType> leftSupp = () -> {
- if(!pairBound) {
- final NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
-
- return mapper.apply(leftVal);
- }
-
- return mapper.apply(boundPair.getLeft());
- };
-
- final Supplier<NewRight> rightSupp = () -> {
- if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
-
- return boundPair.getRight();
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final Function<NewRight, NewRightType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- final Supplier<NewLeft> leftSupp = () -> {
- if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
-
- return boundPair.getLeft();
- };
-
- final Supplier<NewRightType> rightSupp = () -> {
- if(!pairBound) {
- final NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get())
- .getRight();
-
- return mapper.apply(rightVal);
- }
-
- return mapper.apply(boundPair.getRight());
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <MergedType> MergedType merge(final BiFunction<NewLeft, NewRight, MergedType> merger) {
- if(merger == null) throw new NullPointerException("Merger must not be null");
-
- if(!pairBound) {
- /*
- * If the pair isn't bound yet, bind it.
- */
- boundPair = binder.apply(leftSupplier.get(), rightSupplier.get());
-
- pairBound = true;
- }
-
- return boundPair.merge(merger);
- }
-
- @Override
- public String toString() {
- if(pairBound) return boundPair.toString();
-
- return "(un-materialized)";
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java b/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java
deleted file mode 100644
index 613f8e9..0000000
--- a/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package bjc.utils.data.internals;
-
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.ListHolder;
-import bjc.utils.funcdata.IList;
-
-/**
- * Holds a list, converted into a holder.
- *
- * @author Ben Culkin
- */
-@SuppressWarnings("javadoc")
-public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
- /* The list of contained holders. */
- private final IList<IHolder<ContainedType>> heldHolders;
-
- /**
- * Create a new list of holders.
- *
- * @param toHold
- * The list of holders to, well, hold.
- */
- public BoundListHolder(final IList<IHolder<ContainedType>> toHold) {
- heldHolders = toHold;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- if(binder == null) throw new NullPointerException("Binder must not be null");
-
- final IList<IHolder<BoundType>> boundHolders = heldHolders.map((containedHolder) -> {
- return containedHolder.bind(binder);
- });
-
- return new BoundListHolder<>(boundHolders);
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- if(func == null) throw new NullPointerException("Function to lift must not be null");
-
- return (val) -> {
- return new ListHolder<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
-
- final IList<IHolder<MappedType>> mappedHolders = heldHolders.map((containedHolder) -> {
- return containedHolder.map(mapper);
- });
-
- return new BoundListHolder<>(mappedHolders);
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- if(transformer == null) throw new NullPointerException("Transformer must not be null");
-
- heldHolders.forEach((containedHolder) -> {
- containedHolder.transform(transformer);
- });
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
-
- /*
- * @NOTE Is there another way we could want to do this?
- */
- return heldHolders.randItem().unwrap(unwrapper);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java b/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
deleted file mode 100644
index 4803bc2..0000000
--- a/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package bjc.utils.data.internals;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Identity;
-import bjc.utils.data.LazyPair;
-
-/*
- * @NOTE
- * I am not convinced that this code works correctly. Tests should be
- * written to make sure things only ever get instantiated once.
- *
- * Namely, my main concern is to whether the places that bind the pair
- * without setting pairBound are doing the right thing.
- */
-/**
- * A lazy pair, with only one side bound.
- *
- * @author Ben Culkin
- */
-@SuppressWarnings("javadoc")
-public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewLeft, NewRight> {
- /* The supplier of the old value. */
- private final Supplier<OldType> oldSupplier;
-
- /* The function to transform the old value into a new pair. */
- private final Function<OldType, IPair<NewLeft, NewRight>> binder;
-
- /* The new bound pair. */
- private IPair<NewLeft, NewRight> boundPair;
- /* Has the pair been bound yet or not? */
- private boolean pairBound;
-
- /**
- * Create a new half-bound lazy pair.
- *
- * @param oldSupp
- * The supplier of the old value.
- *
- * @param bindr
- * The function to use to create the pair from the old value.
- */
- public HalfBoundLazyPair(final Supplier<OldType> oldSupp,
- final Function<OldType, IPair<NewLeft, NewRight>> bindr) {
- oldSupplier = oldSupp;
- binder = bindr;
- }
-
- @Override
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- final BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- final IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
- final IHolder<Boolean> newPairMade = new Identity<>(pairBound);
-
- final Supplier<NewLeft> leftSupp = () -> {
- if(!newPairMade.getValue()) {
- /* Bind the pair if it hasn't been bound yet. */
- newPair.replace(binder.apply(oldSupplier.get()));
- newPairMade.replace(true);
- }
-
- return newPair.unwrap((pair) -> pair.getLeft());
- };
-
- final Supplier<NewRight> rightSupp = () -> {
- if(!newPairMade.getValue()) {
- /* Bind the pair if it hasn't been bound yet. */
- newPair.replace(binder.apply(oldSupplier.get()));
- newPairMade.replace(true);
- }
-
- return newPair.unwrap((pair) -> pair.getRight());
- };
-
- return new BoundLazyPair<>(leftSupp, rightSupp, bindr);
- }
-
- @Override
- public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
- final Supplier<NewLeft> leftSupp = () -> {
- IPair<NewLeft, NewRight> newPair = boundPair;
-
- if(!pairBound) {
- newPair = binder.apply(oldSupplier.get());
- }
-
- return newPair.getLeft();
- };
-
- return new HalfBoundLazyPair<>(leftSupp, leftBinder);
- }
-
- @Override
- public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
- final Supplier<NewRight> rightSupp = () -> {
- IPair<NewLeft, NewRight> newPair = boundPair;
-
- if(!pairBound) {
- newPair = binder.apply(oldSupplier.get());
- }
-
- return newPair.getRight();
- };
-
- return new HalfBoundLazyPair<>(rightSupp, rightBinder);
- }
-
- @Override
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- final IPair<OtherLeft, OtherRight> otherPair,
- final BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
- final BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
- return otherPair.bind((otherLeft, otherRight) -> {
- return bind((leftVal, rightVal) -> {
- CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft);
- CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
-
- return new LazyPair<>(cLeft, cRight);
- });
- });
- }
-
- @Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) {
- final Supplier<NewLeftType> leftSupp = () -> {
- if(pairBound) return mapper.apply(boundPair.getLeft());
-
- final NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
-
- return mapper.apply(leftVal);
- };
-
- final Supplier<NewRight> rightSupp = () -> {
- if(pairBound) return boundPair.getRight();
-
- return binder.apply(oldSupplier.get()).getRight();
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final Function<NewRight, NewRightType> mapper) {
- final Supplier<NewLeft> leftSupp = () -> {
- if(pairBound) return boundPair.getLeft();
-
- return binder.apply(oldSupplier.get()).getLeft();
- };
-
- final Supplier<NewRightType> rightSupp = () -> {
- if(pairBound) return mapper.apply(boundPair.getRight());
-
- final NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
-
- return mapper.apply(rightVal);
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <MergedType> MergedType merge(final BiFunction<NewLeft, NewRight, MergedType> merger) {
- if(!pairBound) {
- boundPair = binder.apply(oldSupplier.get());
-
- pairBound = true;
- }
-
- return boundPair.merge(merger);
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java b/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java
deleted file mode 100644
index c08e502..0000000
--- a/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package bjc.utils.data.internals;
-
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Lazy;
-
-/**
- * A wrapped lazy value.
- *
- * @author Ben Culkin
- * @param <ContainedType>
- * The type of the wrapped value.
- */
-public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
- /* Held value. */
- private final IHolder<IHolder<ContainedType>> held;
-
- /**
- * Create a new wrapped lazy value.
- *
- * @param wrappedHolder
- * The holder to make lazy.
- */
- public WrappedLazy(final IHolder<ContainedType> wrappedHolder) {
- held = new Lazy<>(wrappedHolder);
- }
-
- /*
- * This has an extra parameter, because otherwise it erases to the same
- * as the public one.
- *
- * This is a case where reified generics would be useful, because then
- * the compiler could know which one we meant without the dummy
- * parameter.
- */
- private WrappedLazy(final IHolder<IHolder<ContainedType>> wrappedHolder,
- @SuppressWarnings("unused") final boolean dummy) {
- held = wrappedHolder;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- final IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> {
- return containedHolder.bind(binder);
- });
-
- return new WrappedLazy<>(newHolder, false);
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- return (val) -> {
- return new Lazy<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- final IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> {
- return containedHolder.map(mapper);
- });
-
- return new WrappedLazy<>(newHolder, false);
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- held.transform((containedHolder) -> {
- return containedHolder.transform(transformer);
- });
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- return held.unwrap((containedHolder) -> {
- return containedHolder.unwrap(unwrapper);
- });
- }
-}
diff --git a/base/src/main/java/bjc/utils/data/internals/WrappedOption.java b/base/src/main/java/bjc/utils/data/internals/WrappedOption.java
deleted file mode 100644
index 19d5e26..0000000
--- a/base/src/main/java/bjc/utils/data/internals/WrappedOption.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package bjc.utils.data.internals;
-
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Option;
-
-/**
- * A wrapped optional value.
- *
- * @author Ben Culkin.
- * @param <ContainedType>
- * The wrapped type.
- */
-public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
- /* The held value. */
- private final IHolder<IHolder<ContainedType>> held;
-
- /**
- * Create a new wrapped option.
- *
- * @param seedValue
- * The value to wrap.
- */
- public WrappedOption(final IHolder<ContainedType> seedValue) {
- held = new Option<>(seedValue);
- }
-
- /*
- * The dummy parameter is to ensure the compiler can pick the right
- * method, because without this method erases to the same type as the
- * public one.
- */
- private WrappedOption(final IHolder<IHolder<ContainedType>> toHold,
- @SuppressWarnings("unused") final boolean dummy) {
- held = toHold;
- }
-
- @Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- final IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> {
- return containedHolder.bind((containedValue) -> {
- if(containedValue == null) return new Option<>(null);
-
- return binder.apply(containedValue);
- });
- });
-
- return new WrappedOption<>(newHolder, false);
- }
-
- @Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
- return (val) -> {
- return new Option<>(func.apply(val));
- };
- }
-
- @Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
- final IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> {
- return containedHolder.map((containedValue) -> {
- if(containedValue == null) return null;
-
- return mapper.apply(containedValue);
- });
- });
-
- return new WrappedOption<>(newHolder, false);
- }
-
- @Override
- public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
- held.transform((containedHolder) -> {
- return containedHolder.transform((containedValue) -> {
- if(containedValue == null) return null;
-
- return transformer.apply(containedValue);
- });
- });
-
- return this;
- }
-
- @Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- return held.unwrap((containedHolder) -> {
- return containedHolder.unwrap((containedValue) -> {
- if(containedValue == null) return null;
-
- return unwrapper.apply(containedValue);
- });
- });
- }
-}
diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java
index b988588..e955152 100644
--- a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java
+++ b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java
@@ -12,10 +12,10 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Identity;
-import bjc.utils.data.Pair;
+import bjc.data.IHolder;
+import bjc.data.IPair;
+import bjc.data.Identity;
+import bjc.data.Pair;
/**
* A wrapper over another list that provides eager functional operations over
diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java b/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java
index 115005c..b67db3c 100644
--- a/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java
+++ b/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java
@@ -6,7 +6,7 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
-import bjc.utils.data.IPair;
+import bjc.data.IPair;
/**
* Basic implementation of {@link IMap}
diff --git a/base/src/main/java/bjc/utils/funcdata/IList.java b/base/src/main/java/bjc/utils/funcdata/IList.java
index c2f247b..5ea7678 100644
--- a/base/src/main/java/bjc/utils/funcdata/IList.java
+++ b/base/src/main/java/bjc/utils/funcdata/IList.java
@@ -9,7 +9,7 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
-import bjc.utils.data.IPair;
+import bjc.data.IPair;
import bjc.utils.functypes.ID;
/**
diff --git a/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java b/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
index 419c216..fab2ba2 100644
--- a/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
@@ -2,8 +2,8 @@ package bjc.utils.funcutils;
import java.util.stream.Collector;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
+import bjc.data.IHolder;
+import bjc.data.IPair;
/**
* Utilities for producing implementations of {@link Collector}
diff --git a/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java b/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java
index 53b4b8d..555d3d1 100644
--- a/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java
+++ b/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java
@@ -7,10 +7,10 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Identity;
-import bjc.utils.data.Pair;
+import bjc.data.IHolder;
+import bjc.data.IPair;
+import bjc.data.Identity;
+import bjc.data.Pair;
/**
* Implementation of a collecter that uses two collectors.
diff --git a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java
index 732f1e9..2b5fc57 100644
--- a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java
@@ -3,7 +3,7 @@ package bjc.utils.funcutils;
import java.util.*;
import java.util.function.*;
-import bjc.utils.data.ArrayIterator;
+import bjc.data.ArrayIterator;
/**
* Utility methods for dealing with iterators.
diff --git a/base/src/main/java/bjc/utils/funcutils/StringUtils.java b/base/src/main/java/bjc/utils/funcutils/StringUtils.java
index dc3f393..88c418f 100644
--- a/base/src/main/java/bjc/utils/funcutils/StringUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -11,7 +11,7 @@ import java.util.regex.Pattern;
import com.ibm.icu.text.BreakIterator;
-import bjc.utils.data.BooleanToggle;
+import bjc.data.BooleanToggle;
import bjc.utils.ioutils.LevelSplitter;
import bjc.utils.parserutils.TokenUtils;
diff --git a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java
index ac8bb69..8392f1c 100644
--- a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java
@@ -3,7 +3,7 @@ package bjc.utils.funcutils;
import java.util.LinkedList;
import java.util.function.Predicate;
-import bjc.utils.data.ITree;
+import bjc.data.ITree;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
diff --git a/base/src/main/java/bjc/utils/gen/WeightedGrammar.java b/base/src/main/java/bjc/utils/gen/WeightedGrammar.java
index 472c3a3..87888bd 100644
--- a/base/src/main/java/bjc/utils/gen/WeightedGrammar.java
+++ b/base/src/main/java/bjc/utils/gen/WeightedGrammar.java
@@ -6,8 +6,8 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Pair;
+import bjc.data.IPair;
+import bjc.data.Pair;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IList;
diff --git a/base/src/main/java/bjc/utils/gen/WeightedRandom.java b/base/src/main/java/bjc/utils/gen/WeightedRandom.java
index 71de333..c1c1714 100644
--- a/base/src/main/java/bjc/utils/gen/WeightedRandom.java
+++ b/base/src/main/java/bjc/utils/gen/WeightedRandom.java
@@ -2,8 +2,8 @@ package bjc.utils.gen;
import java.util.Random;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Pair;
+import bjc.data.IPair;
+import bjc.data.Pair;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
diff --git a/base/src/main/java/bjc/utils/graph/AdjacencyMap.java b/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
index 965eccc..7d75af5 100644
--- a/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
+++ b/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
@@ -6,8 +6,8 @@ import java.io.PrintStream;
import java.util.InputMismatchException;
import java.util.Scanner;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Identity;
+import bjc.data.IHolder;
+import bjc.data.Identity;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IList;
diff --git a/base/src/main/java/bjc/utils/graph/Graph.java b/base/src/main/java/bjc/utils/graph/Graph.java
index 83c2dc2..26d300e 100644
--- a/base/src/main/java/bjc/utils/graph/Graph.java
+++ b/base/src/main/java/bjc/utils/graph/Graph.java
@@ -10,8 +10,8 @@ import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Identity;
+import bjc.data.IHolder;
+import bjc.data.Identity;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IList;
import bjc.utils.funcdata.IMap;
diff --git a/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java b/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java
index 60a2765..9e1592e 100644
--- a/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java
+++ b/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java
@@ -4,7 +4,7 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
-import bjc.utils.data.IHolder;
+import bjc.data.IHolder;
import bjc.utils.gui.layout.HLayout;
/**
diff --git a/base/src/main/java/bjc/utils/ioutils/RegexStringEditor.java b/base/src/main/java/bjc/utils/ioutils/RegexStringEditor.java
index 6068422..de46cbf 100644
--- a/base/src/main/java/bjc/utils/ioutils/RegexStringEditor.java
+++ b/base/src/main/java/bjc/utils/ioutils/RegexStringEditor.java
@@ -5,8 +5,8 @@ import java.util.function.UnaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import bjc.utils.data.Toggle;
-import bjc.utils.data.ValueToggle;
+import bjc.data.Toggle;
+import bjc.data.ValueToggle;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
import bjc.utils.functypes.ID;
diff --git a/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java b/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
index 211a352..c9ac659 100644
--- a/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
+++ b/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
@@ -6,10 +6,10 @@ import java.util.Scanner;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Identity;
-import bjc.utils.data.Pair;
+import bjc.data.IHolder;
+import bjc.data.IPair;
+import bjc.data.Identity;
+import bjc.data.Pair;
import bjc.utils.exceptions.UnknownPragmaException;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.FunctionalStringTokenizer;
diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java
index 73badcd..456a445 100644
--- a/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java
+++ b/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java
@@ -2,7 +2,7 @@ package bjc.utils.ioutils.blocks;
import java.io.IOException;
-import bjc.utils.data.BooleanToggle;
+import bjc.data.BooleanToggle;
/**
* A block reader that toggles between two sources.
diff --git a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java
index f0221be..7ad8b91 100644
--- a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java
+++ b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java
@@ -6,10 +6,10 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.ITree;
-import bjc.utils.data.Pair;
-import bjc.utils.data.Tree;
+import bjc.data.IHolder;
+import bjc.data.ITree;
+import bjc.data.Pair;
+import bjc.data.Tree;
import bjc.utils.parserutils.TreeConstructor.ConstructorState;
import bjc.utils.parserutils.TreeConstructor.QueueFlattener;
diff --git a/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java b/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java
index 59bd56e..2b3a831 100644
--- a/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java
+++ b/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java
@@ -5,11 +5,11 @@ import java.util.LinkedList;
import java.util.function.Function;
import java.util.function.Predicate;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.ITree;
-import bjc.utils.data.Identity;
-import bjc.utils.data.Pair;
+import bjc.data.IHolder;
+import bjc.data.IPair;
+import bjc.data.ITree;
+import bjc.data.Identity;
+import bjc.data.Pair;
import bjc.utils.funcdata.IList;
/**
diff --git a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java
index 3d279d8..a939971 100644
--- a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java
+++ b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java
@@ -6,7 +6,7 @@ import java.util.function.UnaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import bjc.utils.data.CircularIterator;
+import bjc.data.CircularIterator;
/**
* An iterated find/replace, using a circular assortment of replacements.
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
index e89ba08..72184b6 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
@@ -11,10 +11,10 @@ import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.Function;
-import bjc.utils.data.IPair;
-import bjc.utils.data.ITree;
-import bjc.utils.data.Pair;
-import bjc.utils.data.Tree;
+import bjc.data.IPair;
+import bjc.data.ITree;
+import bjc.data.Pair;
+import bjc.data.Tree;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java b/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java
index a84b148..64dc81c 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java
@@ -4,8 +4,8 @@ import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Pair;
+import bjc.data.IPair;
+import bjc.data.Pair;
/**
* A predicated opener for use with {@link RegexCloser}
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
index ff4b348..1dfefef 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
@@ -9,9 +9,9 @@ import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
-import bjc.utils.data.IPair;
-import bjc.utils.data.ITree;
-import bjc.utils.data.Tree;
+import bjc.data.IPair;
+import bjc.data.ITree;
+import bjc.data.Tree;
import bjc.utils.esodata.PushdownMap;
import bjc.utils.esodata.SimpleStack;
import bjc.utils.esodata.Stack;
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java b/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java
index 10c680c..1f8f166 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java
@@ -1,6 +1,6 @@
package bjc.utils.parserutils.delims;
-import bjc.utils.data.ITree;
+import bjc.data.ITree;
/**
* A sequence delimiter specialized for strings.