summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:40:33 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:40:33 -0400
commit889fac2bdf993dc86f64a8893c0260fdcf848acb (patch)
tree99ed08552efa86fdc5fdf4ddb8720d10e599fafe /BJC-Utils2/src/main/java/bjc/utils/data
parent1656b02144446aeedebb3d1179e07ed99c01861c (diff)
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BooleanToggle.java22
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java17
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Either.java96
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java18
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IPair.java24
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ITree.java64
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Identity.java41
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java84
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java105
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java47
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Option.java42
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java71
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Toggle.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java92
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/TransformIterator.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Tree.java142
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ValueToggle.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java35
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java99
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java34
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java75
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java34
25 files changed, 573 insertions, 665 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BooleanToggle.java b/BJC-Utils2/src/main/java/bjc/utils/data/BooleanToggle.java
index 68399a0..12e3b2e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BooleanToggle.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BooleanToggle.java
@@ -2,7 +2,7 @@ package bjc.utils.data;
/**
* A simple {@link ValueToggle} that swaps between true and false.
- *
+ *
* @author EVE
*
*/
@@ -18,17 +18,17 @@ public class BooleanToggle implements Toggle<Boolean> {
/**
* Create a flip-flop with the specified initial value.
- *
+ *
* @param initial
* The initial value of the flip-flop.
*/
- public BooleanToggle(boolean initial) {
+ public BooleanToggle(final boolean initial) {
val = initial;
}
@Override
public Boolean get() {
- boolean res = val;
+ final boolean res = val;
val = !res;
@@ -41,7 +41,7 @@ public class BooleanToggle implements Toggle<Boolean> {
}
@Override
- public void set(boolean vl) {
+ public void set(final boolean vl) {
val = vl;
}
@@ -57,14 +57,14 @@ public class BooleanToggle implements Toggle<Boolean> {
}
@Override
- public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof BooleanToggle)) return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof BooleanToggle)) return false;
- BooleanToggle other = (BooleanToggle) obj;
+ final BooleanToggle other = (BooleanToggle) obj;
- if(val != other.val) return false;
+ if (val != other.val) return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java
index 4b84243..a708eba 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java
@@ -4,7 +4,7 @@ import java.util.Iterator;
/**
* An iterator that repeats elements from a provided iterable.
- *
+ *
* @author EVE
*
* @param <E>
@@ -30,15 +30,15 @@ public class CircularIterator<E> implements Iterator<E> {
/**
* 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(Iterable<E> src, boolean circ) {
+ public CircularIterator(final Iterable<E> src, final boolean circ) {
source = src;
curr = source.iterator();
@@ -47,11 +47,11 @@ public class CircularIterator<E> implements Iterator<E> {
/**
* Create a new circular iterator that does actual circular iteration.
- *
+ *
* @param src
* The iterable to iterate from.
*/
- public CircularIterator(Iterable<E> src) {
+ public CircularIterator(final Iterable<E> src) {
this(src, true);
}
@@ -64,10 +64,9 @@ public class CircularIterator<E> implements Iterator<E> {
@Override
public E next() {
if (!curr.hasNext()) {
- if (doCircle)
+ if (doCircle) {
curr = source.iterator();
- else
- return curElm;
+ } else return curElm;
}
curElm = curr.next();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
index d07fbbe..36b3324 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
@@ -25,7 +25,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
* The value to put on the left
* @return An either with the left side occupied
*/
- public static <LeftType, RightType> Either<LeftType, RightType> left(LeftType left) {
+ public static <LeftType, RightType> Either<LeftType, RightType> left(final LeftType left) {
return new Either<>(left, null);
}
@@ -40,7 +40,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
* The value to put on the right
* @return An either with the right side occupied
*/
- public static <LeftType, RightType> Either<LeftType, RightType> right(RightType right) {
+ public static <LeftType, RightType> Either<LeftType, RightType> right(final RightType right) {
return new Either<>(null, right);
}
@@ -50,7 +50,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
private boolean isLeft;
- private Either(LeftType left, RightType right) {
+ private Either(final LeftType left, final RightType right) {
if (left == null) {
rightVal = right;
} else {
@@ -62,53 +62,46 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- if (binder == null)
- throw new NullPointerException("Binder must not be null");
+ 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(
- Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if (leftBinder == null)
- throw new NullPointerException("Left binder must not be null");
+ 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);
+ if (isLeft) return leftBinder.apply(leftVal);
return new Either<>(null, rightVal);
}
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
- Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if (rightBinder == null)
- throw new NullPointerException("Right binder must not be null");
+ 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);
+ if (isLeft) return new Either<>(leftVal, null);
return rightBinder.apply(rightVal);
}
@Override
public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
+ 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");
+ else if (rightCombiner == null) throw new NullPointerException("Right combiner must not be null");
- if (isLeft)
- return otherPair.bind((otherLeft, otherRight) -> {
- return new Either<>(leftCombiner.apply(leftVal, otherLeft), null);
- });
+ if (isLeft) return otherPair.bind((otherLeft, otherRight) -> {
+ return new Either<>(leftCombiner.apply(leftVal, otherLeft), null);
+ });
return otherPair.bind((otherLeft, otherRight) -> {
return new Either<>(null, rightCombiner.apply(rightVal, otherRight));
@@ -116,31 +109,26 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
}
@Override
- public <NewLeft> IPair<NewLeft, RightType> mapLeft(Function<LeftType, NewLeft> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ 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);
+ if (isLeft) return new Either<>(mapper.apply(leftVal), null);
return new Either<>(null, rightVal);
}
@Override
- public <NewRight> IPair<LeftType, NewRight> mapRight(Function<RightType, NewRight> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ 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);
+ if (isLeft) return new Either<>(leftVal, null);
return new Either<>(null, mapper.apply(rightVal));
}
@Override
- public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger) {
- if (merger == null)
- throw new NullPointerException("Merger must not be null");
+ 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);
}
@@ -151,37 +139,29 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
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());
+ result = prime * result + (leftVal == null ? 0 : leftVal.hashCode());
+ result = prime * result + (rightVal == null ? 0 : rightVal.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Either<?, ?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Either<?, ?>)) return false;
- Either<?, ?> other = (Either<?, ?>) obj;
+ final Either<?, ?> other = (Either<?, ?>) obj;
- if (isLeft != other.isLeft)
- return false;
+ if (isLeft != other.isLeft) return false;
if (leftVal == null) {
- if (other.leftVal != null)
- return false;
- } else if (!leftVal.equals(other.leftVal))
- return false;
+ 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;
+ if (other.rightVal != null) return false;
+ } else if (!rightVal.equals(other.rightVal)) return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
index 1d380c8..ca0b2ba 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
@@ -1,15 +1,15 @@
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;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
/**
* A holder of a single value.
*
@@ -36,7 +36,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
* @param action
* The action to apply to the value
*/
- public default void doWith(Consumer<? super ContainedType> action) {
+ public default void doWith(final Consumer<? super ContainedType> action) {
transform(value -> {
action.accept(value);
@@ -46,15 +46,15 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
@Override
default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap(
- Function<ArgType, ReturnType> func) {
+ final Function<ArgType, ReturnType> func) {
return argumentFunctor -> {
if (!(argumentFunctor instanceof IHolder<?>)) {
- String msg = "This functor only supports mapping over instances of IHolder";
+ final String msg = "This functor only supports mapping over instances of IHolder";
throw new IllegalArgumentException(msg);
}
- IHolder<ArgType> holder = (IHolder<ArgType>) argumentFunctor;
+ final IHolder<ArgType> holder = (IHolder<ArgType>) argumentFunctor;
return holder.map(func);
};
@@ -124,7 +124,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
* The value to hold instead
* @return The holder itself
*/
- public default IHolder<ContainedType> replace(ContainedType newValue) {
+ public default IHolder<ContainedType> replace(final ContainedType newValue) {
return transform(oldValue -> {
return newValue;
});
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
index ae54a88..db8a1cb 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
@@ -1,11 +1,11 @@
package bjc.utils.data;
-import bjc.utils.funcdata.theory.Bifunctor;
-
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
*
@@ -67,7 +67,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
* @return The pairs, pairwise combined together
*/
public default <OtherLeft, OtherRight> IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> combine(
- IPair<OtherLeft, OtherRight> otherPair) {
+ final IPair<OtherLeft, OtherRight> otherPair) {
return combine(otherPair, Pair<LeftType, OtherLeft>::new, Pair<RightType, OtherRight>::new);
}
@@ -100,7 +100,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
* @param consumer
* The action to perform on the pair
*/
- public default void doWith(BiConsumer<LeftType, RightType> consumer) {
+ public default void doWith(final BiConsumer<LeftType, RightType> consumer) {
merge((leftValue, rightValue) -> {
consumer.accept(leftValue, rightValue);
@@ -110,15 +110,15 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
@Override
default <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> fmapLeft(
- Function<OldLeft, NewLeft> func) {
+ final Function<OldLeft, NewLeft> func) {
return argumentPair -> {
- if(!(argumentPair instanceof IPair<?, ?>)) {
- String msg = "This function can only be applied to instances of IPair";
+ if (!(argumentPair instanceof IPair<?, ?>)) {
+ final String msg = "This function can only be applied to instances of IPair";
throw new IllegalArgumentException(msg);
}
- IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
+ final IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
return argPair.mapLeft(func);
};
@@ -127,15 +127,15 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
@Override
default <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight>
- fmapRight(Function<OldRight, NewRight> func) {
+ fmapRight(final Function<OldRight, NewRight> func) {
return argumentPair -> {
- if(!(argumentPair instanceof IPair<?, ?>)) {
- String msg = "This function can only be applied to instances of IPair";
+ if (!(argumentPair instanceof IPair<?, ?>)) {
+ final String msg = "This function can only be applied to instances of IPair";
throw new IllegalArgumentException(msg);
}
- IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
+ final IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
return argPair.mapRight(func);
};
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java
index 166fe3f..ff374e8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java
@@ -1,18 +1,18 @@
package bjc.utils.data;
-import bjc.utils.funcdata.bst.TreeLinearizationMethod;
-import bjc.utils.functypes.ListFlattener;
-
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
+import bjc.utils.funcdata.bst.TreeLinearizationMethod;
+import bjc.utils.functypes.ListFlattener;
+
/**
* 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.
*
@@ -28,7 +28,7 @@ public interface ITree<ContainedType> {
/**
* Prepend a child to this node.
- *
+ *
* @param child
* The child to prepend to this node.
*/
@@ -39,21 +39,21 @@ public interface ITree<ContainedType> {
*
* @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,
@@ -74,13 +74,13 @@ public interface ITree<ContainedType> {
*
* @param mapper
* The function to use to map values into trees.
- *
+ *
* @return A tree, with some nodes expanded into trees.
*/
- default ITree<ContainedType> flatMapTree(Function<ContainedType, ITree<ContainedType>> mapper) {
+ default ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) {
return topDownTransform(dat -> TopDownTransformResult.PUSHDOWN, node -> {
if (node.getChildrenCount() > 0) {
- ITree<ContainedType> parent = node.transformHead(mapper);
+ final ITree<ContainedType> parent = node.transformHead(mapper);
node.doForChildren(parent::addChild);
@@ -96,10 +96,10 @@ public interface ITree<ContainedType> {
*
* @param childNo
* The number of the child to get.
- *
+ *
* @return The specified child of this tree.
*/
- default ITree<ContainedType> getChild(int childNo) {
+ default ITree<ContainedType> getChild(final int childNo) {
return transformChild(childNo, child -> child);
}
@@ -124,13 +124,13 @@ public interface ITree<ContainedType> {
*
* @param <MappedType>
* The type of the new tree.
- *
+ *
* @param leafTransformer
* The function to use to transform leaf tokens.
- *
+ *
* @param operatorTransformer
* The function to use to transform internal tokens.
- *
+ *
* @return The tree, with the nodes changed.
*/
<MappedType> ITree<MappedType> rebuildTree(Function<ContainedType, MappedType> leafTransformer,
@@ -141,7 +141,7 @@ public interface ITree<ContainedType> {
*
* @param nodePicker
* The predicate to use to pick nodes to transform.
- *
+ *
* @param transformer
* The function to use to transform picked nodes.
*/
@@ -152,10 +152,10 @@ public interface ITree<ContainedType> {
*
* @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,
@@ -166,13 +166,13 @@ public interface ITree<ContainedType> {
*
* @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
@@ -187,10 +187,10 @@ public interface ITree<ContainedType> {
*
* @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);
@@ -200,13 +200,13 @@ public interface ITree<ContainedType> {
*
* @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(Function<ContainedType, MappedType> transformer) {
+ default <MappedType> ITree<MappedType> transformTree(final Function<ContainedType, MappedType> transformer) {
return rebuildTree(transformer, transformer);
}
@@ -215,7 +215,7 @@ public interface ITree<ContainedType> {
*
* @param linearizationMethod
* The way to traverse the tree.
- *
+ *
* @param action
* The action to perform on each tree node.
*/
@@ -223,10 +223,10 @@ public interface ITree<ContainedType> {
/**
* 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.
*/
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java
index 77e13cf..a8c8d70 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java
@@ -32,12 +32,12 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
* @param value
* The value to hold
*/
- public Identity(ContainedType value) {
+ public Identity(final ContainedType value) {
heldValue = value;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
+ public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
return binder.apply(heldValue);
}
@@ -46,40 +46,35 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
final int prime = 31;
int result = 1;
- result = prime * result + ((heldValue == null) ? 0 : heldValue.hashCode());
+ result = prime * result + (heldValue == null ? 0 : heldValue.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Identity))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Identity)) return false;
- Identity<?> other = (Identity<?>) obj;
+ final Identity<?> other = (Identity<?>) obj;
if (heldValue == null) {
- if (other.heldValue != null)
- return false;
- } else if (!heldValue.equals(other.heldValue))
- return false;
+ if (other.heldValue != null) return false;
+ } else if (!heldValue.equals(other.heldValue)) return false;
return true;
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
+ 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(Function<ContainedType, MappedType> mapper) {
+ public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
return new Identity<>(mapper.apply(heldValue));
}
@@ -89,32 +84,32 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
heldValue = transformer.apply(heldValue);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
+ 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(ContainedType val) {
+ 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() {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
index 719b11f..ca41b62 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
@@ -1,13 +1,13 @@
package bjc.utils.data;
-import bjc.utils.data.internals.BoundLazy;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
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
@@ -31,7 +31,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
* @param value
* The seed value to use
*/
- public Lazy(ContainedType value) {
+ public Lazy(final ContainedType value) {
heldValue = value;
valueMaterialized = true;
@@ -43,27 +43,26 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
* @param supp
* The source of a value to use
*/
- public Lazy(Supplier<ContainedType> supp) {
+ public Lazy(final Supplier<ContainedType> supp) {
valueSupplier = new SingleSupplier<>(supp);
valueMaterialized = false;
}
- private Lazy(Supplier<ContainedType> supp, IList<UnaryOperator<ContainedType>> pendingActions) {
+ private Lazy(final Supplier<ContainedType> supp, final IList<UnaryOperator<ContainedType>> pendingActions) {
valueSupplier = supp;
actions = pendingActions;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
+ public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
+ final IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
- Supplier<ContainedType> supplier = () -> {
- if (valueMaterialized)
- return heldValue;
+ final Supplier<ContainedType> supplier = () -> {
+ if (valueMaterialized) return heldValue;
return valueSupplier.get();
};
@@ -74,15 +73,15 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
+ 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(Function<ContainedType, MappedType> mapper) {
- IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
+ public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
+ final IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
@@ -103,22 +102,21 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
if (valueMaterialized) {
if (actions.isEmpty())
return String.format("value[v='%s']", heldValue);
- else
- return String.format("value[v='%s'] (has pending transforms)", heldValue);
+ else return String.format("value[v='%s'] (has pending transforms)", heldValue);
}
return "(unmaterialized)";
}
@Override
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
actions.add(transformer);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
if (!valueMaterialized) {
heldValue = valueSupplier.get();
@@ -139,68 +137,58 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
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 + (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(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Lazy<?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Lazy<?>)) return false;
- Lazy<?> other = (Lazy<?>) obj;
+ final Lazy<?> other = (Lazy<?>) obj;
- if (valueMaterialized != other.valueMaterialized)
- return false;
+ 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 (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;
+ 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(ContainedType val) {
+ 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(Supplier<ContainedType> supp) {
+ public static <ContainedType> Lazy<ContainedType> lazy(final Supplier<ContainedType> supp) {
return new Lazy<>(supp);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java
index 70768be..5cb85f3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java
@@ -1,12 +1,12 @@
package bjc.utils.data;
-import bjc.utils.data.internals.BoundLazyPair;
-import bjc.utils.data.internals.HalfBoundLazyPair;
-
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
*
@@ -36,7 +36,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
* @param rightVal
* The value for the right side of the pair
*/
- public LazyPair(LeftType leftVal, RightType rightVal) {
+ public LazyPair(final LeftType leftVal, final RightType rightVal) {
leftValue = leftVal;
rightValue = rightVal;
@@ -52,7 +52,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
* @param rightSupp
* The source for a value on the right side of the pair
*/
- public LazyPair(Supplier<LeftType> leftSupp, Supplier<RightType> rightSupp) {
+ 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);
@@ -63,16 +63,15 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
+ final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
return new BoundLazyPair<>(leftSupplier, rightSupplier, binder);
}
@Override
public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
- Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- Supplier<LeftType> leftSupp = () -> {
- if (leftMaterialized)
- return leftValue;
+ final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
+ final Supplier<LeftType> leftSupp = () -> {
+ if (leftMaterialized) return leftValue;
return leftSupplier.get();
};
@@ -82,10 +81,9 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
- Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- Supplier<RightType> rightSupp = () -> {
- if (rightMaterialized)
- return rightValue;
+ final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
+ final Supplier<RightType> rightSupp = () -> {
+ if (rightMaterialized) return rightValue;
return rightSupplier.get();
};
@@ -95,13 +93,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
+ 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) -> {
- CombinedLeft left = leftCombiner.apply(leftVal, otherLeft);
- CombinedRight right = rightCombiner.apply(rightVal, otherRight);
+ final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft);
+ final CombinedRight right = rightCombiner.apply(rightVal, otherRight);
return new LazyPair<>(left, right);
});
@@ -131,17 +129,15 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
}
@Override
- public <NewLeft> IPair<NewLeft, RightType> mapLeft(Function<LeftType, NewLeft> mapper) {
- Supplier<NewLeft> leftSupp = () -> {
- if (leftMaterialized)
- return mapper.apply(leftValue);
+ 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());
};
- Supplier<RightType> rightSupp = () -> {
- if (rightMaterialized)
- return rightValue;
+ final Supplier<RightType> rightSupp = () -> {
+ if (rightMaterialized) return rightValue;
return rightSupplier.get();
};
@@ -150,17 +146,15 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
}
@Override
- public <NewRight> IPair<LeftType, NewRight> mapRight(Function<RightType, NewRight> mapper) {
- Supplier<LeftType> leftSupp = () -> {
- if (leftMaterialized)
- return leftValue;
+ public <NewRight> IPair<LeftType, NewRight> mapRight(final Function<RightType, NewRight> mapper) {
+ final Supplier<LeftType> leftSupp = () -> {
+ if (leftMaterialized) return leftValue;
return leftSupplier.get();
};
- Supplier<NewRight> rightSupp = () -> {
- if (rightMaterialized)
- return mapper.apply(rightValue);
+ final Supplier<NewRight> rightSupp = () -> {
+ if (rightMaterialized) return mapper.apply(rightValue);
return mapper.apply(rightSupplier.get());
};
@@ -169,7 +163,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
}
@Override
- public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger) {
+ public <MergedType> MergedType merge(final BiFunction<LeftType, RightType, MergedType> merger) {
if (!leftMaterialized) {
leftValue = leftSupplier.get();
@@ -211,48 +205,35 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
int result = 1;
result = prime * result + (leftMaterialized ? 1231 : 1237);
- result = prime * result + ((leftValue == null) ? 0 : leftValue.hashCode());
+ result = prime * result + (leftValue == null ? 0 : leftValue.hashCode());
result = prime * result + (rightMaterialized ? 1231 : 1237);
- result = prime * result + ((rightValue == null) ? 0 : rightValue.hashCode());
+ result = prime * result + (rightValue == null ? 0 : rightValue.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof LazyPair<?, ?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof LazyPair<?, ?>)) return false;
- LazyPair<?, ?> other = (LazyPair<?, ?>) obj;
+ final LazyPair<?, ?> other = (LazyPair<?, ?>) obj;
- if (leftMaterialized != other.leftMaterialized)
- return false;
+ 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 (other.leftValue != null) return false;
+ } else if (!leftValue.equals(other.leftValue)) return false;
+ } else return false;
- if (rightMaterialized != other.rightMaterialized)
- 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;
- }
+ if (other.rightValue != null) return false;
+ } else if (!rightValue.equals(other.rightValue)) return false;
+ } else return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
index 8807312..142057c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
@@ -1,12 +1,12 @@
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;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
/**
* A holder that represents a set of non-deterministic computations
*
@@ -25,50 +25,50 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
* The possible values for the computation
*/
@SafeVarargs
- public ListHolder(ContainedType... values) {
+ public ListHolder(final ContainedType... values) {
heldValues = new FunctionalList<>();
if (values != null) {
- for (ContainedType containedValue : values) {
+ for (final ContainedType containedValue : values) {
heldValues.add(containedValue);
}
}
}
- private ListHolder(IList<ContainedType> toHold) {
+ private ListHolder(final IList<ContainedType> toHold) {
heldValues = toHold;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- IList<IHolder<BoundType>> boundValues = heldValues.map(binder);
+ 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(Function<ContainedType, NewType> func) {
+ 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(Function<ContainedType, MappedType> mapper) {
- IList<MappedType> mappedValues = heldValues.map(mapper);
+ 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(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
heldValues = heldValues.map(transformer);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
return unwrapper.apply(heldValues.randItem());
}
@@ -82,27 +82,22 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
final int prime = 31;
int result = 1;
- result = prime * result + ((heldValues == null) ? 0 : heldValues.hashCode());
+ result = prime * result + (heldValues == null ? 0 : heldValues.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof ListHolder<?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof ListHolder<?>)) return false;
- ListHolder<?> other = (ListHolder<?>) obj;
+ final ListHolder<?> other = (ListHolder<?>) obj;
if (heldValues == null) {
- if (other.heldValues != null)
- return false;
- } else if (!heldValues.equals(other.heldValues))
- return false;
+ if (other.heldValues != null) return false;
+ } else if (!heldValues.equals(other.heldValues)) return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
index 718ab6e..37e0cde 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
@@ -20,35 +20,33 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
* @param seed
* The initial value for the optional
*/
- public Option(ContainedType seed) {
+ public Option(final ContainedType seed) {
held = seed;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- if (held == null)
- return new Option<>(null);
+ 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(Function<ContainedType, NewType> func) {
+ 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(Function<ContainedType, MappedType> mapper) {
- if (held == null)
- return new Option<>(null);
+ 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(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
if (held != null) {
held = transformer.apply(held);
}
@@ -57,9 +55,8 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
- if (held == null)
- return null;
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
+ if (held == null) return null;
return unwrapper.apply(held);
}
@@ -74,27 +71,22 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
final int prime = 31;
int result = 1;
- result = prime * result + ((held == null) ? 0 : held.hashCode());
+ result = prime * result + (held == null ? 0 : held.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Option<?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Option<?>)) return false;
- Option<?> other = (Option<?>) obj;
+ final Option<?> other = (Option<?>) obj;
if (held == null) {
- if (other.held != null)
- return false;
- } else if (!held.equals(other.held))
- return false;
+ if (other.held != null) return false;
+ } else if (!held.equals(other.held)) return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
index 2fc3106..e6796ba 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -35,71 +35,65 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
* @param right
* The value of the right side
*/
- public Pair(LeftType left, RightType right) {
+ public Pair(final LeftType left, final RightType right) {
leftValue = left;
rightValue = right;
}
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- if (binder == null)
- throw new NullPointerException("Binder must not be null.");
+ 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(
- Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if (leftBinder == null)
- throw new NullPointerException("Binder must not be null");
+ 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(
- Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if (rightBinder == null)
- throw new NullPointerException("Binder must not be null");
+ 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(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
+ final IPair<OtherLeft, OtherRight> otherPair,
+ final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
+ final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
return otherPair.bind((otherLeft, otherRight) -> {
- CombinedLeft left = leftCombiner.apply(leftValue, otherLeft);
- CombinedRight right = rightCombiner.apply(rightValue, 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(Function<LeftType, NewLeft> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ 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(Function<RightType, NewRight> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ 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(BiFunction<LeftType, RightType, MergedType> merger) {
- if (merger == null)
- throw new NullPointerException("Merger must not be null");
+ 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);
}
@@ -114,34 +108,27 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
final int prime = 31;
int result = 1;
- result = prime * result + ((leftValue == null) ? 0 : leftValue.hashCode());
- result = prime * result + ((rightValue == null) ? 0 : rightValue.hashCode());
+ result = prime * result + (leftValue == null ? 0 : leftValue.hashCode());
+ result = prime * result + (rightValue == null ? 0 : rightValue.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Pair<?, ?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Pair<?, ?>)) return false;
- Pair<?, ?> other = (Pair<?, ?>) obj;
+ final Pair<?, ?> other = (Pair<?, ?>) obj;
if (leftValue == null) {
- if (other.leftValue != null)
- return false;
- } else if (!leftValue.equals(other.leftValue))
- return false;
+ 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;
+ if (other.rightValue != null) return false;
+ } else if (!rightValue.equals(other.rightValue)) return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java
index 0ddb324..4069c3f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java
@@ -4,24 +4,24 @@ 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> {
- private T itm;
+ private final T itm;
private boolean yielded;
/**
* Create a iterator that yields a single item.
- *
+ *
* @param item
* The item to yield.
*/
- public SingleIterator(T item) {
+ public SingleIterator(final T item) {
itm = item;
yielded = false;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java
index fde5111..c675ebf 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java
@@ -15,11 +15,11 @@ import java.util.function.Supplier;
public class SingleSupplier<T> implements Supplier<T> {
private static long nextID = 0;
- private Supplier<T> source;
+ private final Supplier<T> source;
private boolean gotten;
- private long id;
+ private final long id;
/*
* This is bad practice, but I want to know where the single
@@ -33,7 +33,7 @@ public class SingleSupplier<T> implements Supplier<T> {
* @param supp
* The supplier to give a single value from
*/
- public SingleSupplier(Supplier<T> supp) {
+ public SingleSupplier(final Supplier<T> supp) {
source = supp;
gotten = false;
@@ -44,10 +44,10 @@ public class SingleSupplier<T> implements Supplier<T> {
@Override
public T get() {
if (gotten == true) {
- String msg = String.format(
+ final String msg = String.format(
"Attempted to retrieve value more than once from single supplier #%d", id);
- IllegalStateException isex = new IllegalStateException(msg);
+ final IllegalStateException isex = new IllegalStateException(msg);
isex.initCause(instSite);
@@ -58,7 +58,7 @@ public class SingleSupplier<T> implements Supplier<T> {
try {
throw new IllegalStateException("Previous instantiation here.");
- } catch (IllegalStateException isex) {
+ } catch (final IllegalStateException isex) {
instSite = isex;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Toggle.java b/BJC-Utils2/src/main/java/bjc/utils/data/Toggle.java
index 8ebc4d8..1e10dae 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Toggle.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Toggle.java
@@ -2,7 +2,7 @@ package bjc.utils.data;
/**
* A stateful holder that swaps between two values of the same type.
- *
+ *
* @author EVE
*
* @param <E>
@@ -12,21 +12,21 @@ public interface Toggle<E> {
/**
* Retrieve the currently-aligned value of this toggle, and swap the
* alignment.
- *
+ *
* @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.
*/
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java
index 14548a3..014458b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java
@@ -1,5 +1,7 @@
package bjc.utils.data;
+import static bjc.utils.data.TopDownTransformResult.RTRANSFORM;
+
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
@@ -8,34 +10,31 @@ import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
-import static bjc.utils.data.TopDownTransformResult.RTRANSFORM;
-
-
/*
* FIXME something is broken in here. fix it.
*/
@SuppressWarnings("javadoc")
public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<ContainedType>> {
- private Function<ContainedType, TopDownTransformResult> picker;
- private BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transform;
+ private final Function<ContainedType, TopDownTransformResult> picker;
+ private final BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transform;
private ITree<ContainedType> preParent;
private ITree<ContainedType> postParent;
- private Deque<ITree<ContainedType>> preChildren;
- private Deque<ITree<ContainedType>> postChildren;
+ private final Deque<ITree<ContainedType>> preChildren;
+ private final Deque<ITree<ContainedType>> postChildren;
private TopDownTransformIterator<ContainedType> curChild;
private boolean done;
private boolean initial;
- private Deque<Iterator<ITree<ContainedType>>> toYield;
- private Iterator<ITree<ContainedType>> curYield;
+ private final Deque<Iterator<ITree<ContainedType>>> toYield;
+ private Iterator<ITree<ContainedType>> curYield;
- public TopDownTransformIterator(Function<ContainedType, TopDownTransformResult> pickr,
- BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transfrm,
- ITree<ContainedType> tree) {
+ public TopDownTransformIterator(final Function<ContainedType, TopDownTransformResult> pickr,
+ final BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transfrm,
+ final ITree<ContainedType> tree) {
preParent = tree;
preChildren = new LinkedList<>();
@@ -49,8 +48,8 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
initial = true;
}
- public void addYield(Iterator<ITree<ContainedType>> src) {
- if(curYield != null) {
+ public void addYield(final Iterator<ITree<ContainedType>> src) {
+ if (curYield != null) {
toYield.push(curYield);
}
@@ -62,55 +61,52 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
return !done;
}
- public ITree<ContainedType> flushYields(ITree<ContainedType> val) {
- if(curYield != null) {
+ public ITree<ContainedType> flushYields(final ITree<ContainedType> val) {
+ if (curYield != null) {
toYield.add(new SingleIterator<>(val));
- if(curYield.hasNext())
+ if (curYield.hasNext())
return curYield.next();
else {
- while(toYield.size() != 0 && !curYield.hasNext()) {
+ while (toYield.size() != 0 && !curYield.hasNext()) {
curYield = toYield.pop();
}
- if(toYield.size() == 0 && !curYield.hasNext()) {
+ if (toYield.size() == 0 && !curYield.hasNext()) {
curYield = null;
return val;
- } else
- return curYield.next();
+ } else return curYield.next();
}
- } else
- return val;
+ } else return val;
}
@Override
public ITree<ContainedType> next() {
- if(done) throw new NoSuchElementException();
+ if (done) throw new NoSuchElementException();
- if(curYield != null) {
- if(curYield.hasNext())
+ if (curYield != null) {
+ if (curYield.hasNext())
return curYield.next();
else {
- while(toYield.size() != 0 && !curYield.hasNext()) {
+ while (toYield.size() != 0 && !curYield.hasNext()) {
curYield = toYield.pop();
}
- if(toYield.size() == 0 && !curYield.hasNext()) {
+ if (toYield.size() == 0 && !curYield.hasNext()) {
curYield = null;
- } else
- return curYield.next();
+ } else return curYield.next();
}
}
- if(initial) {
- TopDownTransformResult res = picker.apply(preParent.getHead());
+ if (initial) {
+ final TopDownTransformResult res = picker.apply(preParent.getHead());
- switch(res) {
+ switch (res) {
case PASSTHROUGH:
postParent = new Tree<>(preParent.getHead());
- if(preParent.getChildrenCount() != 0) {
- for(int i = 0; i < preParent.getChildrenCount(); i++) {
+ if (preParent.getChildrenCount() != 0) {
+ for (int i = 0; i < preParent.getChildrenCount(); i++) {
preChildren.add(preParent.getChild(i));
}
@@ -130,8 +126,8 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
preParent = transform.apply(preParent, this::addYield);
return flushYields(preParent);
case PUSHDOWN:
- if(preParent.getChildrenCount() != 0) {
- for(int i = 0; i < preParent.getChildrenCount(); i++) {
+ if (preParent.getChildrenCount() != 0) {
+ for (int i = 0; i < preParent.getChildrenCount(); i++) {
preChildren.add(preParent.getChild(i));
}
@@ -143,12 +139,12 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
this::addYield));
}
case PULLUP:
- ITree<ContainedType> intRes = transform.apply(preParent, this::addYield);
+ 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++) {
+ if (intRes.getChildrenCount() != 0) {
+ for (int i = 0; i < intRes.getChildrenCount(); i++) {
preChildren.add(intRes.getChild(i));
}
@@ -162,16 +158,16 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
throw new IllegalArgumentException("Unknown result type " + res);
}
- if(res != RTRANSFORM) {
+ if (res != RTRANSFORM) {
initial = false;
}
}
- if(curChild == null || !curChild.hasNext()) {
- if(preChildren.size() != 0) {
+ if (curChild == null || !curChild.hasNext()) {
+ if (preChildren.size() != 0) {
curChild = new TopDownTransformIterator<>(picker, transform, preChildren.pop());
- ITree<ContainedType> res = curChild.next();
+ final ITree<ContainedType> res = curChild.next();
System.out.println("\t\tTRACE: adding node " + res + " to children");
postChildren.add(res);
@@ -179,12 +175,12 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
} else {
ITree<ContainedType> res = null;
- if(postParent == null) {
+ if (postParent == null) {
res = new Tree<>(preParent.getHead());
System.out.println("\t\tTRACE: adding nodes " + postChildren + " to " + res);
- for(ITree<ContainedType> child : postChildren) {
+ for (final ITree<ContainedType> child : postChildren) {
res.addChild(child);
}
@@ -194,7 +190,7 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
res = postParent;
System.out.println("\t\tTRACE: adding nodes " + postChildren + " to " + res);
- for(ITree<ContainedType> child : postChildren) {
+ for (final ITree<ContainedType> child : postChildren) {
res.addChild(child);
}
}
@@ -203,7 +199,7 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
return flushYields(res);
}
} else {
- ITree<ContainedType> res = curChild.next();
+ final ITree<ContainedType> res = curChild.next();
System.out.println("\t\tTRACE: adding node " + res + " to children");
postChildren.add(res);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TransformIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/TransformIterator.java
index a0987af..50f28b1 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/TransformIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/TransformIterator.java
@@ -5,30 +5,30 @@ 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> {
- private Iterator<S> source;
+ private final Iterator<S> source;
- private Function<S, D> transform;
+ 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(Iterator<S> source, Function<S, D> transform) {
+ public TransformIterator(final Iterator<S> source, final Function<S, D> transform) {
this.source = source;
this.transform = transform;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
index 0dc96eb..a52f699 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
@@ -1,15 +1,15 @@
package bjc.utils.data;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-import bjc.utils.funcdata.bst.TreeLinearizationMethod;
-import bjc.utils.functypes.ListFlattener;
-
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;
+import bjc.utils.functypes.ListFlattener;
+
/**
* A node in a homogeneous tree.
*
@@ -33,7 +33,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
* @param leaf
* The data to store as a leaf node.
*/
- public Tree(ContainedType leaf) {
+ public Tree(final ContainedType leaf) {
data = leaf;
hasChildren = false;
@@ -46,11 +46,11 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
*
* @param leaf
* The data to hold in this node.
- *
+ *
* @param childrn
* A list of children for this node.
*/
- public Tree(ContainedType leaf, IList<ITree<ContainedType>> childrn) {
+ public Tree(final ContainedType leaf, final IList<ITree<ContainedType>> childrn) {
this(leaf);
hasChildren = true;
@@ -65,12 +65,12 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
*
* @param leaf
* The data to hold in this node.
- *
+ *
* @param childrn
* A list of children for this node.
*/
@SafeVarargs
- public Tree(ContainedType leaf, ITree<ContainedType>... childrn) {
+ public Tree(final ContainedType leaf, final ITree<ContainedType>... childrn) {
this(leaf);
hasChildren = true;
@@ -79,7 +79,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
children = new FunctionalList<>();
- for (ITree<ContainedType> child : childrn) {
+ for (final ITree<ContainedType> child : childrn) {
children.add(child);
childCount++;
@@ -87,7 +87,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public void addChild(ITree<ContainedType> child) {
+ public void addChild(final ITree<ContainedType> child) {
if (hasChildren == false) {
hasChildren = true;
@@ -100,7 +100,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public void prependChild(ITree<ContainedType> child) {
+ public void prependChild(final ITree<ContainedType> child) {
if (hasChildren == false) {
hasChildren = true;
@@ -113,7 +113,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public void doForChildren(Consumer<ITree<ContainedType>> action) {
+ public void doForChildren(final Consumer<ITree<ContainedType>> action) {
if (childCount > 0) {
children.forEach(action);
}
@@ -125,14 +125,12 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public int revFind(Predicate<ITree<ContainedType>> childPred) {
- if (childCount == 0) {
+ public int revFind(final Predicate<ITree<ContainedType>> childPred) {
+ if (childCount == 0)
return -1;
- } else {
+ else {
for (int i = childCount - 1; i >= 0; i--) {
- if (childPred.test(getChild(i))) {
- return i;
- }
+ if (childPred.test(getChild(i))) return i;
}
}
@@ -140,12 +138,12 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public void traverse(TreeLinearizationMethod linearizationMethod, Consumer<ContainedType> action) {
+ public void traverse(final TreeLinearizationMethod linearizationMethod, final Consumer<ContainedType> action) {
if (hasChildren) {
switch (linearizationMethod) {
case INORDER:
if (childCount != 2) {
- String msg = "Can only do in-order traversal for binary trees.";
+ final String msg = "Can only do in-order traversal for binary trees.";
throw new IllegalArgumentException(msg);
}
@@ -176,18 +174,19 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public <NewType, ReturnedType> ReturnedType collapse(Function<ContainedType, NewType> leafTransform,
- Function<ContainedType, ListFlattener<NewType>> nodeCollapser,
- Function<NewType, ReturnedType> resultTransformer) {
+ public <NewType, ReturnedType> ReturnedType collapse(final Function<ContainedType, NewType> leafTransform,
+ final Function<ContainedType, ListFlattener<NewType>> nodeCollapser,
+ final Function<NewType, ReturnedType> resultTransformer) {
return resultTransformer.apply(internalCollapse(leafTransform, nodeCollapser));
}
@Override
- public ITree<ContainedType> flatMapTree(Function<ContainedType, ITree<ContainedType>> mapper) {
+ public ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) {
if (hasChildren) {
- ITree<ContainedType> flatMappedData = mapper.apply(data);
+ final ITree<ContainedType> flatMappedData = mapper.apply(data);
- IList<ITree<ContainedType>> mappedChildren = children.map(child -> child.flatMapTree(mapper));
+ final IList<ITree<ContainedType>> mappedChildren = children
+ .map(child -> child.flatMapTree(mapper));
mappedChildren.forEach(child -> flatMappedData.addChild(child));
@@ -197,13 +196,13 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
return mapper.apply(data);
}
- protected <NewType> NewType internalCollapse(Function<ContainedType, NewType> leafTransform,
- Function<ContainedType, ListFlattener<NewType>> nodeCollapser) {
+ protected <NewType> NewType internalCollapse(final Function<ContainedType, NewType> leafTransform,
+ final Function<ContainedType, ListFlattener<NewType>> nodeCollapser) {
if (hasChildren) {
- Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser.apply(data);
+ final Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser.apply(data);
- IList<NewType> collapsedChildren = children.map(child -> {
- NewType collapsed = child.collapse(leafTransform, nodeCollapser,
+ final IList<NewType> collapsedChildren = children.map(child -> {
+ final NewType collapsed = child.collapse(leafTransform, nodeCollapser,
subTreeVal -> subTreeVal);
return collapsed;
@@ -215,7 +214,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
return leafTransform.apply(data);
}
- protected void internalToString(StringBuilder builder, int indentLevel, boolean initial) {
+ protected void internalToString(final StringBuilder builder, final int indentLevel, final boolean initial) {
for (int i = 0; i < indentLevel; i++) {
builder.append(">\t");
}
@@ -229,7 +228,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
if (hasChildren) {
children.forEach(child -> {
if (child instanceof Tree<?>) {
- Tree<ContainedType> kid = (Tree<ContainedType>) child;
+ final Tree<ContainedType> kid = (Tree<ContainedType>) child;
kid.internalToString(builder, indentLevel + 1, false);
} else {
@@ -244,10 +243,10 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public <MappedType> ITree<MappedType> rebuildTree(Function<ContainedType, MappedType> leafTransformer,
- Function<ContainedType, MappedType> operatorTransformer) {
+ public <MappedType> ITree<MappedType> rebuildTree(final Function<ContainedType, MappedType> leafTransformer,
+ final Function<ContainedType, MappedType> operatorTransformer) {
if (hasChildren) {
- IList<ITree<MappedType>> mappedChildren = children.map(child -> {
+ final IList<ITree<MappedType>> mappedChildren = children.map(child -> {
return child.rebuildTree(leafTransformer, operatorTransformer);
});
@@ -258,7 +257,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public void selectiveTransform(Predicate<ContainedType> nodePicker, UnaryOperator<ContainedType> transformer) {
+ public void selectiveTransform(final Predicate<ContainedType> nodePicker,
+ final UnaryOperator<ContainedType> transformer) {
if (hasChildren) {
children.forEach(child -> child.selectiveTransform(nodePicker, transformer));
} else {
@@ -267,9 +267,10 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public ITree<ContainedType> topDownTransform(Function<ContainedType, TopDownTransformResult> transformPicker,
- UnaryOperator<ITree<ContainedType>> transformer) {
- TopDownTransformResult transformResult = transformPicker.apply(data);
+ public ITree<ContainedType> topDownTransform(
+ final Function<ContainedType, TopDownTransformResult> transformPicker,
+ final UnaryOperator<ITree<ContainedType>> transformer) {
+ final TopDownTransformResult transformResult = transformPicker.apply(data);
switch (transformResult) {
case PASSTHROUGH:
@@ -277,7 +278,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
if (hasChildren) {
children.forEach(child -> {
- ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer);
+ final ITree<ContainedType> kid = child.topDownTransform(transformPicker,
+ transformer);
result.addChild(kid);
});
@@ -295,7 +297,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
if (hasChildren) {
children.forEach(child -> {
- ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer);
+ final ITree<ContainedType> kid = child.topDownTransform(transformPicker,
+ transformer);
result.addChild(kid);
});
@@ -303,40 +306,41 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
return transformer.apply(result);
case PULLUP:
- ITree<ContainedType> intermediateResult = transformer.apply(this);
+ final ITree<ContainedType> intermediateResult = transformer.apply(this);
result = new Tree<>(intermediateResult.getHead());
intermediateResult.doForChildren(child -> {
- ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer);
+ final ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer);
result.addChild(kid);
});
return result;
default:
- String msg = String.format("Recieved unknown transform result %s", transformResult);
+ final String msg = String.format("Recieved unknown transform result %s", transformResult);
throw new IllegalArgumentException(msg);
}
}
@Override
- public <TransformedType> TransformedType transformChild(int childNo,
- Function<ITree<ContainedType>, TransformedType> transformer) {
+ public <TransformedType> TransformedType transformChild(final int childNo,
+ final Function<ITree<ContainedType>, TransformedType> transformer) {
if (childNo < 0 || childNo > childCount - 1) {
- String msg = String.format("Child index #%d is invalid", childNo);
+ final String msg = String.format("Child index #%d is invalid", childNo);
throw new IllegalArgumentException(msg);
}
- ITree<ContainedType> selectedKid = children.getByIndex(childNo);
+ final ITree<ContainedType> selectedKid = children.getByIndex(childNo);
return transformer.apply(selectedKid);
}
@Override
- public <TransformedType> TransformedType transformHead(Function<ContainedType, TransformedType> transformer) {
+ public <TransformedType> TransformedType transformHead(
+ final Function<ContainedType, TransformedType> transformer) {
return transformer.apply(data);
}
@@ -346,15 +350,15 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
int result = 1;
result = prime * result + childCount;
- result = prime * result + ((children == null) ? 0 : children.hashCode());
- result = prime * result + ((data == null) ? 0 : data.hashCode());
+ result = prime * result + (children == null ? 0 : children.hashCode());
+ result = prime * result + (data == null ? 0 : data.hashCode());
return result;
}
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
internalToString(builder, 1, true);
@@ -364,30 +368,22 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Tree<?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Tree<?>)) return false;
- Tree<?> other = (Tree<?>) obj;
+ final Tree<?> other = (Tree<?>) obj;
if (data == null) {
- if (other.data != null)
- return false;
- } else if (!data.equals(other.data))
- return false;
+ if (other.data != null) return false;
+ } else if (!data.equals(other.data)) return false;
- if (childCount != other.childCount)
- 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;
+ if (other.children != null) return false;
+ } else if (!children.equals(other.children)) return false;
return true;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ValueToggle.java b/BJC-Utils2/src/main/java/bjc/utils/data/ValueToggle.java
index 5b5cb83..9193896 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ValueToggle.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ValueToggle.java
@@ -2,9 +2,9 @@ package bjc.utils.data;
/**
* A simple implementation of {@link Toggle}.
- *
+ *
* @author EVE
- *
+ *
* @param <E>
* The type of value to toggle between.
*/
@@ -12,20 +12,20 @@ public class ValueToggle<E> implements Toggle<E> {
private final E lft;
private final E rght;
- private BooleanToggle 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(E left, E right) {
+ public ValueToggle(final E left, final E right) {
lft = left;
rght = right;
@@ -35,24 +35,20 @@ public class ValueToggle<E> implements Toggle<E> {
@Override
public E get() {
- if(alignment.get()) {
+ if (alignment.get())
return lft;
- } else {
- return rght;
- }
+ else return rght;
}
@Override
public E peek() {
- if(alignment.peek()) {
+ if (alignment.peek())
return lft;
- } else {
- return rght;
- }
+ else return rght;
}
@Override
- public void set(boolean isLeft) {
+ public void set(final boolean isLeft) {
alignment.set(isLeft);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java
index cc1c0c0..e5f1b95 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java
@@ -1,14 +1,14 @@
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;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
/*
* Implements a lazy holder that has been bound
*/
@@ -17,12 +17,12 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
/*
* The old value
*/
- private Supplier<IHolder<OldType>> oldSupplier;
+ private final Supplier<IHolder<OldType>> oldSupplier;
/*
* The function to use to transform the old value into a new value
*/
- private Function<OldType, IHolder<BoundContainedType>> binder;
+ private final Function<OldType, IHolder<BoundContainedType>> binder;
/*
* The bound value being held
@@ -37,30 +37,31 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
/*
* Transformations currently pending on the bound value
*/
- private IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>();
+ private final IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>();
/*
* Create a new bound lazy value
*/
- public BoundLazy(Supplier<IHolder<OldType>> supp, Function<OldType, IHolder<BoundContainedType>> binder) {
+ public BoundLazy(final Supplier<IHolder<OldType>> supp,
+ final Function<OldType, IHolder<BoundContainedType>> binder) {
oldSupplier = supp;
this.binder = binder;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<BoundContainedType, IHolder<BoundType>> bindr) {
+ 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
*/
- IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
+ final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
/*
* Create the new supplier of a value
*/
- Supplier<IHolder<BoundContainedType>> typeSupplier = () -> {
+ final Supplier<IHolder<BoundContainedType>> typeSupplier = () -> {
IHolder<BoundContainedType> oldHolder = boundHolder;
/*
@@ -83,7 +84,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <NewType> Function<BoundContainedType, IHolder<NewType>> lift(
- Function<BoundContainedType, NewType> func) {
+ final Function<BoundContainedType, NewType> func) {
if (func == null) throw new NullPointerException("Function to lift must not be null");
return (val) -> {
@@ -92,15 +93,15 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
}
@Override
- public <MappedType> IHolder<MappedType> map(Function<BoundContainedType, MappedType> mapper) {
+ 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
- IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
+ final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
// Prepare the new supplier
- Supplier<MappedType> typeSupplier = () -> {
+ final Supplier<MappedType> typeSupplier = () -> {
IHolder<BoundContainedType> oldHolder = boundHolder;
// Bound the value if it hasn't been bound
@@ -124,7 +125,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
}
@Override
- public IHolder<BoundContainedType> transform(UnaryOperator<BoundContainedType> transformer) {
+ public IHolder<BoundContainedType> transform(final UnaryOperator<BoundContainedType> transformer) {
if (transformer == null) throw new NullPointerException("Transformer must not be null");
actions.add(transformer);
@@ -133,7 +134,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<BoundContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(final Function<BoundContainedType, UnwrappedType> unwrapper) {
if (unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
if (!holderBound) {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
index de290a6..9333e15 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
@@ -1,14 +1,14 @@
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;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
/*
* Implements a lazy pair that has been bound
*/
@@ -17,16 +17,16 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
/*
* The supplier of the left value
*/
- private Supplier<OldLeft> leftSupplier;
+ private final Supplier<OldLeft> leftSupplier;
/*
* The supplier of the right value
*/
- private Supplier<OldRight> rightSupplier;
+ private final Supplier<OldRight> rightSupplier;
/*
* The binder to transform values
*/
- private BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> binder;
+ private final BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> binder;
/*
* The bound pair
@@ -38,8 +38,8 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
*/
private boolean pairBound;
- public BoundLazyPair(Supplier<OldLeft> leftSupp, Supplier<OldRight> rightSupp,
- BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) {
+ public BoundLazyPair(final Supplier<OldLeft> leftSupp, final Supplier<OldRight> rightSupp,
+ final BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) {
leftSupplier = leftSupp;
rightSupplier = rightSupp;
binder = bindr;
@@ -47,14 +47,14 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- if(bindr == null) throw new NullPointerException("Binder must not be null");
+ final BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
+ if (bindr == null) throw new NullPointerException("Binder must not be null");
- IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
- IHolder<Boolean> newPairMade = new Identity<>(pairBound);
+ final IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
+ final IHolder<Boolean> newPairMade = new Identity<>(pairBound);
- Supplier<NewLeft> leftSupp = () -> {
- if(!newPairMade.getValue()) {
+ final Supplier<NewLeft> leftSupp = () -> {
+ if (!newPairMade.getValue()) {
newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
newPairMade.replace(true);
@@ -63,8 +63,8 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
return newPair.unwrap((pair) -> pair.getLeft());
};
- Supplier<NewRight> rightSupp = () -> {
- if(!newPairMade.getValue()) {
+ final Supplier<NewRight> rightSupp = () -> {
+ if (!newPairMade.getValue()) {
newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
newPairMade.replace(true);
@@ -78,13 +78,13 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
- if(leftBinder == null) throw new NullPointerException("Left binder must not be null");
+ final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
+ if (leftBinder == null) throw new NullPointerException("Left binder must not be null");
- Supplier<NewLeft> leftSupp = () -> {
+ final Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if(!pairBound) {
+ if (!pairBound) {
newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
}
@@ -96,13 +96,13 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
- if(rightBinder == null) throw new NullPointerException("Right binder must not be null");
+ final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
+ if (rightBinder == null) throw new NullPointerException("Right binder must not be null");
- Supplier<NewRight> rightSupp = () -> {
+ final Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if(!pairBound) {
+ if (!pairBound) {
newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
}
@@ -114,14 +114,14 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
- if(otherPair == null)
+ 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)
+ 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");
+ else if (rightCombiner == null) throw new NullPointerException("Right combiner must not be null");
return otherPair.bind((otherLeft, otherRight) -> {
return bind((leftVal, rightVal) -> {
@@ -132,12 +132,12 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
}
@Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(Function<NewLeft, NewLeftType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
+ public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) {
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
- Supplier<NewLeftType> leftSupp = () -> {
- if(!pairBound) {
- NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
+ final Supplier<NewLeftType> leftSupp = () -> {
+ if (!pairBound) {
+ final NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
return mapper.apply(leftVal);
}
@@ -145,8 +145,8 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
return mapper.apply(boundPair.getLeft());
};
- Supplier<NewRight> rightSupp = () -> {
- if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
+ final Supplier<NewRight> rightSupp = () -> {
+ if (!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
return boundPair.getRight();
};
@@ -155,18 +155,19 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
}
@Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(Function<NewRight, NewRightType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
+ public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final Function<NewRight, NewRightType> mapper) {
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
- Supplier<NewLeft> leftSupp = () -> {
- if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
+ final Supplier<NewLeft> leftSupp = () -> {
+ if (!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
return boundPair.getLeft();
};
- Supplier<NewRightType> rightSupp = () -> {
- if(!pairBound) {
- NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
+ final Supplier<NewRightType> rightSupp = () -> {
+ if (!pairBound) {
+ final NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get())
+ .getRight();
return mapper.apply(rightVal);
}
@@ -178,10 +179,10 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
}
@Override
- public <MergedType> MergedType merge(BiFunction<NewLeft, NewRight, MergedType> merger) {
- if(merger == null) throw new NullPointerException("Merger must not be null");
+ public <MergedType> MergedType merge(final BiFunction<NewLeft, NewRight, MergedType> merger) {
+ if (merger == null) throw new NullPointerException("Merger must not be null");
- if(!pairBound) {
+ if (!pairBound) {
boundPair = binder.apply(leftSupplier.get(), rightSupplier.get());
pairBound = true;
@@ -192,7 +193,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public String toString() {
- if(pairBound) return boundPair.toString();
+ if (pairBound) return boundPair.toString();
return "(un-materialized)";
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java
index c838ce7..65a6f3d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java
@@ -1,28 +1,28 @@
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;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
/*
* Holds a list, converted into a holder
*/
@SuppressWarnings("javadoc")
public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
- private IList<IHolder<ContainedType>> heldHolders;
+ private final IList<IHolder<ContainedType>> heldHolders;
- public BoundListHolder(IList<IHolder<ContainedType>> toHold) {
+ public BoundListHolder(final IList<IHolder<ContainedType>> toHold) {
heldHolders = toHold;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- if(binder == null) throw new NullPointerException("Binder must not be null");
+ public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
+ if (binder == null) throw new NullPointerException("Binder must not be null");
- IList<IHolder<BoundType>> boundHolders = heldHolders.map((containedHolder) -> {
+ final IList<IHolder<BoundType>> boundHolders = heldHolders.map((containedHolder) -> {
return containedHolder.bind(binder);
});
@@ -30,8 +30,8 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
- if(func == null) throw new NullPointerException("Function to lift must not be null");
+ 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));
@@ -39,10 +39,10 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
+ public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
- IList<IHolder<MappedType>> mappedHolders = heldHolders.map((containedHolder) -> {
+ final IList<IHolder<MappedType>> mappedHolders = heldHolders.map((containedHolder) -> {
return containedHolder.map(mapper);
});
@@ -50,8 +50,8 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
- if(transformer == null) throw new NullPointerException("Transformer must not be null");
+ 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);
@@ -61,8 +61,8 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
- if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
+ if (unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
return heldHolders.randItem().unwrap(unwrapper);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
index 35df1c3..a603a7f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
@@ -1,39 +1,40 @@
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;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
/*
* A lazy pair, with only one side bound
*/
@SuppressWarnings("javadoc")
public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewLeft, NewRight> {
- private Supplier<OldType> oldSupplier;
+ private final Supplier<OldType> oldSupplier;
- private Function<OldType, IPair<NewLeft, NewRight>> binder;
+ private final Function<OldType, IPair<NewLeft, NewRight>> binder;
private IPair<NewLeft, NewRight> boundPair;
private boolean pairBound;
- public HalfBoundLazyPair(Supplier<OldType> oldSupp, Function<OldType, IPair<NewLeft, NewRight>> bindr) {
+ 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(
- BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
- IHolder<Boolean> newPairMade = new Identity<>(pairBound);
+ final BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
+ final IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
+ final IHolder<Boolean> newPairMade = new Identity<>(pairBound);
- Supplier<NewLeft> leftSupp = () -> {
- if(!newPairMade.getValue()) {
+ final Supplier<NewLeft> leftSupp = () -> {
+ if (!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -41,8 +42,8 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
return newPair.unwrap((pair) -> pair.getLeft());
};
- Supplier<NewRight> rightSupp = () -> {
- if(!newPairMade.getValue()) {
+ final Supplier<NewRight> rightSupp = () -> {
+ if (!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -55,11 +56,11 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
- Supplier<NewLeft> leftSupp = () -> {
+ final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
+ final Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if(!pairBound) {
+ if (!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -71,11 +72,11 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
- Supplier<NewRight> rightSupp = () -> {
+ final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
+ final Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if(!pairBound) {
+ if (!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -87,9 +88,9 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
+ 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) -> {
return new LazyPair<>(leftCombiner.apply(leftVal, otherLeft),
@@ -99,17 +100,17 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(Function<NewLeft, NewLeftType> mapper) {
- Supplier<NewLeftType> leftSupp = () -> {
- if(pairBound) return mapper.apply(boundPair.getLeft());
+ public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) {
+ final Supplier<NewLeftType> leftSupp = () -> {
+ if (pairBound) return mapper.apply(boundPair.getLeft());
- NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
+ final NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
return mapper.apply(leftVal);
};
- Supplier<NewRight> rightSupp = () -> {
- if(pairBound) return boundPair.getRight();
+ final Supplier<NewRight> rightSupp = () -> {
+ if (pairBound) return boundPair.getRight();
return binder.apply(oldSupplier.get()).getRight();
};
@@ -118,17 +119,17 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(Function<NewRight, NewRightType> mapper) {
- Supplier<NewLeft> leftSupp = () -> {
- if(pairBound) return boundPair.getLeft();
+ 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();
};
- Supplier<NewRightType> rightSupp = () -> {
- if(pairBound) return mapper.apply(boundPair.getRight());
+ final Supplier<NewRightType> rightSupp = () -> {
+ if (pairBound) return mapper.apply(boundPair.getRight());
- NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
+ final NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
return mapper.apply(rightVal);
};
@@ -137,8 +138,8 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <MergedType> MergedType merge(BiFunction<NewLeft, NewRight, MergedType> merger) {
- if(!pairBound) {
+ public <MergedType> MergedType merge(final BiFunction<NewLeft, NewRight, MergedType> merger) {
+ if (!pairBound) {
boundPair = binder.apply(oldSupplier.get());
pairBound = true;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java
index de161e5..d2e2b98 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java
@@ -1,28 +1,28 @@
package bjc.utils.data.internals;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Lazy;
-
import java.util.function.Function;
import java.util.function.UnaryOperator;
+import bjc.utils.data.IHolder;
+import bjc.utils.data.Lazy;
+
@SuppressWarnings("javadoc")
public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
- private IHolder<IHolder<ContainedType>> held;
+ private final IHolder<IHolder<ContainedType>> held;
- public WrappedLazy(IHolder<ContainedType> wrappedHolder) {
+ 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
- private WrappedLazy(IHolder<IHolder<ContainedType>> wrappedHolder, boolean dummy) {
+ private WrappedLazy(final IHolder<IHolder<ContainedType>> wrappedHolder, final boolean dummy) {
held = wrappedHolder;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> {
+ public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
+ final IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> {
return containedHolder.bind(binder);
});
@@ -30,15 +30,15 @@ public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
+ 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(Function<ContainedType, MappedType> mapper) {
- IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> {
+ public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
+ final IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> {
return containedHolder.map(mapper);
});
@@ -46,7 +46,7 @@ public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
held.transform((containedHolder) -> {
return containedHolder.transform(transformer);
});
@@ -55,7 +55,7 @@ public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
return held.unwrap((containedHolder) -> {
return containedHolder.unwrap(unwrapper);
});
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java
index e98332c..da53ab8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java
@@ -1,28 +1,28 @@
package bjc.utils.data.internals;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.Option;
-
import java.util.function.Function;
import java.util.function.UnaryOperator;
+import bjc.utils.data.IHolder;
+import bjc.utils.data.Option;
+
@SuppressWarnings("javadoc")
public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
- private IHolder<IHolder<ContainedType>> held;
+ private final IHolder<IHolder<ContainedType>> held;
- public WrappedOption(IHolder<ContainedType> seedValue) {
+ public WrappedOption(final IHolder<ContainedType> seedValue) {
held = new Option<>(seedValue);
}
- private WrappedOption(IHolder<IHolder<ContainedType>> toHold, boolean dummy) {
+ private WrappedOption(final IHolder<IHolder<ContainedType>> toHold, final boolean dummy) {
held = toHold;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> {
+ 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);
+ if (containedValue == null) return new Option<>(null);
return binder.apply(containedValue);
});
@@ -32,17 +32,17 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
+ 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(Function<ContainedType, MappedType> mapper) {
- IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> {
+ 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;
+ if (containedValue == null) return null;
return mapper.apply(containedValue);
});
@@ -52,10 +52,10 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
held.transform((containedHolder) -> {
return containedHolder.transform((containedValue) -> {
- if(containedValue == null) return null;
+ if (containedValue == null) return null;
return transformer.apply(containedValue);
});
@@ -65,10 +65,10 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
return held.unwrap((containedHolder) -> {
return containedHolder.unwrap((containedValue) -> {
- if(containedValue == null) return null;
+ if (containedValue == null) return null;
return unwrapper.apply(containedValue);
});