From f51f6da7319787348c38b875652b5c0e9f88c8aa Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:43:13 -0400 Subject: Cleanup pass Pass to do some cleanups --- .../java/bjc/data/internals/HalfBoundLazyPair.java | 73 ++++++++++++---------- 1 file changed, 40 insertions(+), 33 deletions(-) (limited to 'src/main/java/bjc/data/internals/HalfBoundLazyPair.java') 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 implements IPair { +public class HalfBoundLazyPair + implements IPair { /* The supplier of the old value. */ private final Supplier oldSupplier; @@ -39,10 +40,10 @@ public class HalfBoundLazyPair implements IPair oldSupp, final Function> bindr) { @@ -57,35 +58,35 @@ public class HalfBoundLazyPair implements IPair newPairMade = new Identity<>(pairBound); final Supplier 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 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 IPair bindLeft( - final Function> leftBinder) { + public IPair + bindLeft(final Function> leftBinder) { final Supplier leftSupp = () -> { IPair newPair = boundPair; - if(!pairBound) { + if (!pairBound) { newPair = binder.apply(oldSupplier.get()); } @@ -96,12 +97,12 @@ public class HalfBoundLazyPair implements IPair IPair bindRight( - final Function> rightBinder) { + public IPair + bindRight(final Function> rightBinder) { final Supplier rightSupp = () -> { IPair newPair = boundPair; - if(!pairBound) { + if (!pairBound) { newPair = binder.apply(oldSupplier.get()); } @@ -112,24 +113,25 @@ public class HalfBoundLazyPair implements IPair IPair combine( - final IPair otherPair, - final BiFunction leftCombiner, - final BiFunction 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 + IPair + combine(final IPair otherPair, + final BiFunction leftCombiner, + final BiFunction 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 IPair mapLeft(final Function mapper) { + public IPair + mapLeft(final Function mapper) { final Supplier 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 implements IPair rightSupp = () -> { - if(pairBound) return boundPair.getRight(); + if (pairBound) + return boundPair.getRight(); return binder.apply(oldSupplier.get()).getRight(); }; @@ -146,15 +149,18 @@ public class HalfBoundLazyPair implements IPair IPair mapRight(final Function mapper) { + public IPair + mapRight(final Function mapper) { final Supplier leftSupp = () -> { - if(pairBound) return boundPair.getLeft(); + if (pairBound) + return boundPair.getLeft(); return binder.apply(oldSupplier.get()).getLeft(); }; final Supplier 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 implements IPair MergedType merge(final BiFunction merger) { - if(!pairBound) { + public MergedType + merge(final BiFunction merger) { + if (!pairBound) { boundPair = binder.apply(oldSupplier.get()); pairBound = true; -- cgit v1.2.3