diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/data')
25 files changed, 431 insertions, 467 deletions
diff --git a/base/src/main/java/bjc/utils/data/BooleanToggle.java b/base/src/main/java/bjc/utils/data/BooleanToggle.java index 280b90d..542d2b6 100644 --- a/base/src/main/java/bjc/utils/data/BooleanToggle.java +++ b/base/src/main/java/bjc/utils/data/BooleanToggle.java @@ -21,7 +21,7 @@ public class BooleanToggle implements Toggle<Boolean> { * Create a flip-flop with the specified initial value. * * @param initial - * The initial value of the flip-flop. + * The initial value of the flip-flop. */ public BooleanToggle(final boolean initial) { val = initial; @@ -59,13 +59,13 @@ public class BooleanToggle implements Toggle<Boolean> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof BooleanToggle)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof BooleanToggle)) return false; final BooleanToggle other = (BooleanToggle) obj; - if (val != other.val) return false; + if(val != other.val) return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/CircularIterator.java b/base/src/main/java/bjc/utils/data/CircularIterator.java index 60f815c..507ee01 100644 --- a/base/src/main/java/bjc/utils/data/CircularIterator.java +++ b/base/src/main/java/bjc/utils/data/CircularIterator.java @@ -8,7 +8,7 @@ import java.util.Iterator; * @author EVE * * @param <E> - * The type of the iterable. + * The type of the iterable. */ public class CircularIterator<E> implements Iterator<E> { /* The iterable, and our current iterator into it. */ @@ -28,11 +28,11 @@ public class CircularIterator<E> implements Iterator<E> { * Create a new circular iterator. * * @param src - * The iterable to iterate from. + * The iterable to iterate from. * * @param circ - * Should we actually do circular iteration, or just - * repeat the terminal element? + * Should we actually do circular iteration, or just repeat the + * terminal element? */ public CircularIterator(final Iterable<E> src, final boolean circ) { source = src; @@ -45,7 +45,7 @@ public class CircularIterator<E> implements Iterator<E> { * Create a new circular iterator that does actual circular iteration. * * @param src - * The iterable to iterate from. + * The iterable to iterate from. */ public CircularIterator(final Iterable<E> src) { this(src, true); @@ -59,10 +59,11 @@ public class CircularIterator<E> implements Iterator<E> { @Override public E next() { - if (!curr.hasNext()) { - if (doCircle) { + if(!curr.hasNext()) { + if(doCircle) { curr = source.iterator(); - } else return curElm; + } else + return curElm; } curElm = curr.next(); diff --git a/base/src/main/java/bjc/utils/data/Either.java b/base/src/main/java/bjc/utils/data/Either.java index 20a06f5..6023b60 100644 --- a/base/src/main/java/bjc/utils/data/Either.java +++ b/base/src/main/java/bjc/utils/data/Either.java @@ -9,10 +9,10 @@ import java.util.function.Function; * @author ben * * @param <LeftType> - * The type that could be on the left. + * The type that could be on the left. * * @param <RightType> - * The type that could be on the right. + * The type that could be on the right. * */ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { @@ -20,16 +20,15 @@ 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. + * The type of the left value. * * @param <RightType> - * The type of the empty right value. - * + * The type of the empty right value. + * * @param left - * The value to put on the left. + * The value to put on the left. * - * @return - * An either with the left side occupied. + * @return An either with the left side occupied. */ public static <LeftType, RightType> Either<LeftType, RightType> left(final LeftType left) { return new Either<>(left, null); @@ -39,16 +38,15 @@ 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. + * The type of the empty left value. * * @param <RightType> - * The type of the right value. + * The type of the right value. * * @param right - * The value to put on the right. + * The value to put on the right. * - * @return - * An either with the right side occupied. + * @return An either with the right side occupied. */ public static <LeftType, RightType> Either<LeftType, RightType> right(final RightType right) { return new Either<>(null, right); @@ -63,7 +61,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { /* Create a new either with specifed values. */ private Either(final LeftType left, final RightType right) { - if (left == null) { + if(left == null) { rightVal = right; } else { leftVal = left; @@ -75,7 +73,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { - if (binder == null) throw new NullPointerException("Binder must not be null"); + if(binder == null) throw new NullPointerException("Binder must not be null"); return binder.apply(leftVal, rightVal); } @@ -83,9 +81,9 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <BoundLeft> IPair<BoundLeft, RightType> bindLeft( final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) { - if (leftBinder == null) throw new NullPointerException("Left binder must not be null"); + if(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); } @@ -93,9 +91,9 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <BoundRight> IPair<LeftType, BoundRight> bindRight( final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) { - if (rightBinder == null) throw new NullPointerException("Right binder must not be null"); + if(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); } @@ -105,15 +103,15 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { final IPair<OtherLeft, OtherRight> otherPair, final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, final 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) { + } else if(rightCombiner == null) { throw new NullPointerException("Right combiner must not be null"); } - if (isLeft) { + if(isLeft) { return otherPair.bind((otherLeft, otherRight) -> { CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft); @@ -130,25 +128,25 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <NewLeft> IPair<NewLeft, RightType> mapLeft(final 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(final 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(final 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); } @@ -167,21 +165,21 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof Either<?, ?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof Either<?, ?>)) return false; final Either<?, ?> other = (Either<?, ?>) obj; - if (isLeft != other.isLeft) return false; + if(isLeft != other.isLeft) return false; - if (leftVal == null) { - if (other.leftVal != null) return false; - } else if (!leftVal.equals(other.leftVal)) return false; + if(leftVal == null) { + if(other.leftVal != null) return false; + } else if(!leftVal.equals(other.leftVal)) return false; - if (rightVal == null) { - if (other.rightVal != null) return false; - } else if (!rightVal.equals(other.rightVal)) return false; + if(rightVal == null) { + if(other.rightVal != null) return false; + } else if(!rightVal.equals(other.rightVal)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/GeneratingIterator.java b/base/src/main/java/bjc/utils/data/GeneratingIterator.java index 92d10a5..8e6bcd2 100644 --- a/base/src/main/java/bjc/utils/data/GeneratingIterator.java +++ b/base/src/main/java/bjc/utils/data/GeneratingIterator.java @@ -10,7 +10,7 @@ import java.util.function.UnaryOperator; * @author bjculkin * * @param <E> - * The type of element generated. + * The type of element generated. */ public class GeneratingIterator<E> implements Iterator<E> { /* Our current state. */ @@ -24,14 +24,14 @@ public class GeneratingIterator<E> implements Iterator<E> { * Create a new generative iterator. * * @param initial - * The initial state of the generator. + * The initial state of the generator. * * @param transition - * The function to apply to the state. + * The function to apply to the state. * * @param stopper - * The predicate applied to the current state to - * determine when to stop. + * The predicate applied to the current state to determine when + * to stop. */ public GeneratingIterator(E initial, UnaryOperator<E> transition, Predicate<E> stopper) { state = initial; @@ -45,10 +45,9 @@ public class GeneratingIterator<E> implements Iterator<E> { } /* - * @NOTE - * As this currently is, it only works correctly assuming that - * next() is only called when hasNext() is true. Should we - * safeguard against people who are not doing the right thing? + * @NOTE As this currently is, it only works correctly assuming that + * next() is only called when hasNext() is true. Should we safeguard + * against people who are not doing the right thing? */ @Override public E next() { diff --git a/base/src/main/java/bjc/utils/data/IHolder.java b/base/src/main/java/bjc/utils/data/IHolder.java index 0b0cfd2..4d2ed2c 100644 --- a/base/src/main/java/bjc/utils/data/IHolder.java +++ b/base/src/main/java/bjc/utils/data/IHolder.java @@ -16,20 +16,19 @@ import bjc.utils.funcdata.theory.Functor; * @author ben * * @param <ContainedType> - * The type of value held. + * The type of value held. */ public interface IHolder<ContainedType> extends Functor<ContainedType> { /** * Bind a function across the value in this container. * * @param <BoundType> - * The type of value in this container. + * The type of value in this container. * * @param binder - * The function to bind to the value. + * The function to bind to the value. * - * @return - * A holder from binding the value. + * @return A holder from binding the value. */ public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder); @@ -37,7 +36,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { * Apply an action to the value. * * @param action - * The action to apply to the value. + * The action to apply to the value. */ public default void doWith(final Consumer<? super ContainedType> action) { transform(value -> { @@ -51,7 +50,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap( final Function<ArgType, ReturnType> func) { return argumentFunctor -> { - if (!(argumentFunctor instanceof IHolder<?>)) { + if(!(argumentFunctor instanceof IHolder<?>)) { final String msg = "This functor only supports mapping over instances of IHolder"; throw new IllegalArgumentException(msg); @@ -72,21 +71,19 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { * Lifts a function to bind over this holder. * * @param <NewType> - * The type of the functions return. + * The type of the functions return. * * @param func - * The function to lift over the holder. + * The function to lift over the holder. * - * @return - * The function lifted over the holder. + * @return The function lifted over the holder. */ public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func); /** * Make this holder lazy. * - * @return - * A lazy version of this holder. + * @return A lazy version of this holder. */ public default IHolder<ContainedType> makeLazy() { return new WrappedLazy<>(this); @@ -95,8 +92,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { /** * Make this holder a list. * - * @return - * A list version of this holder. + * @return A list version of this holder. */ public default IHolder<ContainedType> makeList() { return new BoundListHolder<>(new FunctionalList<>(this)); @@ -105,8 +101,7 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { /** * Make this holder optional. * - * @return - * An optional version of this holder. + * @return An optional version of this holder. */ public default IHolder<ContainedType> makeOptional() { return new WrappedOption<>(this); @@ -119,13 +114,12 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { * Does not change the internal state of this holder. * * @param <MappedType> - * The type of the mapped value. + * The type of the mapped value. * * @param mapper - * The function to do mapping with. + * The function to do mapping with. * - * @return - * A holder with the mapped value + * @return A holder with the mapped value */ public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper); @@ -133,10 +127,9 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { * Replace the held value with a new one. * * @param newValue - * The value to hold instead. + * The value to hold instead. * - * @return - * The holder itself. + * @return The holder itself. */ public default IHolder<ContainedType> replace(final ContainedType newValue) { return transform(oldValue -> { @@ -148,10 +141,9 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { * Transform the value held in this holder. * * @param transformer - * The function to transform the value with. + * The function to transform the value with. * - * @return - * The holder itself, for easy chaining. + * @return The holder itself, for easy chaining. */ public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer); @@ -160,13 +152,12 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { * held. * * @param <UnwrappedType> - * The type of the unwrapped value. + * The type of the unwrapped value. * * @param unwrapper - * The function to use to unwrap the value. + * The function to use to unwrap the value. * - * @return - * The unwrapped held value. + * @return The unwrapped held value. */ public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper); } diff --git a/base/src/main/java/bjc/utils/data/IPair.java b/base/src/main/java/bjc/utils/data/IPair.java index 75b092d..1c864d1 100644 --- a/base/src/main/java/bjc/utils/data/IPair.java +++ b/base/src/main/java/bjc/utils/data/IPair.java @@ -12,10 +12,10 @@ import bjc.utils.funcdata.theory.Bifunctor; * @author ben * * @param <LeftType> - * The type of the left side of the pair. + * The type of the left side of the pair. * * @param <RightType> - * The type of the right side of the pair. + * The type of the right side of the pair. * */ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightType> { @@ -23,16 +23,15 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * Bind a function across the values in this pair. * * @param <BoundLeft> - * The type of the bound left. + * The type of the bound left. * * @param <BoundRight> - * The type of the bound right. + * The type of the bound right. * * @param binder - * The function to bind with. + * The function to bind with. * - * @return - * The bound pair. + * @return The bound pair. */ public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder); @@ -41,13 +40,12 @@ 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. + * The type of the bound value. * * @param leftBinder - * The function to use to bind. + * The function to use to bind. * - * @return - * A pair with the left type bound. + * @return A pair with the left type bound. */ public <BoundLeft> IPair<BoundLeft, RightType> bindLeft( Function<LeftType, IPair<BoundLeft, RightType>> leftBinder); @@ -56,13 +54,12 @@ 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. + * The type of the bound value. * * @param rightBinder - * The function to use to bind. + * The function to use to bind. * - * @return - * A pair with the right type bound. + * @return A pair with the right type bound. */ public <BoundRight> IPair<LeftType, BoundRight> bindRight( Function<RightType, IPair<LeftType, BoundRight>> rightBinder); @@ -71,16 +68,15 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * Pairwise combine two pairs together. * * @param <OtherLeft> - * The left type of the other pair. + * The left type of the other pair. * * @param <OtherRight> - * The right type of the other pair. + * The right type of the other pair. * * @param otherPair - * The pair to combine with. + * The pair to combine with. * - * @return - * The pairs, pairwise combined together. + * @return The pairs, pairwise combined together. */ public default <OtherLeft, OtherRight> IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> combine( final IPair<OtherLeft, OtherRight> otherPair) { @@ -91,28 +87,27 @@ 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. + * The type of the left value of the other pair. * * @param <OtherRight> - * The type of the right value of the other pair. + * The type of the right value of the other pair. * * @param <CombinedLeft> - * The type of the left value of the combined pair. + * The type of the left value of the combined pair. * * @param <CombinedRight> - * The type of the right value of the combined pair. + * The type of the right value of the combined pair. * * @param otherPair - * The other pair to combine with. + * The other pair to combine with. * * @param leftCombiner - * The function to combine the left values with. + * The function to combine the left values with. * * @param rightCombiner - * The function to combine the right values with. + * The function to combine the right values with. * - * @return - * A pair with its values combined. + * @return A pair with its values combined. */ public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( IPair<OtherLeft, OtherRight> otherPair, @@ -124,7 +119,7 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * pair. * * @param consumer - * The action to perform on the pair. + * The action to perform on the pair. */ public default void doWith(final BiConsumer<LeftType, RightType> consumer) { merge((leftValue, rightValue) -> { @@ -135,10 +130,10 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp } @Override - default <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> - fmapLeft(final Function<OldLeft, NewLeft> func) { + default <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> fmapLeft( + final Function<OldLeft, NewLeft> func) { return argumentPair -> { - if (!(argumentPair instanceof IPair<?, ?>)) { + if(!(argumentPair instanceof IPair<?, ?>)) { final String msg = "This function can only be applied to instances of IPair"; throw new IllegalArgumentException(msg); @@ -151,10 +146,10 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp } @Override - default <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight> - fmapRight(final Function<OldRight, NewRight> func) { + default <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight> fmapRight( + final Function<OldRight, NewRight> func) { return argumentPair -> { - if (!(argumentPair instanceof IPair<?, ?>)) { + if(!(argumentPair instanceof IPair<?, ?>)) { final String msg = "This function can only be applied to instances of IPair"; throw new IllegalArgumentException(msg); @@ -169,8 +164,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. + * @return The value on the left side of the pair. */ @Override public default LeftType getLeft() { @@ -180,8 +174,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. + * @return The value on the right side of the pair. */ @Override public default RightType getRight() { @@ -189,19 +182,17 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp } /** - * Transform the value on the left side of the pair. + * 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. + * The new type of the left part of the pair. * * @param mapper - * The function to use to transform the left part of the - * pair. + * The function to use to transform the left part of the pair. * - * @return - * The pair, with its left part transformed. + * @return The pair, with its left part transformed. */ public <NewLeft> IPair<NewLeft, RightType> mapLeft(Function<LeftType, NewLeft> mapper); @@ -211,14 +202,12 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp * Doesn't modify the pair. * * @param <NewRight> - * The new type of the right part of the pair. + * The new type of the right part of the pair. * * @param mapper - * The function to use to transform the right part of the - * pair. + * The function to use to transform the right part of the pair. * - * @return - * The pair, with its right part transformed. + * @return The pair, with its right part transformed. */ public <NewRight> IPair<LeftType, NewRight> mapRight(Function<RightType, NewRight> mapper); @@ -226,13 +215,12 @@ 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. + * The type of the single value. * * @param merger - * The function to use for merging. + * The function to use for merging. * - * @return - * The pair, merged into a single value. + * @return The pair, merged into a single value. */ public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger); } diff --git a/base/src/main/java/bjc/utils/data/ITree.java b/base/src/main/java/bjc/utils/data/ITree.java index 450905b..5a4d645 100644 --- a/base/src/main/java/bjc/utils/data/ITree.java +++ b/base/src/main/java/bjc/utils/data/ITree.java @@ -14,7 +14,7 @@ import bjc.utils.functypes.ListFlattener; * @author ben * * @param <ContainedType> - * The type of data contained in the tree nodes. + * The type of data contained in the tree nodes. * */ public interface ITree<ContainedType> { @@ -22,7 +22,7 @@ public interface ITree<ContainedType> { * Append a child to this node. * * @param child - * The child to append to this node. + * The child to append to this node. */ void addChild(ITree<ContainedType> child); @@ -30,7 +30,7 @@ public interface ITree<ContainedType> { * Prepend a child to this node. * * @param child - * The child to prepend to this node. + * The child to prepend to this node. */ void prependChild(ITree<ContainedType> child); @@ -38,24 +38,23 @@ public interface ITree<ContainedType> { * Collapse a tree into a single version. * * @param <NewType> - * The intermediate type being folded. + * The intermediate type being folded. * * @param <ReturnedType> - * The type that is the end result. + * The type that is the end result. * * @param leafTransform - * The function to use to convert leaf values. + * The function to use to convert leaf values. * * @param nodeCollapser - * The function to use to convert internal nodes and - * their children. + * 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. + * The function to use to convert a state to the returned + * version. * - * @return - * The final transformed state. + * @return The final transformed state. */ <NewType, ReturnedType> ReturnedType collapse(Function<ContainedType, NewType> leafTransform, Function<ContainedType, ListFlattener<NewType>> nodeCollapser, @@ -65,7 +64,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. + * The action to execute for each child. */ void doForChildren(Consumer<ITree<ContainedType>> action); @@ -74,14 +73,13 @@ public interface ITree<ContainedType> { * those trees into a single tree. * * @param mapper - * The function to use to map values into trees. + * The function to use to map values into trees. * - * @return - * A tree, with some nodes expanded into trees. + * @return A tree, with some nodes expanded into trees. */ default ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) { return topDownTransform(dat -> TopDownTransformResult.PUSHDOWN, node -> { - if (node.getChildrenCount() > 0) { + if(node.getChildrenCount() > 0) { final ITree<ContainedType> parent = node.transformHead(mapper); node.doForChildren(parent::addChild); @@ -97,10 +95,9 @@ public interface ITree<ContainedType> { * Get the specified child of this tree. * * @param childNo - * The number of the child to get. + * The number of the child to get. * - * @return - * The specified child of this tree. + * @return The specified child of this tree. */ default ITree<ContainedType> getChild(final int childNo) { return transformChild(childNo, child -> child); @@ -109,16 +106,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. + * @return The number of direct children this node has. */ int getChildrenCount(); /** * Get the data stored in this node. * - * @return - * The data stored in this node. + * @return The data stored in this node. */ default ContainedType getHead() { return transformHead(head -> head); @@ -128,16 +123,15 @@ public interface ITree<ContainedType> { * Rebuild the tree with the same structure, but different nodes. * * @param <MappedType> - * The type of the new tree. + * The type of the new tree. * * @param leafTransformer - * The function to use to transform leaf tokens. + * The function to use to transform leaf tokens. * * @param internalTransformer - * The function to use to transform internal tokens. + * The function to use to transform internal tokens. * - * @return - * The tree, with the nodes changed. + * @return The tree, with the nodes changed. */ <MappedType> ITree<MappedType> rebuildTree(Function<ContainedType, MappedType> leafTransformer, Function<ContainedType, MappedType> internalTransformer); @@ -146,10 +140,10 @@ public interface ITree<ContainedType> { * Transform some of the nodes in this tree. * * @param nodePicker - * The predicate to use to pick nodes to transform. + * The predicate to use to pick nodes to transform. * * @param transformer - * The function to use to transform picked nodes. + * The function to use to transform picked nodes. */ void selectiveTransform(Predicate<ContainedType> nodePicker, UnaryOperator<ContainedType> transformer); @@ -157,13 +151,12 @@ public interface ITree<ContainedType> { * Do a top-down transform of the tree. * * @param transformPicker - * The function to use to pick how to progress. + * The function to use to pick how to progress. * * @param transformer - * The function used to transform picked subtrees. + * The function used to transform picked subtrees. * - * @return - * The tree with the transform applied to picked subtrees. + * @return The tree with the transform applied to picked subtrees. */ ITree<ContainedType> topDownTransform(Function<ContainedType, TopDownTransformResult> transformPicker, UnaryOperator<ITree<ContainedType>> transformer); @@ -172,20 +165,19 @@ public interface ITree<ContainedType> { * Transform one of this nodes children. * * @param <TransformedType> - * The type of the transformed value. + * The type of the transformed value. * * @param childNo - * The number of the child to transform. + * The number of the child to transform. * * @param transformer - * The function to use to transform the value. + * The function to use to transform the value. * - * @return - * The transformed value. + * @return The transformed value. * * @throws IllegalArgumentException - * if the childNo is out of bounds (0 <= childNo <= - * childCount()). + * if the childNo is out of bounds (0 <= childNo <= + * childCount()). */ <TransformedType> TransformedType transformChild(int childNo, Function<ITree<ContainedType>, TransformedType> transformer); @@ -194,13 +186,12 @@ public interface ITree<ContainedType> { * Transform the value that is the head of this node. * * @param <TransformedType> - * The type of the transformed value. + * The type of the transformed value. * * @param transformer - * The function to use to transform the value. + * The function to use to transform the value. * - * @return - * The transformed value. + * @return The transformed value. */ <TransformedType> TransformedType transformHead(Function<ContainedType, TransformedType> transformer); @@ -208,13 +199,12 @@ public interface ITree<ContainedType> { * Transform the tree into a tree with a different type of token. * * @param <MappedType> - * The type of the new tree. + * The type of the new tree. * * @param transformer - * The function to use to transform tokens. + * The function to use to transform tokens. * - * @return - * A tree with the token types transformed. + * @return A tree with the token types transformed. */ default <MappedType> ITree<MappedType> transformTree(final Function<ContainedType, MappedType> transformer) { return rebuildTree(transformer, transformer); @@ -224,10 +214,10 @@ public interface ITree<ContainedType> { * Perform an action on each part of the tree. * * @param linearizationMethod - * The way to traverse the tree. + * The way to traverse the tree. * * @param action - * The action to perform on each tree node. + * The action to perform on each tree node. */ void traverse(TreeLinearizationMethod linearizationMethod, Consumer<ContainedType> action); @@ -235,11 +225,10 @@ public interface ITree<ContainedType> { * Find the farthest to right child that satisfies the given predicate. * * @param childPred - * The predicate to satisfy. + * The predicate to satisfy. * - * @return - * The index of the right-most child that satisfies the predicate, - * or -1 if one doesn't exist. + * @return The index of the right-most child that satisfies the + * predicate, or -1 if one doesn't exist. */ int revFind(Predicate<ITree<ContainedType>> childPred); } diff --git a/base/src/main/java/bjc/utils/data/Identity.java b/base/src/main/java/bjc/utils/data/Identity.java index 3acb5aa..44ddc31 100644 --- a/base/src/main/java/bjc/utils/data/Identity.java +++ b/base/src/main/java/bjc/utils/data/Identity.java @@ -9,7 +9,7 @@ import java.util.function.UnaryOperator; * @author ben * * @param <ContainedType> - * The type contained in the holder. + * The type contained in the holder. */ public class Identity<ContainedType> implements IHolder<ContainedType> { /* The held value. */ @@ -24,7 +24,7 @@ public class Identity<ContainedType> implements IHolder<ContainedType> { * Create a holder holding the specified value. * * @param value - * The value to hold. + * The value to hold. */ public Identity(final ContainedType value) { heldValue = value; @@ -47,15 +47,15 @@ public class Identity<ContainedType> implements IHolder<ContainedType> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof Identity)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof Identity)) return false; final Identity<?> other = (Identity<?>) obj; - if (heldValue == null) { - if (other.heldValue != null) return false; - } else if (!heldValue.equals(other.heldValue)) return false; + if(heldValue == null) { + if(other.heldValue != null) return false; + } else if(!heldValue.equals(other.heldValue)) return false; return true; } @@ -93,10 +93,9 @@ public class Identity<ContainedType> implements IHolder<ContainedType> { * Create a new identity container. * * @param val - * The contained value. + * The contained value. * - * @return - * A new identity container. + * @return A new identity container. */ public static <ContainedType> Identity<ContainedType> id(final ContainedType val) { return new Identity<>(val); @@ -105,8 +104,7 @@ public class Identity<ContainedType> implements IHolder<ContainedType> { /** * Create a new empty identity container. * - * @return - * A new empty identity container. + * @return A new empty identity container. */ public static <ContainedType> Identity<ContainedType> id() { return new Identity<>(); diff --git a/base/src/main/java/bjc/utils/data/LazyPair.java b/base/src/main/java/bjc/utils/data/LazyPair.java index 548a09e..0500486 100644 --- a/base/src/main/java/bjc/utils/data/LazyPair.java +++ b/base/src/main/java/bjc/utils/data/LazyPair.java @@ -13,40 +13,40 @@ import bjc.utils.data.internals.HalfBoundLazyPair; * @author ben * * @param <LeftType> - * The type on the left side of the pair. + * The type on the left side of the pair. * * @param <RightType> - * The type on the right side of the pair. + * The type on the right side of the pair. */ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> { /* The supplier for the left value. */ - private Supplier<LeftType> leftSupplier; + private Supplier<LeftType> leftSupplier; /* The left value. */ private LeftType leftValue; /* Whether the left value has been created. */ - private boolean leftMaterialized; + private boolean leftMaterialized; /* The supplier for the right value. */ private Supplier<RightType> rightSupplier; /* The right value. */ private RightType rightValue; /* Whether the right value has been created. */ - private boolean rightMaterialized; + private boolean rightMaterialized; /** * Create a new lazy pair, using the set values. * * @param leftVal - * The value for the left side of the pair. + * The value for the left side of the pair. * * @param rightVal - * The value for the right side of the pair. + * The value for the right side of the pair. */ public LazyPair(final LeftType leftVal, final RightType rightVal) { - leftValue = leftVal; + leftValue = leftVal; rightValue = rightVal; - leftMaterialized = true; + leftMaterialized = true; rightMaterialized = true; } @@ -54,17 +54,17 @@ 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. + * The source for a value on the left side of the pair. * * @param rightSupp - * The source for a value on the right side of the pair. + * The source for a value on the right side of the pair. */ public LazyPair(final Supplier<LeftType> leftSupp, final Supplier<RightType> rightSupp) { /* Use single suppliers to catch double-instantiation bugs. */ - leftSupplier = new SingleSupplier<>(leftSupp); + leftSupplier = new SingleSupplier<>(leftSupp); rightSupplier = new SingleSupplier<>(rightSupp); - leftMaterialized = false; + leftMaterialized = false; rightMaterialized = false; } @@ -78,7 +78,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> public <BoundLeft> IPair<BoundLeft, RightType> bindLeft( final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) { final Supplier<LeftType> leftSupp = () -> { - if (leftMaterialized) return leftValue; + if(leftMaterialized) return leftValue; return leftSupplier.get(); }; @@ -90,7 +90,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> public <BoundRight> IPair<LeftType, BoundRight> bindRight( final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) { final Supplier<RightType> rightSupp = () -> { - if (rightMaterialized) return rightValue; + if(rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -105,7 +105,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { - final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); + final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); final CombinedRight right = rightCombiner.apply(rightVal, otherRight); return new LazyPair<>(left, right); @@ -115,7 +115,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public LeftType getLeft() { - if (!leftMaterialized) { + if(!leftMaterialized) { leftValue = leftSupplier.get(); leftMaterialized = true; @@ -126,7 +126,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public RightType getRight() { - if (!rightMaterialized) { + if(!rightMaterialized) { rightValue = rightSupplier.get(); rightMaterialized = true; @@ -138,13 +138,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public <NewLeft> IPair<NewLeft, RightType> mapLeft(final Function<LeftType, NewLeft> mapper) { final Supplier<NewLeft> leftSupp = () -> { - if (leftMaterialized) return mapper.apply(leftValue); + if(leftMaterialized) return mapper.apply(leftValue); return mapper.apply(leftSupplier.get()); }; final Supplier<RightType> rightSupp = () -> { - if (rightMaterialized) return rightValue; + if(rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -155,13 +155,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public <NewRight> IPair<LeftType, NewRight> mapRight(final Function<RightType, NewRight> mapper) { final Supplier<LeftType> leftSupp = () -> { - if (leftMaterialized) return leftValue; + if(leftMaterialized) return leftValue; return leftSupplier.get(); }; final Supplier<NewRight> rightSupp = () -> { - if (rightMaterialized) return mapper.apply(rightValue); + if(rightMaterialized) return mapper.apply(rightValue); return mapper.apply(rightSupplier.get()); }; @@ -171,13 +171,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public <MergedType> MergedType merge(final BiFunction<LeftType, RightType, MergedType> merger) { - if (!leftMaterialized) { + if(!leftMaterialized) { leftValue = leftSupplier.get(); leftMaterialized = true; } - if (!rightMaterialized) { + if(!rightMaterialized) { rightValue = rightSupplier.get(); rightMaterialized = true; @@ -191,13 +191,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> String leftVal; String rightVal; - if (leftMaterialized) { + if(leftMaterialized) { leftVal = leftValue.toString(); } else { leftVal = "(un-materialized)"; } - if (rightMaterialized) { + if(rightMaterialized) { rightVal = rightValue.toString(); } else { rightVal = "(un-materialized)"; @@ -221,26 +221,28 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof LazyPair<?, ?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof LazyPair<?, ?>)) return false; final LazyPair<?, ?> other = (LazyPair<?, ?>) obj; - if (leftMaterialized != other.leftMaterialized) return false; - - if (leftMaterialized) { - if (leftValue == null) { - if (other.leftValue != null) return false; - } else if (!leftValue.equals(other.leftValue)) return false; - } else return false; - - if (rightMaterialized != other.rightMaterialized) return false; - if (rightMaterialized) { - if (rightValue == null) { - if (other.rightValue != null) return false; - } else if (!rightValue.equals(other.rightValue)) return false; - } else return false; + if(leftMaterialized != other.leftMaterialized) return false; + + if(leftMaterialized) { + if(leftValue == null) { + if(other.leftValue != null) return false; + } else if(!leftValue.equals(other.leftValue)) return false; + } else + return false; + + if(rightMaterialized != other.rightMaterialized) return false; + if(rightMaterialized) { + if(rightValue == null) { + if(other.rightValue != null) return false; + } else if(!rightValue.equals(other.rightValue)) return false; + } else + return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/ListHolder.java b/base/src/main/java/bjc/utils/data/ListHolder.java index 4564466..dbcdf6e 100644 --- a/base/src/main/java/bjc/utils/data/ListHolder.java +++ b/base/src/main/java/bjc/utils/data/ListHolder.java @@ -13,7 +13,7 @@ import bjc.utils.funcdata.IList; * @author ben * * @param <ContainedType> - * The type of contained value. + * The type of contained value. */ public class ListHolder<ContainedType> implements IHolder<ContainedType> { private IList<ContainedType> heldValues; @@ -22,14 +22,14 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> { * Create a new list holder. * * @param values - * The possible values for the computation. + * The possible values for the computation. */ @SafeVarargs public ListHolder(final ContainedType... values) { heldValues = new FunctionalList<>(); - if (values != null) { - for (final ContainedType containedValue : values) { + if(values != null) { + for(final ContainedType containedValue : values) { heldValues.add(containedValue); } } @@ -90,15 +90,15 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof ListHolder<?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof ListHolder<?>)) return false; final ListHolder<?> other = (ListHolder<?>) obj; - if (heldValues == null) { - if (other.heldValues != null) return false; - } else if (!heldValues.equals(other.heldValues)) return false; + if(heldValues == null) { + if(other.heldValues != null) return false; + } else if(!heldValues.equals(other.heldValues)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/Option.java b/base/src/main/java/bjc/utils/data/Option.java index 6eae21f..7869946 100644 --- a/base/src/main/java/bjc/utils/data/Option.java +++ b/base/src/main/java/bjc/utils/data/Option.java @@ -9,7 +9,7 @@ import java.util.function.UnaryOperator; * @author ben * * @param <ContainedType> - * The type of the value that may or may not be held. + * The type of the value that may or may not be held. */ public class Option<ContainedType> implements IHolder<ContainedType> { private ContainedType held; @@ -18,7 +18,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. + * The initial value for the optional. */ public Option(final ContainedType seed) { held = seed; @@ -26,7 +26,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> { @Override public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) { - if (held == null) return new Option<>(null); + if(held == null) return new Option<>(null); return binder.apply(held); } @@ -40,14 +40,14 @@ public class Option<ContainedType> implements IHolder<ContainedType> { @Override public <MappedType> IHolder<MappedType> map(final 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(final UnaryOperator<ContainedType> transformer) { - if (held != null) { + if(held != null) { held = transformer.apply(held); } @@ -56,7 +56,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> { @Override public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) { - if (held == null) return null; + if(held == null) return null; return unwrapper.apply(held); } @@ -78,15 +78,15 @@ public class Option<ContainedType> implements IHolder<ContainedType> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof Option<?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof Option<?>)) return false; final Option<?> other = (Option<?>) obj; - if (held == null) { - if (other.held != null) return false; - } else if (!held.equals(other.held)) return false; + if(held == null) { + if(other.held != null) return false; + } else if(!held.equals(other.held)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/Pair.java b/base/src/main/java/bjc/utils/data/Pair.java index fb81e17..40e4849 100644 --- a/base/src/main/java/bjc/utils/data/Pair.java +++ b/base/src/main/java/bjc/utils/data/Pair.java @@ -9,10 +9,10 @@ import java.util.function.Function; * @author ben * * @param <LeftType> - * The type of the left value. + * The type of the left value. * * @param <RightType> - * The type of the right value. + * The type of the right value. */ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> { /* The left value. */ @@ -29,20 +29,20 @@ 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. + * The value of the left side. * * @param right - * The value of the right side. + * The value of the right side. */ public Pair(final LeftType left, final RightType right) { - leftValue = left; + leftValue = left; rightValue = right; } @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { - if (binder == null) throw new NullPointerException("Binder must not be null."); + if(binder == null) throw new NullPointerException("Binder must not be null."); return binder.apply(leftValue, rightValue); } @@ -50,7 +50,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <BoundLeft> IPair<BoundLeft, RightType> bindLeft( final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) { - if (leftBinder == null) throw new NullPointerException("Binder must not be null"); + if(leftBinder == null) throw new NullPointerException("Binder must not be null"); return leftBinder.apply(leftValue); } @@ -58,7 +58,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <BoundRight> IPair<LeftType, BoundRight> bindRight( final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) { - if (rightBinder == null) throw new NullPointerException("Binder must not be null"); + if(rightBinder == null) throw new NullPointerException("Binder must not be null"); return rightBinder.apply(rightValue); } @@ -69,7 +69,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> { final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { - final CombinedLeft left = leftCombiner.apply(leftValue, otherLeft); + final CombinedLeft left = leftCombiner.apply(leftValue, otherLeft); final CombinedRight right = rightCombiner.apply(rightValue, otherRight); return new Pair<>(left, right); @@ -78,21 +78,21 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public <NewLeft> IPair<NewLeft, RightType> mapLeft(final 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(final 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(final 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); } @@ -115,19 +115,19 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof Pair<?, ?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof Pair<?, ?>)) return false; final Pair<?, ?> other = (Pair<?, ?>) obj; - if (leftValue == null) { - if (other.leftValue != null) return false; - } else if (!leftValue.equals(other.leftValue)) return false; + if(leftValue == null) { + if(other.leftValue != null) return false; + } else if(!leftValue.equals(other.leftValue)) return false; - if (rightValue == null) { - if (other.rightValue != null) return false; - } else if (!rightValue.equals(other.rightValue)) return false; + if(rightValue == null) { + if(other.rightValue != null) return false; + } else if(!rightValue.equals(other.rightValue)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/SingleIterator.java b/base/src/main/java/bjc/utils/data/SingleIterator.java index 1241a68..561cd0b 100644 --- a/base/src/main/java/bjc/utils/data/SingleIterator.java +++ b/base/src/main/java/bjc/utils/data/SingleIterator.java @@ -8,7 +8,7 @@ import java.util.Iterator; * @author EVE * * @param <T> - * The type of the item. + * The type of the item. */ public class SingleIterator<T> implements Iterator<T> { /* The item being held. */ @@ -20,7 +20,7 @@ public class SingleIterator<T> implements Iterator<T> { * Create a iterator that yields a single item. * * @param item - * The item to yield. + * The item to yield. */ public SingleIterator(final T item) { itm = item; diff --git a/base/src/main/java/bjc/utils/data/SingleSupplier.java b/base/src/main/java/bjc/utils/data/SingleSupplier.java index 60f9136..8054d33 100644 --- a/base/src/main/java/bjc/utils/data/SingleSupplier.java +++ b/base/src/main/java/bjc/utils/data/SingleSupplier.java @@ -10,7 +10,7 @@ import java.util.function.Supplier; * @author ben * * @param <T> - * The supplied type + * The supplied type */ public class SingleSupplier<T> implements Supplier<T> { /* The next supplier ID. */ @@ -25,10 +25,9 @@ public class SingleSupplier<T> implements Supplier<T> { /* * The place where the supplier was instantiated. * - * @NOTE - * This is both slow to create, and generally bad practice to keep - * exceptions around without throwing them. However, it is very - * useful to find where the first instantiation was. + * @NOTE This is both slow to create, and generally bad practice to keep + * exceptions around without throwing them. However, it is very useful + * to find where the first instantiation was. */ private Exception instSite; @@ -36,7 +35,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. + * The supplier to give a single value from. */ public SingleSupplier(final Supplier<T> supp) { source = supp; @@ -48,7 +47,7 @@ public class SingleSupplier<T> implements Supplier<T> { @Override public T get() { - if (gotten == true) { + if(gotten == true) { final String msg = String.format( "Attempted to retrieve value more than once from single supplier #%d", id); @@ -63,7 +62,7 @@ public class SingleSupplier<T> implements Supplier<T> { try { throw new IllegalStateException("Previous instantiation here."); - } catch (final IllegalStateException isex) { + } catch(final IllegalStateException isex) { instSite = isex; } diff --git a/base/src/main/java/bjc/utils/data/Toggle.java b/base/src/main/java/bjc/utils/data/Toggle.java index a1467e4..4e7b7d8 100644 --- a/base/src/main/java/bjc/utils/data/Toggle.java +++ b/base/src/main/java/bjc/utils/data/Toggle.java @@ -6,23 +6,21 @@ package bjc.utils.data; * @author EVE * * @param <E> - * The value stored in the toggle. + * The value stored in the toggle. */ public interface Toggle<E> { /** * Retrieve the currently-aligned value of this toggle, and swap the * value to the new one. * - * @return - * The previously-aligned value. + * @return The previously-aligned value. */ E get(); /** * Retrieve the currently-aligned value without altering the alignment. * - * @return - * The currently-aligned value. + * @return The currently-aligned value. */ E peek(); @@ -30,7 +28,7 @@ public interface Toggle<E> { * Change the alignment of the toggle. * * @param isLeft - * Whether the toggle should be left-aligned or not. + * Whether the toggle should be left-aligned or not. */ void set(boolean isLeft); } diff --git a/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java b/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java index c6b7d31..8f3e40c 100644 --- a/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java +++ b/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java @@ -50,7 +50,7 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C } public void addYield(final Iterator<ITree<ContainedType>> src) { - if (curYield != null) { + if(curYield != null) { toYield.push(curYield); } @@ -63,51 +63,54 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C } public ITree<ContainedType> flushYields(final 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()) { + 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) { + 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)); } @@ -127,8 +130,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 +147,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,13 +162,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()); final ITree<ContainedType> res = curChild.next(); @@ -176,12 +179,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 (final ITree<ContainedType> child : postChildren) { + for(final ITree<ContainedType> child : postChildren) { res.addChild(child); } @@ -191,7 +194,7 @@ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<C res = postParent; System.out.println("\t\tTRACE: adding nodes " + postChildren + " to " + res); - for (final ITree<ContainedType> child : postChildren) { + for(final ITree<ContainedType> child : postChildren) { res.addChild(child); } } diff --git a/base/src/main/java/bjc/utils/data/TransformIterator.java b/base/src/main/java/bjc/utils/data/TransformIterator.java index 5a6ac85..9ce3b20 100644 --- a/base/src/main/java/bjc/utils/data/TransformIterator.java +++ b/base/src/main/java/bjc/utils/data/TransformIterator.java @@ -9,10 +9,10 @@ import java.util.function.Function; * @author EVE * * @param <S> - * The source iterator type. + * The source iterator type. * * @param <D> - * The destination iterator type. + * The destination iterator type. */ public class TransformIterator<S, D> implements Iterator<D> { /* Our source of values. */ @@ -24,10 +24,10 @@ public class TransformIterator<S, D> implements Iterator<D> { * Create a new transform iterator. * * @param source - * The source iterator to use. + * The source iterator to use. * * @param transform - * The transform to apply. + * The transform to apply. */ public TransformIterator(final Iterator<S> source, final Function<S, D> transform) { this.source = source; diff --git a/base/src/main/java/bjc/utils/data/Tree.java b/base/src/main/java/bjc/utils/data/Tree.java index 386153b..6b7e03a 100644 --- a/base/src/main/java/bjc/utils/data/Tree.java +++ b/base/src/main/java/bjc/utils/data/Tree.java @@ -16,7 +16,7 @@ import bjc.utils.functypes.ListFlattener; * @author ben * * @param <ContainedType> - * The type contained in the tree. + * The type contained in the tree. */ public class Tree<ContainedType> implements ITree<ContainedType> { /* The data/label for this node. */ @@ -26,17 +26,16 @@ public class Tree<ContainedType> implements ITree<ContainedType> { private IList<ITree<ContainedType>> children; /* Whether this node has children. */ - /* @NOTE - * Why have both this boolean and childCount? Why not just do a - * childCount == 0 - * whenever you'd check hasChildren? + /* + * @NOTE Why have both this boolean and childCount? Why not just do a + * childCount == 0 whenever you'd check hasChildren? */ private boolean hasChildren; /* The number of children this node has. */ - private int childCount = 0; + private int childCount = 0; /* The ID of this node. */ - private int ID; + private int ID; /* The next ID to assign to a node. */ private static int nextID = 0; @@ -44,7 +43,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { * Create a new leaf node in a tree. * * @param leaf - * The data to store as a leaf node. + * The data to store as a leaf node. */ public Tree(final ContainedType leaf) { data = leaf; @@ -58,10 +57,10 @@ 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. + * The data to hold in this node. * * @param childrn - * A list of children for this node. + * A list of children for this node. */ public Tree(final ContainedType leaf, final IList<ITree<ContainedType>> childrn) { this(leaf); @@ -77,10 +76,10 @@ 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. + * The data to hold in this node. * * @param childrn - * A list of children for this node. + * A list of children for this node. */ @SafeVarargs public Tree(final ContainedType leaf, final ITree<ContainedType>... childrn) { @@ -92,7 +91,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { children = new FunctionalList<>(); - for (final ITree<ContainedType> child : childrn) { + for(final ITree<ContainedType> child : childrn) { children.add(child); childCount++; @@ -101,7 +100,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public void addChild(final ITree<ContainedType> child) { - if (hasChildren == false) { + if(hasChildren == false) { hasChildren = true; children = new FunctionalList<>(); @@ -114,7 +113,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public void prependChild(final ITree<ContainedType> child) { - if (hasChildren == false) { + if(hasChildren == false) { hasChildren = true; children = new FunctionalList<>(); @@ -127,7 +126,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public void doForChildren(final Consumer<ITree<ContainedType>> action) { - if (childCount > 0) { + if(childCount > 0) { children.forEach(action); } } @@ -139,11 +138,11 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public int revFind(final Predicate<ITree<ContainedType>> childPred) { - if (childCount == 0) { + if(childCount == 0) { return -1; } else { - for (int i = childCount - 1; i >= 0; i--) { - if (childPred.test(getChild(i))) return i; + for(int i = childCount - 1; i >= 0; i--) { + if(childPred.test(getChild(i))) return i; } return -1; @@ -152,10 +151,10 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public void traverse(final TreeLinearizationMethod linearizationMethod, final Consumer<ContainedType> action) { - if (hasChildren) { - switch (linearizationMethod) { + if(hasChildren) { + switch(linearizationMethod) { case INORDER: - if (childCount != 2) { + if(childCount != 2) { final String msg = "Can only do in-order traversal for binary trees."; throw new IllegalArgumentException(msg); @@ -195,7 +194,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) { - if (hasChildren) { + if(hasChildren) { final ITree<ContainedType> flatMappedData = mapper.apply(data); final IList<ITree<ContainedType>> mappedChildren = children @@ -212,14 +211,13 @@ public class Tree<ContainedType> implements ITree<ContainedType> { /* * Do a collapse of this tree. * - * @NOTE - * Why is this protected? I can't see any good reason someone'd - * want to override it. + * @NOTE Why is this protected? I can't see any good reason someone'd + * want to override it. */ protected <NewType> NewType internalCollapse(final Function<ContainedType, NewType> leafTransform, final Function<ContainedType, ListFlattener<NewType>> nodeCollapser) { - if (hasChildren) { + if(hasChildren) { final Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser.apply(data); final IList<NewType> collapsedChildren = children.map(child -> { @@ -236,7 +234,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { } protected void internalToString(final StringBuilder builder, final int indentLevel, final boolean initial) { - for (int i = 0; i < indentLevel; i++) { + for(int i = 0; i < indentLevel; i++) { builder.append(">\t"); } @@ -246,14 +244,14 @@ public class Tree<ContainedType> implements ITree<ContainedType> { builder.append(data == null ? "(null)" : data.toString()); builder.append("\n"); - if (hasChildren) { + if(hasChildren) { children.forEach(child -> { - if (child instanceof Tree<?>) { + if(child instanceof Tree<?>) { final Tree<ContainedType> kid = (Tree<ContainedType>) child; kid.internalToString(builder, indentLevel + 1, false); } else { - for (int i = 0; i < indentLevel + 1; i++) { + for(int i = 0; i < indentLevel + 1; i++) { builder.append(">\t"); } @@ -268,7 +266,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public <MappedType> ITree<MappedType> rebuildTree(final Function<ContainedType, MappedType> leafTransformer, final Function<ContainedType, MappedType> operatorTransformer) { - if (hasChildren) { + if(hasChildren) { final IList<ITree<MappedType>> mappedChildren = children.map(child -> { return child.rebuildTree(leafTransformer, operatorTransformer); }); @@ -283,7 +281,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public void selectiveTransform(final Predicate<ContainedType> nodePicker, final UnaryOperator<ContainedType> transformer) { - if (hasChildren) { + if(hasChildren) { children.forEach(child -> child.selectiveTransform(nodePicker, transformer)); } else { data = transformer.apply(data); @@ -296,11 +294,11 @@ public class Tree<ContainedType> implements ITree<ContainedType> { final UnaryOperator<ITree<ContainedType>> transformer) { final TopDownTransformResult transformResult = transformPicker.apply(data); - switch (transformResult) { + switch(transformResult) { case PASSTHROUGH: ITree<ContainedType> result = new Tree<>(data); - if (hasChildren) { + if(hasChildren) { children.forEach(child -> { final ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer); @@ -319,7 +317,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { case PUSHDOWN: result = new Tree<>(data); - if (hasChildren) { + if(hasChildren) { children.forEach(child -> { final ITree<ContainedType> kid = child.topDownTransform(transformPicker, transformer); @@ -351,7 +349,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public <TransformedType> TransformedType transformChild(final int childNo, final Function<ITree<ContainedType>, TransformedType> transformer) { - if (childNo < 0 || childNo > childCount - 1) { + if(childNo < 0 || childNo > childCount - 1) { final String msg = String.format("Child index #%d is invalid", childNo); throw new IllegalArgumentException(msg); @@ -394,21 +392,21 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof Tree<?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof Tree<?>)) return false; final Tree<?> other = (Tree<?>) obj; - if (data == null) { - if (other.data != null) return false; - } else if (!data.equals(other.data)) return false; + if(data == null) { + 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(children == null) { + if(other.children != null) return false; + } else if(!children.equals(other.children)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/data/ValueToggle.java b/base/src/main/java/bjc/utils/data/ValueToggle.java index 54c7a57..09f314c 100644 --- a/base/src/main/java/bjc/utils/data/ValueToggle.java +++ b/base/src/main/java/bjc/utils/data/ValueToggle.java @@ -6,13 +6,13 @@ package bjc.utils.data; * @author EVE * * @param <E> - * The type of value to toggle between. + * The type of value to toggle between. */ public class ValueToggle<E> implements Toggle<E> { /* Our left value. */ - private final E lft; + private final E lft; /* Our right value. */ - private final E rght; + private final E rght; /* Our alignment. */ private final BooleanToggle alignment; @@ -22,10 +22,10 @@ public class ValueToggle<E> implements Toggle<E> { * All toggles start right-aligned. * * @param left - * The value when the toggle is left-aligned. + * The value when the toggle is left-aligned. * * @param right - * The value when the toggle is right-aligned. + * The value when the toggle is right-aligned. */ public ValueToggle(final E left, final E right) { lft = left; @@ -37,7 +37,7 @@ public class ValueToggle<E> implements Toggle<E> { @Override public E get() { - if (alignment.get()) { + if(alignment.get()) { return lft; } else { return rght; @@ -46,7 +46,7 @@ public class ValueToggle<E> implements Toggle<E> { @Override public E peek() { - if (alignment.peek()) { + if(alignment.peek()) { return lft; } else { return rght; diff --git a/base/src/main/java/bjc/utils/data/internals/BoundLazy.java b/base/src/main/java/bjc/utils/data/internals/BoundLazy.java index a1c2ea0..f4e8f7e 100644 --- a/base/src/main/java/bjc/utils/data/internals/BoundLazy.java +++ b/base/src/main/java/bjc/utils/data/internals/BoundLazy.java @@ -32,13 +32,13 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont private final IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>(); /** - * Create a new bound lazy value. + * Create a new bound lazy value. * * @param supp - * The supplier of the old value. + * The supplier of the old value. * * @param binder - * The function to use to bind the old value to the new one. + * The function to use to bind the old value to the new one. */ public BoundLazy(final Supplier<IHolder<OldType>> supp, final Function<OldType, IHolder<BoundContainedType>> binder) { @@ -48,7 +48,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont @Override public <BoundType> IHolder<BoundType> bind(final 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. */ final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>(); @@ -59,7 +59,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont IHolder<BoundContainedType> oldHolder = boundHolder; /* Bind the value if it hasn't been bound before. */ - if (!holderBound) { + if(!holderBound) { oldHolder = oldSupplier.get().unwrap(binder); } @@ -75,7 +75,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont @Override public <NewType> Function<BoundContainedType, IHolder<NewType>> lift( final Function<BoundContainedType, NewType> func) { - if (func == null) throw new NullPointerException("Function to lift must not be null"); + if(func == null) throw new NullPointerException("Function to lift must not be null"); return (val) -> { return new Lazy<>(func.apply(val)); @@ -84,7 +84,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont @Override public <MappedType> IHolder<MappedType> map(final 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. */ final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>(); @@ -95,7 +95,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); } @@ -110,14 +110,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(final 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); @@ -126,9 +126,9 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont @Override public <UnwrappedType> UnwrappedType unwrap(final 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/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java b/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java index 401f5d5..2ef0e4c 100644 --- a/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java +++ b/base/src/main/java/bjc/utils/data/internals/BoundLazyPair.java @@ -34,13 +34,14 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai * Create a new bound lazy pair. * * @param leftSupp - * The supplier for the left value. + * The supplier for the left value. * * @param rightSupp - * The supplier for the right value. + * The supplier for the right value. * * @param bindr - * The function to use to bind the left and right into a new pair. + * The function to use to bind the left and right into a new + * pair. */ public BoundLazyPair(final Supplier<OldLeft> leftSupp, final Supplier<OldRight> rightSupp, final BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) { @@ -52,13 +53,13 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( final BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) { - if (bindr == null) throw new NullPointerException("Binder must not be null"); + if(bindr == null) throw new NullPointerException("Binder must not be null"); final IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair); - final IHolder<Boolean> newPairMade = new Identity<>(pairBound); + final IHolder<Boolean> newPairMade = new Identity<>(pairBound); final Supplier<NewLeft> leftSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { /* * If the pair hasn't been bound before, bind * it. @@ -72,7 +73,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai }; final Supplier<NewRight> rightSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { /* * If the pair hasn't been bound before, bind * it. @@ -91,12 +92,12 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai @Override public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft( final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) { - if (leftBinder == null) throw new NullPointerException("Left binder must not be null"); + if(leftBinder == null) throw new NullPointerException("Left binder must not be null"); final Supplier<NewLeft> leftSupp = () -> { IPair<NewLeft, NewRight> newPair = boundPair; - if (!pairBound) { + if(!pairBound) { /* * If the pair hasn't been bound before, bind * it. @@ -113,12 +114,12 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai @Override public <BoundRight> IPair<NewLeft, BoundRight> bindRight( final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) { - if (rightBinder == null) throw new NullPointerException("Right binder must not be null"); + if(rightBinder == null) throw new NullPointerException("Right binder must not be null"); final Supplier<NewRight> rightSupp = () -> { IPair<NewLeft, NewRight> newPair = boundPair; - if (!pairBound) { + if(!pairBound) { /* * If the pair hasn't been bound before, bind * it. @@ -137,17 +138,17 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai final IPair<OtherLeft, OtherRight> otherPair, final BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner, final 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) { + } else if(rightCombiner == null) { throw new NullPointerException("Right combiner must not be null"); } return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { - CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft); + CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft); CombinedRight cRight = rightCombiner.apply(rightVal, otherRight); return new LazyPair<>(cLeft, cRight); @@ -157,10 +158,10 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai @Override public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final 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"); final Supplier<NewLeftType> leftSupp = () -> { - if (!pairBound) { + if(!pairBound) { final NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return mapper.apply(leftVal); @@ -170,7 +171,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai }; final 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(); }; @@ -180,16 +181,16 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai @Override public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final 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"); final 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(); }; final Supplier<NewRightType> rightSupp = () -> { - if (!pairBound) { + if(!pairBound) { final NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()) .getRight(); @@ -204,9 +205,9 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai @Override public <MergedType> MergedType merge(final 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) { /* * If the pair isn't bound yet, bind it. */ @@ -220,7 +221,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/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java b/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java index 31178da..613f8e9 100644 --- a/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java +++ b/base/src/main/java/bjc/utils/data/internals/BoundListHolder.java @@ -21,7 +21,7 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> { * Create a new list of holders. * * @param toHold - * The list of holders to, well, hold. + * The list of holders to, well, hold. */ public BoundListHolder(final IList<IHolder<ContainedType>> toHold) { heldHolders = toHold; @@ -29,7 +29,7 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> { @Override public <BoundType> IHolder<BoundType> bind(final 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"); final IList<IHolder<BoundType>> boundHolders = heldHolders.map((containedHolder) -> { return containedHolder.bind(binder); @@ -40,7 +40,7 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> { @Override public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) { - if (func == null) throw new NullPointerException("Function to lift must not be null"); + if(func == null) throw new NullPointerException("Function to lift must not be null"); return (val) -> { return new ListHolder<>(func.apply(val)); @@ -49,7 +49,7 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> { @Override public <MappedType> IHolder<MappedType> map(final 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"); final IList<IHolder<MappedType>> mappedHolders = heldHolders.map((containedHolder) -> { return containedHolder.map(mapper); @@ -60,7 +60,7 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> { @Override public IHolder<ContainedType> transform(final 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); @@ -71,11 +71,10 @@ public class BoundListHolder<ContainedType> implements IHolder<ContainedType> { @Override public <UnwrappedType> UnwrappedType unwrap(final 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"); /* - * @NOTE - * Is there another way we could want to do this? + * @NOTE Is there another way we could want to do this? */ return heldHolders.randItem().unwrap(unwrapper); } diff --git a/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java b/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java index 5467255..4803bc2 100644 --- a/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java +++ b/base/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java @@ -31,18 +31,18 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL private final Function<OldType, IPair<NewLeft, NewRight>> binder; /* The new bound pair. */ - private IPair<NewLeft, NewRight> boundPair; + private IPair<NewLeft, NewRight> boundPair; /* Has the pair been bound yet or not? */ - private boolean pairBound; + private boolean pairBound; /** * Create a new half-bound lazy pair. * * @param oldSupp - * The supplier of the old value. + * The supplier of the old value. * * @param bindr - * The function to use to create the pair from the old value. + * The function to use to create the pair from the old value. */ public HalfBoundLazyPair(final Supplier<OldType> oldSupp, final Function<OldType, IPair<NewLeft, NewRight>> bindr) { @@ -57,7 +57,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL final IHolder<Boolean> newPairMade = new Identity<>(pairBound); final Supplier<NewLeft> leftSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { /* Bind the pair if it hasn't been bound yet. */ newPair.replace(binder.apply(oldSupplier.get())); newPairMade.replace(true); @@ -67,7 +67,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL }; final Supplier<NewRight> rightSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { /* Bind the pair if it hasn't been bound yet. */ newPair.replace(binder.apply(oldSupplier.get())); newPairMade.replace(true); @@ -85,7 +85,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL final Supplier<NewLeft> leftSupp = () -> { IPair<NewLeft, NewRight> newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(oldSupplier.get()); } @@ -101,7 +101,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL final Supplier<NewRight> rightSupp = () -> { IPair<NewLeft, NewRight> newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(oldSupplier.get()); } @@ -118,7 +118,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL final BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { - CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft); + CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft); CombinedRight cRight = rightCombiner.apply(rightVal, otherRight); return new LazyPair<>(cLeft, cRight); @@ -129,7 +129,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL @Override public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) { final Supplier<NewLeftType> leftSupp = () -> { - if (pairBound) return mapper.apply(boundPair.getLeft()); + if(pairBound) return mapper.apply(boundPair.getLeft()); final NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft(); @@ -137,7 +137,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL }; final Supplier<NewRight> rightSupp = () -> { - if (pairBound) return boundPair.getRight(); + if(pairBound) return boundPair.getRight(); return binder.apply(oldSupplier.get()).getRight(); }; @@ -148,13 +148,13 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL @Override public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final Function<NewRight, NewRightType> mapper) { final Supplier<NewLeft> leftSupp = () -> { - if (pairBound) return boundPair.getLeft(); + if(pairBound) return boundPair.getLeft(); return binder.apply(oldSupplier.get()).getLeft(); }; final Supplier<NewRightType> rightSupp = () -> { - if (pairBound) return mapper.apply(boundPair.getRight()); + if(pairBound) return mapper.apply(boundPair.getRight()); final NewRight rightVal = binder.apply(oldSupplier.get()).getRight(); @@ -166,7 +166,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL @Override public <MergedType> MergedType merge(final BiFunction<NewLeft, NewRight, MergedType> merger) { - if (!pairBound) { + if(!pairBound) { boundPair = binder.apply(oldSupplier.get()); pairBound = true; diff --git a/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java b/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java index a5c8130..57f9302 100644 --- a/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java +++ b/base/src/main/java/bjc/utils/data/internals/WrappedLazy.java @@ -19,13 +19,13 @@ public class WrappedLazy<ContainedType> implements IHolder<ContainedType> { * Create a new wrapped lazy value. * * @param wrappedHolder - * The holder to make lazy. + * The holder to make lazy. */ public WrappedLazy(final IHolder<ContainedType> wrappedHolder) { held = new Lazy<>(wrappedHolder); } - /* + /* * This has an extra parameter, because otherwise it erases to the same * as the public one. * diff --git a/base/src/main/java/bjc/utils/data/internals/WrappedOption.java b/base/src/main/java/bjc/utils/data/internals/WrappedOption.java index 872295f..6260ce4 100644 --- a/base/src/main/java/bjc/utils/data/internals/WrappedOption.java +++ b/base/src/main/java/bjc/utils/data/internals/WrappedOption.java @@ -19,7 +19,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { * Create a new wrapped option. * * @param seedValue - * The value to wrap. + * The value to wrap. */ public WrappedOption(final IHolder<ContainedType> seedValue) { held = new Option<>(seedValue); @@ -38,7 +38,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { 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); }); @@ -58,7 +58,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { 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); }); @@ -71,7 +71,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { 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); }); @@ -84,7 +84,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { 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); }); |
