summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/data/internals/HalfBoundLazyPair.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-04-13 18:43:13 -0400
committerBen Culkin <scorpress@gmail.com>2020-04-13 18:43:13 -0400
commitf51f6da7319787348c38b875652b5c0e9f88c8aa (patch)
tree943888fc724da2d2dedd89abec99dcbfcc089fd0 /src/main/java/bjc/data/internals/HalfBoundLazyPair.java
parent9052ed6da37af23ea82588d248f409e60a33c6cb (diff)
Cleanup pass
Pass to do some cleanups
Diffstat (limited to 'src/main/java/bjc/data/internals/HalfBoundLazyPair.java')
-rw-r--r--src/main/java/bjc/data/internals/HalfBoundLazyPair.java73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/main/java/bjc/data/internals/HalfBoundLazyPair.java b/src/main/java/bjc/data/internals/HalfBoundLazyPair.java
index 4f28012..6bcb6ae 100644
--- a/src/main/java/bjc/data/internals/HalfBoundLazyPair.java
+++ b/src/main/java/bjc/data/internals/HalfBoundLazyPair.java
@@ -23,7 +23,8 @@ import bjc.data.LazyPair;
* @author Ben Culkin
*/
@SuppressWarnings("javadoc")
-public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewLeft, NewRight> {
+public class HalfBoundLazyPair<OldType, NewLeft, NewRight>
+ implements IPair<NewLeft, NewRight> {
/* The supplier of the old value. */
private final Supplier<OldType> oldSupplier;
@@ -39,10 +40,10 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
* 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,35 +58,35 @@ 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);
}
- return newPair.unwrap((pair) -> pair.getLeft());
+ return newPair.unwrap(pair -> pair.getLeft());
};
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);
}
- return newPair.unwrap((pair) -> pair.getRight());
+ return newPair.unwrap(pair -> pair.getRight());
};
return new BoundLazyPair<>(leftSupp, rightSupp, bindr);
}
@Override
- public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
+ public <BoundLeft> IPair<BoundLeft, NewRight>
+ bindLeft(final Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
final Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if(!pairBound) {
+ if (!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -96,12 +97,12 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
+ public <BoundRight> IPair<NewLeft, BoundRight>
+ bindRight(final Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
final Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if(!pairBound) {
+ if (!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -112,24 +113,25 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- final IPair<OtherLeft, OtherRight> otherPair,
- final BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
- final BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
- return otherPair.bind((otherLeft, otherRight) -> {
- return bind((leftVal, rightVal) -> {
- CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft);
- CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
-
- return new LazyPair<>(cLeft, cRight);
- });
- });
+ public <OtherLeft, OtherRight, CombinedLeft, CombinedRight>
+ IPair<CombinedLeft, CombinedRight>
+ combine(final IPair<OtherLeft, OtherRight> otherPair,
+ final BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
+ final BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
+ return otherPair.bind((otherLeft, otherRight) -> bind((leftVal, rightVal) -> {
+ CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft);
+ CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
+
+ return new LazyPair<>(cLeft, cRight);
+ }));
}
@Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) {
+ 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 +139,8 @@ 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();
};
@@ -146,15 +149,18 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final Function<NewRight, NewRightType> mapper) {
+ 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();
@@ -165,8 +171,9 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <MergedType> MergedType merge(final BiFunction<NewLeft, NewRight, MergedType> merger) {
- if(!pairBound) {
+ public <MergedType> MergedType
+ merge(final BiFunction<NewLeft, NewRight, MergedType> merger) {
+ if (!pairBound) {
boundPair = binder.apply(oldSupplier.get());
pairBound = true;