diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
9 files changed, 103 insertions, 58 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java index b6cd715..d6f3b1d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java @@ -35,7 +35,8 @@ class BoundLazy<OldType, BoundContainedType> /* * Transformations currently pending on the bound value */ - private IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>(); + private IList<UnaryOperator< + BoundContainedType>> actions = new FunctionalList<>(); /* * Create a new bound lazy value @@ -52,7 +53,8 @@ class BoundLazy<OldType, BoundContainedType> /* * Prepare a list of pending actions */ - IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + BoundContainedType>> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); /* @@ -91,7 +93,8 @@ class BoundLazy<OldType, BoundContainedType> public <MappedType> IHolder<MappedType> map( Function<BoundContainedType, MappedType> mapper) { // Prepare a list of pending actions - IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + BoundContainedType>> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); // Prepare the new supplier diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java index c527d94..622bd2e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java @@ -6,18 +6,21 @@ import java.util.function.Supplier; class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPair<NewLeft, NewRight> { - private Supplier<OldLeft> leftSupplier; - private Supplier<OldRight> rightSupplier; + private Supplier< + OldLeft> leftSupplier; + private Supplier< + OldRight> rightSupplier; private BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> binder; - private IPair<NewLeft, NewRight> boundPair; + private IPair<NewLeft, + NewRight> boundPair; private boolean pairBound; public BoundLazyPair(Supplier<OldLeft> leftSupp, - Supplier<OldRight> rightSupp, - BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) { + Supplier<OldRight> rightSupp, BiFunction<OldLeft, OldRight, + IPair<NewLeft, NewRight>> bindr) { leftSupplier = leftSupp; rightSupplier = rightSupp; binder = bindr; @@ -25,9 +28,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) { - IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>( - boundPair); + BiFunction<NewLeft, NewRight, + IPair<BoundLeft, BoundRight>> bindr) { + IHolder<IPair<NewLeft, + NewRight>> newPair = new Identity<>(boundPair); IHolder<Boolean> newPairMade = new Identity<>(pairBound); Supplier<NewLeft> leftSupp = () -> { @@ -90,10 +94,13 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<NewLeft, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<NewRight, OtherRight, + CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java index 9418882..aa38959 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java @@ -26,10 +26,12 @@ public class Either<LeftType, RightType> * The value to put on the left * @return An either with the left side occupied */ - public static <LeftType, RightType> Either<LeftType, RightType> fromLeft( - LeftType left) { + public static <LeftType, + RightType> Either<LeftType, RightType> fromLeft( + LeftType left) { return new Either<>(left, null); } + /** * Create a new either with the right value occupied * @@ -41,8 +43,9 @@ public class Either<LeftType, RightType> * The value to put on the right * @return An either with the right side occupied */ - public static <LeftType, RightType> Either<LeftType, RightType> fromRight( - RightType right) { + public static <LeftType, + RightType> Either<LeftType, RightType> fromRight( + RightType right) { return new Either<>(null, right); } @@ -64,7 +67,8 @@ public class Either<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder) { return binder.apply(leftVal, rightVal); } @@ -89,10 +93,13 @@ public class Either<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> rightCombiner) { if (isLeft) { return otherPair.bind((otherLeft, otherRight) -> { return new Either<>(leftCombiner.apply(leftVal, otherLeft), diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java index d91ede2..72c0bdf 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java @@ -21,9 +21,10 @@ class HalfBoundLazyPair<OldType, NewLeft, NewRight> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) { - IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>( - boundPair); + BiFunction<NewLeft, NewRight, + IPair<BoundLeft, BoundRight>> bindr) { + IHolder<IPair<NewLeft, + NewRight>> newPair = new Identity<>(boundPair); IHolder<Boolean> newPairMade = new Identity<>(pairBound); Supplier<NewLeft> leftSupp = () -> { @@ -80,10 +81,13 @@ class HalfBoundLazyPair<OldType, NewLeft, NewRight> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<NewLeft, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<NewRight, OtherRight, + CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java index b2e4369..a8c9f77 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java @@ -43,8 +43,10 @@ public interface IHolder<ContainedType> extends Functor<ContainedType> { } @Override - default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap( - Function<ArgType, ReturnType> func) { + default <ArgType, + ReturnType> Function<Functor<ArgType>, + Functor<ReturnType>> fmap( + Function<ArgType, ReturnType> func) { return (argumentFunctor) -> { if (!(argumentFunctor instanceof IHolder<?>)) { throw new IllegalArgumentException( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java index a2a635f..c82cc8e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -30,7 +30,8 @@ public interface IPair<LeftType, RightType> * @return The bound pair */ public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder); + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder); /** * Bind a function to the left value in this pair @@ -67,8 +68,10 @@ public interface IPair<LeftType, RightType> * The pair to combine with * @return The pairs, pairwise combined together */ - public default <OtherLeft, OtherRight> IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> combine( - IPair<OtherLeft, OtherRight> otherPair) { + public default <OtherLeft, + OtherRight> IPair<IPair<LeftType, OtherLeft>, + IPair<RightType, OtherRight>> combine( + IPair<OtherLeft, OtherRight> otherPair) { return combine(otherPair, (left, otherLeft) -> new Pair<>(left, otherLeft), (right, otherRight) -> new Pair<>(right, otherRight)); @@ -91,10 +94,13 @@ public interface IPair<LeftType, RightType> * @param rightCombiner * @return A pair with its values combined */ - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner); + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> rightCombiner); /** * Immediately perfom the specified action with the contents of this @@ -112,22 +118,26 @@ public interface IPair<LeftType, RightType> } @Override - default <OldLeft, OldRight, NewLeft> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> fmapLeft( - Function<OldLeft, NewLeft> func) { + default <OldLeft, OldRight, + NewLeft> Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<NewLeft, OldRight>> fmapLeft( + Function<OldLeft, NewLeft> func) { return (argumentPair) -> { if (!(argumentPair instanceof IPair<?, ?>)) { throw new IllegalArgumentException( "This function can only be applied to instances of IPair"); } - IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair; + IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, + OldRight>) argumentPair; return argPair.mapLeft(func); }; } @Override - default <OldLeft, OldRight, NewRight> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<OldLeft, NewRight>> + default <OldLeft, OldRight, NewRight> Function< + Bifunctor<OldLeft, OldRight>, Bifunctor<OldLeft, NewRight>> fmapRight(Function<OldRight, NewRight> func) { return (argumentPair) -> { @@ -136,7 +146,8 @@ public interface IPair<LeftType, RightType> "This function can only be applied to instances of IPair"); } - IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair; + IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, + OldRight>) argumentPair; return argPair.mapRight(func); }; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java index f05204b..ffc4919 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java @@ -18,7 +18,8 @@ import bjc.utils.funcdata.IList; public class Lazy<ContainedType> implements IHolder<ContainedType> { private Supplier<ContainedType> valueSupplier; - private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>(); + private IList<UnaryOperator< + ContainedType>> actions = new FunctionalList<>(); private boolean valueMaterialized; @@ -58,7 +59,8 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> { @Override public <BoundType> IHolder<BoundType> bind( Function<ContainedType, IHolder<BoundType>> binder) { - IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + ContainedType>> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); @@ -86,7 +88,8 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> { @Override public <MappedType> IHolder<MappedType> map( Function<ContainedType, MappedType> mapper) { - IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + ContainedType>> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java index df4c3ac..53428d9 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java @@ -63,7 +63,8 @@ public class LazyPair<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder) { return new BoundLazyPair<>(leftSupplier, rightSupplier, binder); } @@ -96,10 +97,13 @@ public class LazyPair<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java index 1000fc0..3480b2a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -41,7 +41,8 @@ public class Pair<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder) { if (binder == null) { throw new NullPointerException("Binder must not be null."); } @@ -70,10 +71,13 @@ public class Pair<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return new Pair<>(leftCombiner.apply(leftValue, otherLeft), rightCombiner.apply(rightValue, otherRight)); |
