From dca8e9f586fd595a7995f07788318fb92b8cce79 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 28 Jul 2016 16:44:36 -0400 Subject: Format/Cleanup pass --- .../src/main/java/bjc/utils/data/BoundLazy.java | 49 +++++----- .../main/java/bjc/utils/data/BoundLazyPair.java | 60 ++++++------ .../main/java/bjc/utils/data/BoundListHolder.java | 19 ++-- .../src/main/java/bjc/utils/data/Either.java | 89 +++++++++-------- .../java/bjc/utils/data/HalfBoundLazyPair.java | 51 +++++----- .../src/main/java/bjc/utils/data/IHolder.java | 25 +++-- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 108 ++++++++++----------- .../src/main/java/bjc/utils/data/Identity.java | 16 +-- BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java | 16 +-- .../src/main/java/bjc/utils/data/LazyPair.java | 104 ++++++++++---------- .../src/main/java/bjc/utils/data/ListHolder.java | 27 +++--- .../src/main/java/bjc/utils/data/Option.java | 16 +-- BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 51 +++++----- .../main/java/bjc/utils/data/SingleSupplier.java | 4 +- .../src/main/java/bjc/utils/data/WrappedLazy.java | 24 ++--- .../main/java/bjc/utils/data/WrappedOption.java | 24 ++--- 16 files changed, 334 insertions(+), 349 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data') 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 1256e31..b6cd715 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java @@ -15,28 +15,27 @@ class BoundLazy /* * The old value */ - private Supplier> oldSupplier; + private Supplier> oldSupplier; /* * The function to use to transform the old value into a new value */ - private Function> binder; + private Function> binder; /* * The bound value being held */ - private IHolder boundHolder; + private IHolder boundHolder; /* * Whether the bound value has been actualized or not */ - private boolean holderBound; + private boolean holderBound; /* * Transformations currently pending on the bound value */ - private IList> actions = - new FunctionalList<>(); + private IList> actions = new FunctionalList<>(); /* * Create a new bound lazy value @@ -48,13 +47,12 @@ class BoundLazy } @Override - public IHolder - bind(Function> bindr) { + public IHolder bind( + Function> bindr) { /* * Prepare a list of pending actions */ - IList> pendingActions = - new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); /* @@ -82,11 +80,18 @@ class BoundLazy } @Override - public IHolder - map(Function mapper) { + public Function> lift( + Function func) { + return (val) -> { + return new Lazy<>(func.apply(val)); + }; + } + + @Override + public IHolder map( + Function mapper) { // Prepare a list of pending actions - IList> pendingActions = - new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); // Prepare the new supplier @@ -117,28 +122,20 @@ class BoundLazy } @Override - public IHolder - transform(UnaryOperator transformer) { + public IHolder transform( + UnaryOperator transformer) { actions.add(transformer); return this; } @Override - public UnwrappedType - unwrap(Function unwrapper) { + public UnwrappedType unwrap( + Function unwrapper) { if (!holderBound) { boundHolder = oldSupplier.get().unwrap(binder::apply); } return boundHolder.unwrap(unwrapper); } - - @Override - public Function> - lift(Function func) { - return (val) -> { - return new Lazy<>(func.apply(val)); - }; - } } \ No newline at end of file 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 2b20349..c527d94 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java @@ -90,25 +90,17 @@ class BoundLazyPair } @Override - public MergedType merge( - BiFunction merger) { - if (!pairBound) { - boundPair = binder.apply(leftSupplier.get(), - rightSupplier.get()); - - pairBound = true; - } - - return boundPair.merge(merger); - } - - @Override - public String toString() { - if (pairBound) { - return boundPair.toString(); - } - - return "(un-materialized)"; + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { + return otherPair.bind((otherLeft, otherRight) -> { + return bind((leftVal, rightVal) -> { + return new LazyPair<>( + leftCombiner.apply(leftVal, otherLeft), + rightCombiner.apply(rightVal, otherRight)); + }); + }); } @Override @@ -168,16 +160,24 @@ class BoundLazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { - return otherPair.bind((otherLeft, otherRight) -> { - return bind((leftVal, rightVal) -> { - return new LazyPair<>( - leftCombiner.apply(leftVal, otherLeft), - rightCombiner.apply(rightVal, otherRight)); - }); - }); + public MergedType merge( + BiFunction merger) { + if (!pairBound) { + boundPair = binder.apply(leftSupplier.get(), + rightSupplier.get()); + + pairBound = true; + } + + return boundPair.merge(merger); + } + + @Override + public String toString() { + if (pairBound) { + return boundPair.toString(); + } + + return "(un-materialized)"; } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java index 85ec8f6..fe47dcc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java @@ -8,8 +8,7 @@ import bjc.utils.funcdata.IList; class BoundListHolder implements IHolder { private IList> heldHolders; - public BoundListHolder( - IList> toHold) { + public BoundListHolder(IList> toHold) { heldHolders = toHold; } @@ -24,6 +23,14 @@ class BoundListHolder implements IHolder { return new BoundListHolder<>(boundHolders); } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new ListHolder<>(func.apply(val)); + }; + } + @Override public IHolder map( Function mapper) { @@ -50,12 +57,4 @@ class BoundListHolder implements IHolder { Function unwrapper) { return heldHolders.randItem().unwrap(unwrapper); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new ListHolder<>(func.apply(val)); - }; - } } 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 8787888..9418882 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java @@ -15,21 +15,6 @@ import java.util.function.Function; */ public class Either implements IPair { - private LeftType leftVal; - private RightType rightVal; - - private boolean isLeft; - - private Either(LeftType left, RightType right) { - if (left == null) { - rightVal = right; - } else { - leftVal = left; - - isLeft = true; - } - } - /** * Create a new either with the left value occupied * @@ -41,11 +26,10 @@ public class Either * The value to put on the left * @return An either with the left side occupied */ - public static Either - fromLeft(LeftType left) { + public static Either fromLeft( + LeftType left) { return new Either<>(left, null); } - /** * Create a new either with the right value occupied * @@ -57,11 +41,27 @@ public class Either * The value to put on the right * @return An either with the right side occupied */ - public static Either - fromRight(RightType right) { + public static Either fromRight( + RightType right) { return new Either<>(null, right); } + private LeftType leftVal; + + private RightType rightVal; + + private boolean isLeft; + + private Either(LeftType left, RightType right) { + if (left == null) { + rightVal = right; + } else { + leftVal = left; + + isLeft = true; + } + } + @Override public IPair bind( BiFunction> binder) { @@ -89,8 +89,26 @@ public class Either } @Override - public IPair - mapLeft(Function mapper) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { + if (isLeft) { + return otherPair.bind((otherLeft, otherRight) -> { + return new Either<>(leftCombiner.apply(leftVal, otherLeft), + null); + }); + } + + return otherPair.bind((otherLeft, otherRight) -> { + return new Either<>(null, + rightCombiner.apply(rightVal, otherRight)); + }); + } + + @Override + public IPair mapLeft( + Function mapper) { if (isLeft) { return new Either<>(mapper.apply(leftVal), null); } @@ -99,8 +117,8 @@ public class Either } @Override - public IPair - mapRight(Function mapper) { + public IPair mapRight( + Function mapper) { if (isLeft) { return new Either<>(leftVal, null); } @@ -109,27 +127,8 @@ public class Either } @Override - public MergedType - merge(BiFunction merger) { + public MergedType merge( + BiFunction merger) { return merger.apply(leftVal, rightVal); } - - @Override - public - IPair - combine(IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { - if (isLeft) { - return otherPair.bind((otherLeft, otherRight) -> { - return new Either<>(leftCombiner.apply(leftVal, otherLeft), - null); - }); - } - - return otherPair.bind((otherLeft, otherRight) -> { - return new Either<>(null, - rightCombiner.apply(rightVal, otherRight)); - }); - } } 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 198dd96..d91ede2 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java @@ -80,20 +80,22 @@ class HalfBoundLazyPair } @Override - public MergedType - merge(BiFunction merger) { - if (!pairBound) { - boundPair = binder.apply(oldSupplier.get()); - - pairBound = true; - } - - return boundPair.merge(merger); + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { + return otherPair.bind((otherLeft, otherRight) -> { + return bind((leftVal, rightVal) -> { + return new LazyPair<>( + leftCombiner.apply(leftVal, otherLeft), + rightCombiner.apply(rightVal, otherRight)); + }); + }); } @Override - public IPair - mapLeft(Function mapper) { + public IPair mapLeft( + Function mapper) { Supplier leftSupp = () -> { if (pairBound) { return mapper.apply(boundPair.getLeft()); @@ -116,8 +118,8 @@ class HalfBoundLazyPair } @Override - public IPair - mapRight(Function mapper) { + public IPair mapRight( + Function mapper) { Supplier leftSupp = () -> { if (pairBound) { return boundPair.getLeft(); @@ -138,19 +140,16 @@ class HalfBoundLazyPair return new LazyPair<>(leftSupp, rightSupp); } - + @Override - public - IPair - combine(IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { - return otherPair.bind((otherLeft, otherRight) -> { - return bind((leftVal, rightVal) -> { - return new LazyPair<>( - leftCombiner.apply(leftVal, otherLeft), - rightCombiner.apply(rightVal, otherRight)); - }); - }); + public MergedType merge( + BiFunction merger) { + if (!pairBound) { + boundPair = binder.apply(oldSupplier.get()); + + pairBound = true; + } + + return boundPair.merge(merger); } } \ No newline at end of file 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 58ae5db..b2e4369 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java @@ -25,8 +25,8 @@ public interface IHolder extends Functor { * The function to bind to the value * @return A holder from binding the value */ - public IHolder - bind(Function> binder); + public IHolder bind( + Function> binder); /** * Apply an action to the value @@ -43,9 +43,8 @@ public interface IHolder extends Functor { } @Override - default - Function, Functor> - fmap(Function func) { + default Function, Functor> fmap( + Function func) { return (argumentFunctor) -> { if (!(argumentFunctor instanceof IHolder)) { throw new IllegalArgumentException( @@ -72,8 +71,8 @@ public interface IHolder extends Functor { * The function to lift over the holder * @return The function lifted over the holder */ - public Function> - lift(Function func); + public Function> lift( + Function func); /** * Make this holder lazy @@ -114,8 +113,8 @@ public interface IHolder extends Functor { * The function to do mapping with * @return A holder with the mapped value */ - public IHolder - map(Function mapper); + public IHolder map( + Function mapper); /** * Replace the held value with a new one @@ -137,8 +136,8 @@ public interface IHolder extends Functor { * The function to transform the value with * @return The holder itself, for easy chaining */ - public IHolder - transform(UnaryOperator transformer); + public IHolder transform( + UnaryOperator transformer); /** * Unwrap the value contained in this holder so that it is no longer @@ -150,6 +149,6 @@ public interface IHolder extends Functor { * The function to use to unwrap the value * @return The unwrapped held value */ - public UnwrappedType - unwrap(Function unwrapper); + public UnwrappedType unwrap( + Function unwrapper); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java index f94d656..a2a635f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -56,6 +56,46 @@ public interface IPair public IPair bindRight( Function> rightBinder); + /** + * Pairwise combine two pairs together + * + * @param + * The left type of the other pair + * @param + * The right type of the other pair + * @param otherPair + * The pair to combine with + * @return The pairs, pairwise combined together + */ + public default IPair, IPair> combine( + IPair otherPair) { + return combine(otherPair, + (left, otherLeft) -> new Pair<>(left, otherLeft), + (right, otherRight) -> new Pair<>(right, otherRight)); + } + + /** + * Combine the contents of two pairs together + * + * @param + * The type of the left value of the other pair + * @param + * The type of the right value of the other pair + * @param + * The type of the left value of the combined pair + * @param + * The type of the right value of the combined pair + * @param otherPair + * The other pair to combine with + * @param leftCombiner + * @param rightCombiner + * @return A pair with its values combined + */ + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner); + /** * Immediately perfom the specified action with the contents of this * pair @@ -72,25 +112,22 @@ public interface IPair } @Override - default - Function, Bifunctor> - fmapLeft(Function func) { + default Function, Bifunctor> fmapLeft( + Function func) { return (argumentPair) -> { if (!(argumentPair instanceof IPair)) { throw new IllegalArgumentException( "This function can only be applied to instances of IPair"); } - IPair argPair = - (IPair) argumentPair; + IPair argPair = (IPair) argumentPair; return argPair.mapLeft(func); }; } @Override - default - Function, Bifunctor> + default Function, Bifunctor> fmapRight(Function func) { return (argumentPair) -> { @@ -99,8 +136,7 @@ public interface IPair "This function can only be applied to instances of IPair"); } - IPair argPair = - (IPair) argumentPair; + IPair argPair = (IPair) argumentPair; return argPair.mapRight(func); }; @@ -137,8 +173,8 @@ public interface IPair * pair * @return The pair, with its left part transformed */ - public IPair - mapLeft(Function mapper); + public IPair mapLeft( + Function mapper); /** * Transform the value on the right side of the pair. Doesn't modify @@ -151,8 +187,8 @@ public interface IPair * pair * @return The pair, with its right part transformed */ - public IPair - mapRight(Function mapper); + public IPair mapRight( + Function mapper); /** * Merge the two values in this pair into a single value @@ -163,48 +199,6 @@ public interface IPair * The function to use for merging * @return The pair, merged into a single value */ - public MergedType - merge(BiFunction merger); - - /** - * Combine the contents of two pairs together - * - * @param - * The type of the left value of the other pair - * @param - * The type of the right value of the other pair - * @param - * The type of the left value of the combined pair - * @param - * The type of the right value of the combined pair - * @param otherPair - * The other pair to combine with - * @param leftCombiner - * @param rightCombiner - * @return A pair with its values combined - */ - public - IPair - combine(IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner); - - /** - * Pairwise combine two pairs together - * - * @param - * The left type of the other pair - * @param - * The right type of the other pair - * @param otherPair - * The pair to combine with - * @return The pairs, pairwise combined together - */ - public default - IPair, IPair> - combine(IPair otherPair) { - return combine(otherPair, - (left, otherLeft) -> new Pair<>(left, otherLeft), - (right, otherRight) -> new Pair<>(right, otherRight)); - } + public MergedType merge( + BiFunction merger); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java index f42ceb7..8fcaf98 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java @@ -88,6 +88,14 @@ public class Identity implements IHolder { return result; } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new Identity<>(func.apply(val)); + }; + } + @Override public IHolder map( Function mapper) { @@ -112,12 +120,4 @@ public class Identity implements IHolder { Function unwrapper) { return unwrapper.apply(heldValue); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new Identity<>(func.apply(val)); - }; - } } \ No newline at end of file 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 22f948c..f05204b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java @@ -75,6 +75,14 @@ public class Lazy implements IHolder { }, binder); } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new Lazy<>(func.apply(val)); + }; + } + @Override public IHolder map( Function mapper) { @@ -133,12 +141,4 @@ public class Lazy implements IHolder { return unwrapper.apply(heldValue); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new Lazy<>(func.apply(val)); - }; - } } 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 490c4fc..df4c3ac 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java @@ -95,6 +95,20 @@ public class LazyPair return new HalfBoundLazyPair<>(rightSupp, rightBinder); } + @Override + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { + return otherPair.bind((otherLeft, otherRight) -> { + return bind((leftVal, rightVal) -> { + return new LazyPair<>( + leftCombiner.apply(leftVal, otherLeft), + rightCombiner.apply(rightVal, otherRight)); + }); + }); + } + @Override public LeftType getLeft() { if (!leftMaterialized) { @@ -117,47 +131,6 @@ public class LazyPair return rightValue; } - @Override - public MergedType merge( - BiFunction merger) { - if (!leftMaterialized) { - leftValue = leftSupplier.get(); - - leftMaterialized = true; - } - - if (!rightMaterialized) { - rightValue = rightSupplier.get(); - - rightMaterialized = true; - } - - return merger.apply(leftValue, rightValue); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("pair[l="); - - if (leftMaterialized) { - sb.append(leftValue.toString()); - } else { - sb.append("(un-materialized)"); - } - - sb.append(", r="); - - if (rightMaterialized) { - sb.append(rightValue.toString()); - } else { - sb.append("(un-materialized)"); - } - - sb.append("]"); - - return sb.toString(); - } - @Override public IPair mapLeft( Function mapper) { @@ -203,16 +176,43 @@ public class LazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { - return otherPair.bind((otherLeft, otherRight) -> { - return bind((leftVal, rightVal) -> { - return new LazyPair<>( - leftCombiner.apply(leftVal, otherLeft), - rightCombiner.apply(rightVal, otherRight)); - }); - }); + public MergedType merge( + BiFunction merger) { + if (!leftMaterialized) { + leftValue = leftSupplier.get(); + + leftMaterialized = true; + } + + if (!rightMaterialized) { + rightValue = rightSupplier.get(); + + rightMaterialized = true; + } + + return merger.apply(leftValue, rightValue); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("pair[l="); + + if (leftMaterialized) { + sb.append(leftValue.toString()); + } else { + sb.append("(un-materialized)"); + } + + sb.append(", r="); + + if (rightMaterialized) { + sb.append(rightValue.toString()); + } else { + sb.append("(un-materialized)"); + } + + sb.append("]"); + + return sb.toString(); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java index 03765ed..fc6180b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java @@ -17,10 +17,6 @@ import bjc.utils.funcdata.IList; public class ListHolder implements IHolder { private IList heldValues; - private ListHolder(IList toHold) { - heldValues = toHold; - } - /** * Create a new list holder * @@ -38,15 +34,26 @@ public class ListHolder implements IHolder { } } + private ListHolder(IList toHold) { + heldValues = toHold; + } + @Override public IHolder bind( Function> binder) { - IList> boundValues = heldValues - .map(binder); + IList> boundValues = heldValues.map(binder); return new BoundListHolder<>(boundValues); } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new ListHolder<>(new FunctionalList<>(func.apply(val))); + }; + } + @Override public IHolder map( Function mapper) { @@ -68,12 +75,4 @@ public class ListHolder implements IHolder { Function unwrapper) { return unwrapper.apply(heldValues.randItem()); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new ListHolder<>(new FunctionalList<>(func.apply(val))); - }; - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java index 9f6d448..16d90e3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java @@ -34,6 +34,14 @@ public class Option implements IHolder { return binder.apply(held); } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new Option<>(func.apply(val)); + }; + } + @Override public IHolder map( Function mapper) { @@ -63,12 +71,4 @@ public class Option implements IHolder { return unwrapper.apply(held); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new Option<>(func.apply(val)); - }; - } } 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 1fc0d19..1000fc0 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -70,24 +70,19 @@ public class Pair } @Override - public MergedType - merge(BiFunction merger) { - if (merger == null) { - throw new NullPointerException("Merger must not be null"); - } - - return merger.apply(leftValue, rightValue); - } - - @Override - public String toString() { - return "pair[l=" + leftValue.toString() + ", r=" - + rightValue.toString() + "]"; + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { + return otherPair.bind((otherLeft, otherRight) -> { + return new Pair<>(leftCombiner.apply(leftValue, otherLeft), + rightCombiner.apply(rightValue, otherRight)); + }); } @Override - public IPair - mapLeft(Function mapper) { + public IPair mapLeft( + Function mapper) { if (mapper == null) { throw new NullPointerException("Mapper must not be null"); } @@ -96,8 +91,8 @@ public class Pair } @Override - public IPair - mapRight(Function mapper) { + public IPair mapRight( + Function mapper) { if (mapper == null) { throw new NullPointerException("Mapper must not be null"); } @@ -106,14 +101,18 @@ public class Pair } @Override - public - IPair - combine(IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { - return otherPair.bind((otherLeft, otherRight) -> { - return new Pair<>(leftCombiner.apply(leftValue, otherLeft), - rightCombiner.apply(rightValue, otherRight)); - }); + public MergedType merge( + BiFunction merger) { + if (merger == null) { + throw new NullPointerException("Merger must not be null"); + } + + return merger.apply(leftValue, rightValue); + } + + @Override + public String toString() { + return "pair[l=" + leftValue.toString() + ", r=" + + rightValue.toString() + "]"; } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java index 989f1a5..f40ab29 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java @@ -3,6 +3,8 @@ package bjc.utils.data; import java.util.function.Supplier; public class SingleSupplier implements Supplier { + private static long nextID = 0; + private Supplier source; private boolean gotten; @@ -13,8 +15,6 @@ public class SingleSupplier implements Supplier { // instantiation was, in case of duplicate initiations private Exception instSite; - private static long nextID = 0; - public SingleSupplier(Supplier supp) { source = supp; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/WrappedLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/WrappedLazy.java index 737482c..8ca29bc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/WrappedLazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/WrappedLazy.java @@ -6,6 +6,10 @@ import java.util.function.UnaryOperator; class WrappedLazy implements IHolder { private IHolder> held; + public WrappedLazy(IHolder wrappedHolder) { + held = new Lazy<>(wrappedHolder); + } + // This has an extra parameter, because otherwise it erases to the same // as the public one private WrappedLazy(IHolder> wrappedHolder, @@ -13,10 +17,6 @@ class WrappedLazy implements IHolder { held = wrappedHolder; } - public WrappedLazy(IHolder wrappedHolder) { - held = new Lazy<>(wrappedHolder); - } - @Override public IHolder bind( Function> binder) { @@ -28,6 +28,14 @@ class WrappedLazy implements IHolder { return new WrappedLazy<>(newHolder, false); } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new Lazy<>(func.apply(val)); + }; + } + @Override public IHolder map( Function mapper) { @@ -58,12 +66,4 @@ class WrappedLazy implements IHolder { return containedHolder.unwrap(unwrapper); }); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new Lazy<>(func.apply(val)); - }; - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/WrappedOption.java b/BJC-Utils2/src/main/java/bjc/utils/data/WrappedOption.java index c36cafa..5be55cc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/WrappedOption.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/WrappedOption.java @@ -6,15 +6,15 @@ import java.util.function.UnaryOperator; class WrappedOption implements IHolder { private IHolder> held; + public WrappedOption(IHolder seedValue) { + held = new Option<>(seedValue); + } + private WrappedOption(IHolder> toHold, @SuppressWarnings("unused") boolean dummy) { held = toHold; } - public WrappedOption(IHolder seedValue) { - held = new Option<>(seedValue); - } - @Override public IHolder bind( Function> binder) { @@ -32,6 +32,14 @@ class WrappedOption implements IHolder { return new WrappedOption<>(newHolder, false); } + @Override + public Function> lift( + Function func) { + return (val) -> { + return new Option<>(func.apply(val)); + }; + } + @Override public IHolder map( Function mapper) { @@ -78,12 +86,4 @@ class WrappedOption implements IHolder { }); }); } - - @Override - public Function> lift( - Function func) { - return (val) -> { - return new Option<>(func.apply(val)); - }; - } } -- cgit v1.2.3