summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java75
1 files changed, 38 insertions, 37 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
index 35df1c3..a603a7f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
@@ -1,39 +1,40 @@
package bjc.utils.data.internals;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.data.LazyPair;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
/*
* A lazy pair, with only one side bound
*/
@SuppressWarnings("javadoc")
public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewLeft, NewRight> {
- private Supplier<OldType> oldSupplier;
+ private final Supplier<OldType> oldSupplier;
- private Function<OldType, IPair<NewLeft, NewRight>> binder;
+ private final Function<OldType, IPair<NewLeft, NewRight>> binder;
private IPair<NewLeft, NewRight> boundPair;
private boolean pairBound;
- public HalfBoundLazyPair(Supplier<OldType> oldSupp, Function<OldType, IPair<NewLeft, NewRight>> bindr) {
+ public HalfBoundLazyPair(final Supplier<OldType> oldSupp,
+ final Function<OldType, IPair<NewLeft, NewRight>> bindr) {
oldSupplier = oldSupp;
binder = bindr;
}
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
- IHolder<Boolean> newPairMade = new Identity<>(pairBound);
+ final BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
+ final IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(boundPair);
+ final IHolder<Boolean> newPairMade = new Identity<>(pairBound);
- Supplier<NewLeft> leftSupp = () -> {
- if(!newPairMade.getValue()) {
+ final Supplier<NewLeft> leftSupp = () -> {
+ if (!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -41,8 +42,8 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
return newPair.unwrap((pair) -> pair.getLeft());
};
- Supplier<NewRight> rightSupp = () -> {
- if(!newPairMade.getValue()) {
+ final Supplier<NewRight> rightSupp = () -> {
+ if (!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -55,11 +56,11 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
- Supplier<NewLeft> leftSupp = () -> {
+ 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());
}
@@ -71,11 +72,11 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
- Supplier<NewRight> rightSupp = () -> {
+ 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());
}
@@ -87,9 +88,9 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
- BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
+ 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) -> {
return new LazyPair<>(leftCombiner.apply(leftVal, otherLeft),
@@ -99,17 +100,17 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(Function<NewLeft, NewLeftType> mapper) {
- Supplier<NewLeftType> leftSupp = () -> {
- if(pairBound) return mapper.apply(boundPair.getLeft());
+ public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(final Function<NewLeft, NewLeftType> mapper) {
+ final Supplier<NewLeftType> leftSupp = () -> {
+ if (pairBound) return mapper.apply(boundPair.getLeft());
- NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
+ final NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
return mapper.apply(leftVal);
};
- Supplier<NewRight> rightSupp = () -> {
- if(pairBound) return boundPair.getRight();
+ final Supplier<NewRight> rightSupp = () -> {
+ if (pairBound) return boundPair.getRight();
return binder.apply(oldSupplier.get()).getRight();
};
@@ -118,17 +119,17 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(Function<NewRight, NewRightType> mapper) {
- Supplier<NewLeft> leftSupp = () -> {
- if(pairBound) return boundPair.getLeft();
+ public <NewRightType> IPair<NewLeft, NewRightType> mapRight(final Function<NewRight, NewRightType> mapper) {
+ final Supplier<NewLeft> leftSupp = () -> {
+ if (pairBound) return boundPair.getLeft();
return binder.apply(oldSupplier.get()).getLeft();
};
- Supplier<NewRightType> rightSupp = () -> {
- if(pairBound) return mapper.apply(boundPair.getRight());
+ final Supplier<NewRightType> rightSupp = () -> {
+ if (pairBound) return mapper.apply(boundPair.getRight());
- NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
+ final NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
return mapper.apply(rightVal);
};
@@ -137,8 +138,8 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
}
@Override
- public <MergedType> MergedType merge(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;