summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-14 12:07:14 -0400
committerEVE <EVE@EVE-PC>2017-03-14 12:07:14 -0400
commit504ca816530efdff06bc202e0432ebd354aec304 (patch)
tree4836932fb81d1d625470502c78c94d202c9a7420 /BJC-Utils2/src/main/java/bjc/utils/data
parent5c1163df17c46f7d3e15b6c7949c38843ec56146 (diff)
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Either.java64
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java38
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IPair.java40
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ITree.java38
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Identity.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java62
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Option.java18
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java87
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Tree.java89
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java38
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java66
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java38
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java22
23 files changed, 314 insertions, 446 deletions
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 8e0bf86..7131114 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java
@@ -3,8 +3,8 @@ package bjc.utils.data;
import java.util.Iterator;
public class CircularIterator<E> implements Iterator<E> {
- private Iterable<E> source;
- private Iterator<E> curr;
+ private Iterable<E> source;
+ private Iterator<E> curr;
private E curElm;
@@ -21,18 +21,19 @@ public class CircularIterator<E> implements Iterator<E> {
this(src, true);
}
+ @Override
public boolean hasNext() {
// We always have something
return true;
}
+ @Override
public E next() {
- if (!curr.hasNext()) {
- if (doCircle) {
+ if(!curr.hasNext()) {
+ if(doCircle) {
curr = source.iterator();
- } else {
+ } else
return curElm;
- }
}
curElm = curr.next();
@@ -40,6 +41,7 @@ public class CircularIterator<E> implements Iterator<E> {
return curElm;
}
+ @Override
public void remove() {
curr.remove();
}
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 7ec1720..d34f752 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
@@ -5,7 +5,7 @@ import java.util.function.Function;
/**
* Represents a pair where only one side has a value
- *
+ *
* @author ben
* @param <LeftType>
* The type that could be on the left
@@ -16,7 +16,7 @@ import java.util.function.Function;
public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
/**
* Create a new either with the left value occupied
- *
+ *
* @param <LeftType>
* The type of the left value
* @param <RightType>
@@ -31,7 +31,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
/**
* Create a new either with the right value occupied
- *
+ *
* @param <LeftType>
* The type of the empty left value
* @param <RightType>
@@ -51,7 +51,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
private boolean isLeft;
private Either(LeftType left, RightType right) {
- if (left == null) {
+ if(left == null) {
rightVal = right;
} else {
leftVal = left;
@@ -63,9 +63,7 @@ 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");
- }
+ if(binder == null) throw new NullPointerException("Binder must not be null");
return binder.apply(leftVal, rightVal);
}
@@ -73,13 +71,9 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
@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");
- }
+ 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);
}
@@ -87,13 +81,9 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
@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");
- }
+ 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);
}
@@ -103,19 +93,15 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
IPair<OtherLeft, OtherRight> otherPair,
BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
- if (otherPair == null) {
+ 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");
- 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));
@@ -124,35 +110,25 @@ 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");
- }
+ 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");
- }
+ 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");
- }
+ if(merger == null) throw new NullPointerException("Merger must not be null");
return merger.apply(leftVal, rightVal);
}
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 7b6c8d5..999f3da 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
@@ -1,18 +1,18 @@
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.
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -21,7 +21,7 @@ import bjc.utils.funcdata.theory.Functor;
public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Bind a function across the value in this container
- *
+ *
* @param <BoundType>
* The type of value in this container
* @param binder
@@ -32,7 +32,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Apply an action to the value
- *
+ *
* @param action
* The action to apply to the value
*/
@@ -48,10 +48,8 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap(
Function<ArgType, ReturnType> func) {
return (argumentFunctor) -> {
- if (!(argumentFunctor instanceof IHolder<?>)) {
- throw new IllegalArgumentException(
- "This functor only supports mapping over instances of IHolder");
- }
+ if(!(argumentFunctor instanceof IHolder<?>)) throw new IllegalArgumentException(
+ "This functor only supports mapping over instances of IHolder");
IHolder<ArgType> holder = (IHolder<ArgType>) argumentFunctor;
@@ -66,7 +64,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Lifts a function to bind over this holder
- *
+ *
* @param <NewType>
* The type of the functions return
* @param func
@@ -77,7 +75,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Make this holder lazy
- *
+ *
* @return A lazy version of this holder
*/
public default IHolder<ContainedType> makeLazy() {
@@ -86,7 +84,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Make this holder a list
- *
+ *
* @return A list version of this holder
*/
public default IHolder<ContainedType> makeList() {
@@ -95,7 +93,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Make this holder optional
- *
+ *
* @return An optional version of this holder
*/
public default IHolder<ContainedType> makeOptional() {
@@ -105,9 +103,9 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Create a new holder with a mapped version of the value in this
* holder.
- *
+ *
* Does not change the internal state of this holder
- *
+ *
* @param <MappedType>
* The type of the mapped value
* @param mapper
@@ -118,7 +116,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Replace the held value with a new one
- *
+ *
* @param newValue
* The value to hold instead
* @return The holder itself
@@ -131,7 +129,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Transform the value held in this holder
- *
+ *
* @param transformer
* The function to transform the value with
* @return The holder itself, for easy chaining
@@ -141,7 +139,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> {
/**
* Unwrap the value contained in this holder so that it is no longer
* held
- *
+ *
* @param <UnwrappedType>
* The type of the unwrapped value
* @param unwrapper
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 1405d75..24e0381 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
@@ -1,14 +1,14 @@
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
- *
+ *
* @author ben
* @param <LeftType>
* The type of the left side of the pair
@@ -19,7 +19,7 @@ import bjc.utils.funcdata.theory.Bifunctor;
public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightType> {
/**
* Bind a function across the values in this pair
- *
+ *
* @param <BoundLeft>
* The type of the bound left
* @param <BoundRight>
@@ -33,7 +33,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Bind a function to the left value in this pair
- *
+ *
* @param <BoundLeft>
* The type of the bound value
* @param leftBinder
@@ -45,7 +45,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Bind a function to the right value in this pair
- *
+ *
* @param <BoundRight>
* The type of the bound value
* @param rightBinder
@@ -57,7 +57,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Pairwise combine two pairs together
- *
+ *
* @param <OtherLeft>
* The left type of the other pair
* @param <OtherRight>
@@ -74,7 +74,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Combine the contents of two pairs together
- *
+ *
* @param <OtherLeft>
* The type of the left value of the other pair
* @param <OtherRight>
@@ -97,7 +97,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Immediately perfom the specified action with the contents of this
* pair
- *
+ *
* @param consumer
* The action to perform on the pair
*/
@@ -113,10 +113,8 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
default <OldLeft, OldRight, NewLeft> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> fmapLeft(
Function<OldLeft, NewLeft> func) {
return (argumentPair) -> {
- if (!(argumentPair instanceof IPair<?, ?>)) {
- throw new IllegalArgumentException(
- "This function can only be applied to instances of IPair");
- }
+ if(!(argumentPair instanceof IPair<?, ?>)) throw new IllegalArgumentException(
+ "This function can only be applied to instances of IPair");
IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
@@ -129,10 +127,8 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
fmapRight(Function<OldRight, NewRight> func) {
return (argumentPair) -> {
- if (!(argumentPair instanceof IPair<?, ?>)) {
- throw new IllegalArgumentException(
- "This function can only be applied to instances of IPair");
- }
+ if(!(argumentPair instanceof IPair<?, ?>)) throw new IllegalArgumentException(
+ "This function can only be applied to instances of IPair");
IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair;
@@ -142,7 +138,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Get the value on the left side of the pair
- *
+ *
* @return The value on the left side of the pair
*/
@Override
@@ -152,7 +148,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Get the value on the right side of the pair
- *
+ *
* @return The value on the right side of the pair
*/
@Override
@@ -163,7 +159,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Transform the value on the left side of the pair. Doesn't modify the
* pair
- *
+ *
* @param <NewLeft>
* The new type of the left part of the pair
* @param mapper
@@ -176,7 +172,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Transform the value on the right side of the pair. Doesn't modify the
* pair
- *
+ *
* @param <NewRight>
* The new type of the right part of the pair
* @param mapper
@@ -188,7 +184,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
/**
* Merge the two values in this pair into a single value
- *
+ *
* @param <MergedType>
* The type of the single value
* @param merger
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 4b6725c..63a82b8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java
@@ -1,16 +1,16 @@
package bjc.utils.data;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.bst.TreeLinearizationMethod;
+
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
-import bjc.utils.funcdata.IList;
-import bjc.utils.funcdata.bst.TreeLinearizationMethod;
-
/**
* A node in a homogenous tree with a unlimited amount of children
- *
+ *
* @author ben
* @param <ContainedType>
* The type of data contained in the tree nodes
@@ -19,7 +19,7 @@ import bjc.utils.funcdata.bst.TreeLinearizationMethod;
public interface ITree<ContainedType> {
/**
* Add a child to this node
- *
+ *
* @param child
* The child to add to this node
*/
@@ -27,7 +27,7 @@ public interface ITree<ContainedType> {
/**
* Collapse a tree into a single version
- *
+ *
* @param <NewType>
* The intermediate type being folded
* @param <ReturnedType>
@@ -48,7 +48,7 @@ public interface ITree<ContainedType> {
/**
* Execute a given action for each of this tree's children
- *
+ *
* @param action
* The action to execute for each child
*/
@@ -57,7 +57,7 @@ public interface ITree<ContainedType> {
/**
* Expand the nodes of a tree into trees, and then merge the contents of
* those trees into a single tree
- *
+ *
* @param mapper
* The function to use to map values into trees
* @return A tree, with some nodes expanded into trees
@@ -66,7 +66,7 @@ public interface ITree<ContainedType> {
/**
* Get the specified child of this tree
- *
+ *
* @param childNo
* The number of the child to get
* @return The specified child of this tree
@@ -77,14 +77,14 @@ public interface ITree<ContainedType> {
/**
* Get a count of the number of direct children this node has
- *
+ *
* @return The number of direct children this node has
*/
public int getChildrenCount();
/**
* Get the data stored in this node
- *
+ *
* @return The data stored in this node
*/
default ContainedType getHead() {
@@ -93,7 +93,7 @@ public interface ITree<ContainedType> {
/**
* Rebuild the tree with the same structure, but different nodes
- *
+ *
* @param <MappedType>
* The type of the new tree
* @param leafTransformer
@@ -107,7 +107,7 @@ public interface ITree<ContainedType> {
/**
* Transform some of the nodes in this tree
- *
+ *
* @param nodePicker
* The predicate to use to pick nodes to transform
* @param transformer
@@ -117,7 +117,7 @@ public interface ITree<ContainedType> {
/**
* Do a top-down transform of the tree
- *
+ *
* @param transformPicker
* The function to use to pick how to progress
* @param transformer
@@ -129,7 +129,7 @@ public interface ITree<ContainedType> {
/**
* Transform one of this nodes children
- *
+ *
* @param <TransformedType>
* The type of the transformed value
* @param childNo
@@ -137,7 +137,7 @@ public interface ITree<ContainedType> {
* @param transformer
* The function to use to transform the value
* @return The transformed value
- *
+ *
* @throws IllegalArgumentException
* if the childNo is out of bounds (0 <= childNo <=
* childCount())
@@ -147,7 +147,7 @@ public interface ITree<ContainedType> {
/**
* Transform the value that is the head of this node
- *
+ *
* @param <TransformedType>
* The type of the transformed value
* @param transformer
@@ -158,7 +158,7 @@ public interface ITree<ContainedType> {
/**
* Transform the tree into a tree with a different type of token
- *
+ *
* @param <MappedType>
* The type of the new tree
* @param transformer
@@ -169,7 +169,7 @@ public interface ITree<ContainedType> {
/**
* Perform an action on each part of the tree
- *
+ *
* @param linearizationMethod
* The way to traverse the tree
* @param action
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 aa3f7aa..9c4ea45 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java
@@ -10,7 +10,7 @@ import java.util.function.UnaryOperator;
*/
/**
* Simple implementation of IHolder that has no hidden behavior
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -28,7 +28,7 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
/**
* Create a holder holding the specified value
- *
+ *
* @param value
* The value to hold
*/
@@ -43,35 +43,29 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
- if (this == obj) {
+ if(this == obj)
return true;
- } else if (obj == null) {
- return false;
- } else if (getClass() != obj.getClass()) {
+ else if(obj == null)
return false;
- }
+ else if(getClass() != obj.getClass()) return false;
Identity<?> other = (Identity<?>) obj;
- if (heldValue == null) {
- if (other.heldValue != null) {
- return false;
- }
- } else if (!heldValue.equals(other.heldValue)) {
- return false;
- }
+ if(heldValue == null) {
+ if(other.heldValue != null) return false;
+ } else if(!heldValue.equals(other.heldValue)) return false;
return true;
}
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -80,7 +74,7 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
int result = 1;
- int fieldHash = (heldValue == null) ? 0 : heldValue.hashCode();
+ int fieldHash = heldValue == null ? 0 : heldValue.hashCode();
result = prime * result + fieldHash;
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 3a037d7..d4d350a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
@@ -1,17 +1,17 @@
package bjc.utils.data;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.internals.BoundLazy;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.function.UnaryOperator;
+
/**
* A holder that holds a means to create a value, but doesn't actually compute
* the value until it's needed
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -27,7 +27,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
/**
* Create a new lazy value from the specified seed value
- *
+ *
* @param value
* The seed value to use
*/
@@ -39,7 +39,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
/**
* Create a new lazy value from the specified value source
- *
+ *
* @param supp
* The source of a value to use
*/
@@ -62,9 +62,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
actions.forEach(pendingActions::add);
Supplier<ContainedType> supplier = () -> {
- if (valueMaterialized) {
- return heldValue;
- }
+ if(valueMaterialized) return heldValue;
return valueSupplier.get();
};
@@ -90,7 +88,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
return new Lazy<>(() -> {
ContainedType currVal = heldValue;
- if (!valueMaterialized) {
+ if(!valueMaterialized) {
currVal = valueSupplier.get();
}
@@ -101,10 +99,8 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
@Override
public String toString() {
- if (valueMaterialized) {
- if (actions.isEmpty()) {
- return "value[v='" + heldValue + "']";
- }
+ if(valueMaterialized) {
+ if(actions.isEmpty()) return "value[v='" + heldValue + "']";
return "value[v='" + heldValue + "'] (has pending transforms)";
}
@@ -121,7 +117,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
@Override
public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
- if (!valueMaterialized) {
+ if(!valueMaterialized) {
heldValue = valueSupplier.get();
valueMaterialized = true;
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 29e37ac..59df1b1 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java
@@ -1,36 +1,36 @@
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
- *
+ *
* @author ben
*
* @param <LeftType>
* The type on the left side of the pair
* @param <RightType>
* The type on the right side of the pair
- *
+ *
*/
public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> {
- private LeftType leftValue;
- private RightType rightValue;
+ private LeftType leftValue;
+ private RightType rightValue;
- private Supplier<LeftType> leftSupplier;
- private Supplier<RightType> rightSupplier;
+ private Supplier<LeftType> leftSupplier;
+ private Supplier<RightType> rightSupplier;
- private boolean leftMaterialized;
- private boolean rightMaterialized;
+ private boolean leftMaterialized;
+ private boolean rightMaterialized;
/**
* Create a new lazy pair, using the set values
- *
+ *
* @param leftVal
* The value for the left side of the pair
* @param rightVal
@@ -46,7 +46,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
/**
* Create a new lazy pair from the given value sources
- *
+ *
* @param leftSupp
* The source for a value on the left side of the pair
* @param rightSupp
@@ -71,9 +71,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
Supplier<LeftType> leftSupp = () -> {
- if (leftMaterialized) {
- return leftValue;
- }
+ if(leftMaterialized) return leftValue;
return leftSupplier.get();
};
@@ -85,9 +83,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
Supplier<RightType> rightSupp = () -> {
- if (rightMaterialized) {
- return rightValue;
- }
+ if(rightMaterialized) return rightValue;
return rightSupplier.get();
};
@@ -110,7 +106,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public LeftType getLeft() {
- if (!leftMaterialized) {
+ if(!leftMaterialized) {
leftValue = leftSupplier.get();
leftMaterialized = true;
@@ -121,7 +117,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public RightType getRight() {
- if (!rightMaterialized) {
+ if(!rightMaterialized) {
rightValue = rightSupplier.get();
rightMaterialized = true;
@@ -133,17 +129,13 @@ 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);
- }
+ if(leftMaterialized) return mapper.apply(leftValue);
return mapper.apply(leftSupplier.get());
};
Supplier<RightType> rightSupp = () -> {
- if (rightMaterialized) {
- return rightValue;
- }
+ if(rightMaterialized) return rightValue;
return rightSupplier.get();
};
@@ -154,17 +146,13 @@ 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;
- }
+ if(leftMaterialized) return leftValue;
return leftSupplier.get();
};
Supplier<NewRight> rightSupp = () -> {
- if (rightMaterialized) {
- return mapper.apply(rightValue);
- }
+ if(rightMaterialized) return mapper.apply(rightValue);
return mapper.apply(rightSupplier.get());
};
@@ -174,13 +162,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger) {
- if (!leftMaterialized) {
+ if(!leftMaterialized) {
leftValue = leftSupplier.get();
leftMaterialized = true;
}
- if (!rightMaterialized) {
+ if(!rightMaterialized) {
rightValue = rightSupplier.get();
rightMaterialized = true;
@@ -193,7 +181,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public String toString() {
StringBuilder sb = new StringBuilder("pair[l=");
- if (leftMaterialized) {
+ if(leftMaterialized) {
sb.append(leftValue.toString());
} else {
sb.append("(un-materialized)");
@@ -201,7 +189,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
sb.append(", r=");
- if (rightMaterialized) {
+ if(rightMaterialized) {
sb.append(rightValue.toString());
} else {
sb.append("(un-materialized)");
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 5c14475..84ea01d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
@@ -1,15 +1,15 @@
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
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -20,7 +20,7 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
/**
* Create a new list holder
- *
+ *
* @param values
* The possible values for the computation
*/
@@ -28,8 +28,8 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
public ListHolder(ContainedType... values) {
heldValues = new FunctionalList<>();
- if (values != null) {
- for (ContainedType containedValue : values) {
+ if(values != null) {
+ for(ContainedType containedValue : values) {
heldValues.add(containedValue);
}
}
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 210d2aa..052e78a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
@@ -5,7 +5,7 @@ import java.util.function.UnaryOperator;
/**
* A holder that may or may not contain a value
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -16,7 +16,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
/**
* Create a new optional, using the given initial value
- *
+ *
* @param seed
* The initial value for the optional
*/
@@ -26,9 +26,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- if (held == null) {
- return new Option<>(null);
- }
+ if(held == null) return new Option<>(null);
return binder.apply(held);
}
@@ -42,16 +40,14 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
- if (held == null) {
- return new Option<>(null);
- }
+ if(held == null) return new Option<>(null);
return new Option<>(mapper.apply(held));
}
@Override
public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
- if (held != null) {
+ if(held != null) {
held = transformer.apply(held);
}
@@ -60,9 +56,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
- if (held == null) {
- return null;
- }
+ if(held == null) return null;
return unwrapper.apply(held);
}
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 b22fd28..77afa4a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -5,7 +5,7 @@ import java.util.function.Function;
/**
* A pair of values, with nothing special about them.
- *
+ *
* @author ben
*
* @param <LeftType>
@@ -29,7 +29,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
/**
* Create a new pair with both sides set to the specified values
- *
+ *
* @param left
* The value of the left side
* @param right
@@ -43,9 +43,7 @@ public class Pair<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.");
- }
+ if(binder == null) throw new NullPointerException("Binder must not be null.");
return binder.apply(leftValue, rightValue);
}
@@ -53,9 +51,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if (leftBinder == null) {
- throw new NullPointerException("Binder must not be null");
- }
+ if(leftBinder == null) throw new NullPointerException("Binder must not be null");
return leftBinder.apply(leftValue);
}
@@ -63,9 +59,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if (rightBinder == null) {
- throw new NullPointerException("Binder must not be null");
- }
+ if(rightBinder == null) throw new NullPointerException("Binder must not be null");
return rightBinder.apply(rightValue);
}
@@ -83,27 +77,21 @@ public class Pair<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");
- }
+ 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");
- }
+ 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");
- }
+ if(merger == null) throw new NullPointerException("Merger must not be null");
return merger.apply(leftValue, rightValue);
}
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 fde1197..4d79b92 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java
@@ -13,10 +13,12 @@ public class SingleIterator<T> implements Iterator<T> {
yielded = false;
}
+ @Override
public boolean hasNext() {
return !yielded;
}
+ @Override
public T next() {
yielded = true;
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 bf8b0a0..76c9be2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java
@@ -4,9 +4,9 @@ import java.util.function.Supplier;
/**
* A supplier that can only supply one value.
- *
+ *
* Attempting to retrieve another value will cause an exception to be thrown.
- *
+ *
* @author ben
*
* @param <T>
@@ -26,7 +26,7 @@ public class SingleSupplier<T> implements Supplier<T> {
/**
* Create a new single supplier from an existing value
- *
+ *
* @param supp
* The supplier to give a single value from
*/
@@ -40,7 +40,7 @@ public class SingleSupplier<T> implements Supplier<T> {
@Override
public T get() {
- if (gotten == true) {
+ if(gotten == true) {
IllegalStateException isex = new IllegalStateException("Attempted to get value more than once"
+ " from single supplier #" + id + ". Previous instantiation below.");
@@ -53,7 +53,7 @@ public class SingleSupplier<T> implements Supplier<T> {
try {
throw new IllegalStateException("Previous instantiation here.");
- } catch (IllegalStateException isex) {
+ } catch(IllegalStateException isex) {
instSite = isex;
}
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 8a24512..2463df9 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java
@@ -8,25 +8,25 @@ import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
-import static bjc.utils.data.TopDownTransformResult.*;
+import static bjc.utils.data.TopDownTransformResult.RTRANSFORM;
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 Function<ContainedType, TopDownTransformResult> picker;
+ private BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transform;
- private ITree<ContainedType> preParent;
- private ITree<ContainedType> postParent;
+ private ITree<ContainedType> preParent;
+ private ITree<ContainedType> postParent;
- private Deque<ITree<ContainedType>> preChildren;
- private Deque<ITree<ContainedType>> postChildren;
+ private Deque<ITree<ContainedType>> preChildren;
+ private Deque<ITree<ContainedType>> postChildren;
private TopDownTransformIterator<ContainedType> curChild;
- private boolean done;
- private boolean initial;
+ private boolean done;
+ private boolean initial;
- private Deque<Iterator<ITree<ContainedType>>> toYield;
- private Iterator<ITree<ContainedType>> curYield;
+ private 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,
@@ -45,69 +45,67 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
}
public void addYield(Iterator<ITree<ContainedType>> src) {
- if (curYield != null) {
+ if(curYield != null) {
toYield.push(curYield);
}
curYield = src;
}
+ @Override
public boolean hasNext() {
return !done;
}
public ITree<ContainedType> flushYields(ITree<ContainedType> val) {
- if (curYield != null) {
+ if(curYield != null) {
toYield.add(new SingleIterator<>(val));
- if (curYield.hasNext()) {
+ if(curYield.hasNext())
return curYield.next();
- } else {
- while (toYield.size() != 0 && !curYield.hasNext()) {
+ else {
+ 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 {
+ } else
return curYield.next();
- }
}
- } else {
+ } 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()) {
+ else {
+ while(toYield.size() != 0 && !curYield.hasNext()) {
curYield = toYield.pop();
}
- if (toYield.size() == 0 && !curYield.hasNext()) {
+ if(toYield.size() == 0 && !curYield.hasNext()) {
curYield = null;
- } else {
+ } else
return curYield.next();
- }
}
}
- if (initial) {
+ if(initial) {
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));
}
@@ -127,8 +125,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));
}
@@ -144,8 +142,8 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C
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));
}
@@ -159,12 +157,13 @@ 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();
@@ -175,12 +174,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(ITree<ContainedType> child : postChildren) {
res.addChild(child);
}
@@ -190,7 +189,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(ITree<ContainedType> child : postChildren) {
res.addChild(child);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java
index 0db9482..ed41eae 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java
@@ -2,7 +2,7 @@ package bjc.utils.data;
/**
* Represents the results for doing a top-down transform of a tree
- *
+ *
* @author ben
*
*/
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java
index 742a73b..80de96f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java
@@ -13,10 +13,12 @@ public class TransformedIterator<PreType, PostType> implements Iterator<PostType
trans = transform;
}
+ @Override
public boolean hasNext() {
return source.hasNext();
}
+ @Override
public PostType next() {
return transform.apply(source.next());
}
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 6a16491..52414d2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java
@@ -1,17 +1,17 @@
package bjc.utils.data;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.bst.TreeLinearizationMethod;
+
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-import bjc.utils.funcdata.bst.TreeLinearizationMethod;
-
/**
* A node in a homogenous tree.
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -19,16 +19,16 @@ import bjc.utils.funcdata.bst.TreeLinearizationMethod;
public class Tree<ContainedType> implements ITree<ContainedType> {
private ContainedType data;
- private IList<ITree<ContainedType>> children;
- private boolean hasChildren;
- private int childCount = 0;
+ private IList<ITree<ContainedType>> children;
+ private boolean hasChildren;
+ private int childCount = 0;
- private int ID;
- private static int nextID = 0;
+ private int ID;
+ private static int nextID = 0;
/**
* Create a new leaf node in a tree
- *
+ *
* @param leaf
* The data to store as a leaf node
*/
@@ -42,7 +42,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
/**
* Create a new tree node with the specified children
- *
+ *
* @param leaf
* The data to hold in this node
* @param childrn
@@ -58,7 +58,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
/**
* Create a new tree node with the specified children
- *
+ *
* @param leaf
* The data to hold in this node
* @param childrn
@@ -74,7 +74,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
children = new FunctionalList<>();
- for (ITree<ContainedType> child : childrn) {
+ for(ITree<ContainedType> child : childrn) {
children.add(child);
childCount++;
@@ -83,7 +83,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public void addChild(ITree<ContainedType> child) {
- if (hasChildren == false) {
+ if(hasChildren == false) {
hasChildren = true;
children = new FunctionalList<>();
@@ -109,7 +109,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public ITree<ContainedType> flatMapTree(Function<ContainedType, ITree<ContainedType>> mapper) {
- if (hasChildren) {
+ if(hasChildren) {
ITree<ContainedType> flatMappedData = mapper.apply(data);
children.map((child) -> child.flatMapTree(mapper))
@@ -128,10 +128,10 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
protected <NewType> NewType internalCollapse(Function<ContainedType, NewType> leafTransform,
Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser) {
- if (hasChildren) {
+ if(hasChildren) {
Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser.apply(data);
- IList<NewType> collapsedChildren = (IList<NewType>) children.map((child) -> {
+ IList<NewType> collapsedChildren = children.map((child) -> {
return child.collapse(leafTransform, nodeCollapser, (subTreeVal) -> subTreeVal);
});
@@ -142,7 +142,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
protected void internalToString(StringBuilder builder, int indentLevel, boolean initial) {
- for (int i = 0; i < indentLevel; i++) {
+ for(int i = 0; i < indentLevel; i++) {
builder.append(">\t");
}
@@ -152,7 +152,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
builder.append(data == null ? "(null)" : data.toString());
builder.append("\n");
- if (hasChildren) {
+ if(hasChildren) {
children.forEach((child) -> {
((Tree<ContainedType>) child).internalToString(builder, indentLevel + 1, false);
});
@@ -162,7 +162,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public <MappedType> ITree<MappedType> rebuildTree(Function<ContainedType, MappedType> leafTransformer,
Function<ContainedType, MappedType> operatorTransformer) {
- if (hasChildren) {
+ if(hasChildren) {
IList<ITree<MappedType>> mappedChildren = children.map((child) -> {
return child.rebuildTree(leafTransformer, operatorTransformer);
});
@@ -175,7 +175,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public void selectiveTransform(Predicate<ContainedType> nodePicker, UnaryOperator<ContainedType> transformer) {
- if (hasChildren) {
+ if(hasChildren) {
children.forEach((child) -> child.selectiveTransform(nodePicker, transformer));
} else {
data = transformer.apply(data);
@@ -187,11 +187,11 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
UnaryOperator<ITree<ContainedType>> transformer) {
TopDownTransformResult transformResult = transformPicker.apply(data);
- switch (transformResult) {
+ switch(transformResult) {
case PASSTHROUGH:
ITree<ContainedType> result = new Tree<>(data);
- if (hasChildren) {
+ if(hasChildren) {
children.forEach((child) -> {
result.addChild(child.topDownTransform(transformPicker, transformer));
});
@@ -207,7 +207,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
case PUSHDOWN:
result = new Tree<>(data);
- if (hasChildren) {
+ if(hasChildren) {
children.forEach((child) -> {
result.addChild(child.topDownTransform(transformPicker, transformer));
});
@@ -244,9 +244,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public <TransformedType> TransformedType transformChild(int childNo,
Function<ITree<ContainedType>, TransformedType> transformer) {
- if (childNo < 0 || childNo > (childCount - 1)) {
+ if(childNo < 0 || childNo > childCount - 1)
throw new IllegalArgumentException("Child index #" + childNo + " is invalid");
- }
return transformer.apply(children.getByIndex(childNo));
}
@@ -258,7 +257,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public <MappedType> ITree<MappedType> transformTree(Function<ContainedType, MappedType> transformer) {
- if (hasChildren) {
+ if(hasChildren) {
IList<ITree<MappedType>> transformedChildren = children
.map((child) -> child.transformTree(transformer));
@@ -270,13 +269,11 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public void traverse(TreeLinearizationMethod linearizationMethod, Consumer<ContainedType> action) {
- if (hasChildren) {
- switch (linearizationMethod) {
+ if(hasChildren) {
+ switch(linearizationMethod) {
case INORDER:
- if (childCount != 2) {
- throw new IllegalArgumentException(
- "Can only do in-order traversal for binary trees.");
- }
+ if(childCount != 2) throw new IllegalArgumentException(
+ "Can only do in-order traversal for binary trees.");
children.getByIndex(0).traverse(linearizationMethod, action);
@@ -303,32 +300,26 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
}
}
+ @Override
public boolean equals(Object other) {
- if (!(other instanceof Tree<?>))
- return false;
+ if(!(other instanceof Tree<?>)) return false;
@SuppressWarnings("unchecked")
Tree<ContainedType> otr = (Tree<ContainedType>) other;
- if (!otr.data.equals(data))
- return false;
+ if(!otr.data.equals(data)) return false;
- if (children == null && otr.children == null)
- return true;
+ if(children == null && otr.children == null) return true;
- if (children == null && otr.children != null)
- return false;
- if (children != null && otr.children == null)
- return false;
+ if(children == null && otr.children != null) return false;
+ if(children != null && otr.children == null) return false;
- if (children.getSize() != otr.children.getSize())
- return false;
+ if(children.getSize() != otr.children.getSize()) return false;
int childNo = 0;
- for (ITree<ContainedType> child : children) {
- if (!otr.children.getByIndex(childNo).equals(child))
- return false;
+ for(ITree<ContainedType> child : children) {
+ if(!otr.children.getByIndex(childNo).equals(child)) return false;
childNo += 1;
}
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 57bf006..0ec69f0 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
*/
@@ -48,9 +48,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <BoundType> IHolder<BoundType> bind(Function<BoundContainedType, IHolder<BoundType>> bindr) {
- if (bindr == null) {
- throw new NullPointerException("Binder must not be null");
- }
+ if(bindr == null) throw new NullPointerException("Binder must not be null");
/*
* Prepare a list of pending actions
@@ -67,7 +65,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
/*
* Bind the value if it hasn't been bound before
*/
- if (!holderBound) {
+ if(!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
@@ -85,9 +83,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <NewType> Function<BoundContainedType, IHolder<NewType>> lift(
Function<BoundContainedType, NewType> func) {
- if (func == null) {
- throw new NullPointerException("Function to lift must not be null");
- }
+ if(func == null) throw new NullPointerException("Function to lift must not be null");
return (val) -> {
return new Lazy<>(func.apply(val));
@@ -96,9 +92,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <MappedType> IHolder<MappedType> map(Function<BoundContainedType, MappedType> mapper) {
- if (mapper == null) {
- throw new NullPointerException("Mapper must not be null");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
// Prepare a list of pending actions
IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
@@ -109,7 +103,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
IHolder<BoundContainedType> oldHolder = boundHolder;
// Bound the value if it hasn't been bound
- if (!holderBound) {
+ if(!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
@@ -123,18 +117,14 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public String toString() {
- if (holderBound) {
- return boundHolder.toString();
- }
+ if(holderBound) return boundHolder.toString();
return "(unmaterialized)";
}
@Override
public IHolder<BoundContainedType> transform(UnaryOperator<BoundContainedType> transformer) {
- if (transformer == null) {
- throw new NullPointerException("Transformer must not be null");
- }
+ if(transformer == null) throw new NullPointerException("Transformer must not be null");
actions.add(transformer);
@@ -143,11 +133,9 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <UnwrappedType> UnwrappedType unwrap(Function<BoundContainedType, UnwrappedType> unwrapper) {
- if (unwrapper == null) {
- throw new NullPointerException("Unwrapper must not be null");
- }
+ if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
- if (!holderBound) {
+ if(!holderBound) {
boundHolder = oldSupplier.get().unwrap(binder::apply);
}
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 d425d99..6ab8121 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
*/
@@ -47,15 +47,13 @@ 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");
- }
+ 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);
Supplier<NewLeft> leftSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
newPairMade.replace(true);
@@ -65,7 +63,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
};
Supplier<NewRight> rightSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
newPairMade.replace(true);
@@ -80,14 +78,12 @@ 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");
- }
+ if(leftBinder == null) throw new NullPointerException("Left binder must not be null");
Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
}
@@ -100,14 +96,12 @@ 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");
- }
+ if(rightBinder == null) throw new NullPointerException("Right binder must not be null");
Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
}
@@ -122,13 +116,11 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
IPair<OtherLeft, OtherRight> otherPair,
BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
- if (otherPair == null) {
+ 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) -> {
@@ -140,12 +132,10 @@ 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");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
Supplier<NewLeftType> leftSupp = () -> {
- if (!pairBound) {
+ if(!pairBound) {
NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
return mapper.apply(leftVal);
@@ -155,9 +145,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
};
Supplier<NewRight> rightSupp = () -> {
- if (!pairBound) {
- return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
- }
+ if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
return boundPair.getRight();
};
@@ -167,20 +155,16 @@ 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");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
Supplier<NewLeft> leftSupp = () -> {
- if (!pairBound) {
- return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
- }
+ if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
return boundPair.getLeft();
};
Supplier<NewRightType> rightSupp = () -> {
- if (!pairBound) {
+ if(!pairBound) {
NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
return mapper.apply(rightVal);
@@ -194,11 +178,9 @@ 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");
- }
+ if(merger == null) throw new NullPointerException("Merger must not be null");
- if (!pairBound) {
+ if(!pairBound) {
boundPair = binder.apply(leftSupplier.get(), rightSupplier.get());
pairBound = true;
@@ -209,9 +191,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 f363b7e..467d55d 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,12 +1,12 @@
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
*/
@@ -19,9 +19,7 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- if (binder == null) {
- throw new NullPointerException("Binder must not be null");
- }
+ if(binder == null) throw new NullPointerException("Binder must not be null");
IList<IHolder<BoundType>> boundHolders = heldHolders.map((containedHolder) -> {
return containedHolder.bind(binder);
@@ -32,9 +30,7 @@ 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");
- }
+ if(func == null) throw new NullPointerException("Function to lift must not be null");
return (val) -> {
return new ListHolder<>(func.apply(val));
@@ -43,9 +39,7 @@ 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");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
IList<IHolder<MappedType>> mappedHolders = heldHolders.map((containedHolder) -> {
return containedHolder.map(mapper);
@@ -56,9 +50,7 @@ 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");
- }
+ if(transformer == null) throw new NullPointerException("Transformer must not be null");
heldHolders.forEach((containedHolder) -> {
containedHolder.transform(transformer);
@@ -69,9 +61,7 @@ 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");
- }
+ 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 a8bdb6a..c5e9c9f 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,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;
+
/*
* A lazy pair, with only one side bound
*/
@@ -17,8 +17,8 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
private Function<OldType, IPair<NewLeft, NewRight>> binder;
- private IPair<NewLeft, NewRight> boundPair;
- private boolean pairBound;
+ private IPair<NewLeft, NewRight> boundPair;
+ private boolean pairBound;
public HalfBoundLazyPair(Supplier<OldType> oldSupp, Function<OldType, IPair<NewLeft, NewRight>> bindr) {
oldSupplier = oldSupp;
@@ -32,7 +32,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
IHolder<Boolean> newPairMade = new Identity<>(pairBound);
Supplier<NewLeft> leftSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -41,7 +41,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
};
Supplier<NewRight> rightSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -58,7 +58,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -74,7 +74,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -100,9 +100,7 @@ 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());
- }
+ if(pairBound) return mapper.apply(boundPair.getLeft());
NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
@@ -110,9 +108,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
};
Supplier<NewRight> rightSupp = () -> {
- if (pairBound) {
- return boundPair.getRight();
- }
+ if(pairBound) return boundPair.getRight();
return binder.apply(oldSupplier.get()).getRight();
};
@@ -123,17 +119,13 @@ 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();
- }
+ if(pairBound) return boundPair.getLeft();
return binder.apply(oldSupplier.get()).getLeft();
};
Supplier<NewRightType> rightSupp = () -> {
- if (pairBound) {
- return mapper.apply(boundPair.getRight());
- }
+ if(pairBound) return mapper.apply(boundPair.getRight());
NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
@@ -145,7 +137,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <MergedType> MergedType merge(BiFunction<NewLeft, NewRight, MergedType> merger) {
- if (!pairBound) {
+ 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 7f0b8db..f400345 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,11 +1,11 @@
package bjc.utils.data.internals;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.Lazy;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
private IHolder<IHolder<ContainedType>> held;
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 2b03f62..1639351 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,11 +1,11 @@
package bjc.utils.data.internals;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.Option;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
private IHolder<IHolder<ContainedType>> held;
@@ -21,9 +21,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
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);
});
@@ -43,9 +41,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
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);
});
@@ -58,9 +54,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
held.transform((containedHolder) -> {
return containedHolder.transform((containedValue) -> {
- if (containedValue == null) {
- return null;
- }
+ if(containedValue == null) return null;
return transformer.apply(containedValue);
});
@@ -73,9 +67,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public <UnwrappedType> UnwrappedType unwrap(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);
});