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/BoundLazyPair.java | 122 +++++++++++---------- 1 file changed, 66 insertions(+), 56 deletions(-) (limited to 'src/main/java/bjc/data/internals/BoundLazyPair.java') diff --git a/src/main/java/bjc/data/internals/BoundLazyPair.java b/src/main/java/bjc/data/internals/BoundLazyPair.java index 105b410..e081c04 100644 --- a/src/main/java/bjc/data/internals/BoundLazyPair.java +++ b/src/main/java/bjc/data/internals/BoundLazyPair.java @@ -15,7 +15,8 @@ import bjc.data.LazyPair; * @author Ben Culkin */ @SuppressWarnings("javadoc") -public class BoundLazyPair implements IPair { +public class BoundLazyPair + implements IPair { /* The supplier of the left value. */ private final Supplier leftSupplier; /* The supplier of the right value. */ @@ -34,16 +35,17 @@ public class BoundLazyPair implements IPai * Create a new bound lazy pair. * * @param leftSupp - * The supplier for the left value. + * The supplier for the left value. * * @param rightSupp - * The supplier for the right value. + * The supplier for the right value. * * @param bindr - * The function to use to bind the left and right into a new - * pair. + * The function to use to bind the left and right into a new + * pair. */ - public BoundLazyPair(final Supplier leftSupp, final Supplier rightSupp, + public BoundLazyPair(final Supplier leftSupp, + final Supplier rightSupp, final BiFunction> bindr) { leftSupplier = leftSupp; rightSupplier = rightSupp; @@ -53,54 +55,53 @@ public class BoundLazyPair implements IPai @Override public IPair bind( final BiFunction> bindr) { - if(bindr == null) throw new NullPointerException("Binder must not be null"); + if (bindr == null) + throw new NullPointerException("Binder must not be null"); final IHolder> newPair = new Identity<>(boundPair); final IHolder newPairMade = new Identity<>(pairBound); final Supplier leftSupp = () -> { - if(!newPairMade.getValue()) { + if (!newPairMade.getValue()) { /* - * If the pair hasn't been bound before, bind - * it. + * If the pair hasn't been bound before, bind it. */ newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.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()) { /* - * If the pair hasn't been bound before, bind - * it. + * If the pair hasn't been bound before, bind it. */ newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.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) { - if(leftBinder == null) throw new NullPointerException("Left binder must not be null"); + public IPair + bindLeft(final Function> leftBinder) { + if (leftBinder == null) + throw new NullPointerException("Left binder must not be null"); final Supplier leftSupp = () -> { IPair newPair = boundPair; - if(!pairBound) { + if (!pairBound) { /* - * If the pair hasn't been bound before, bind - * it. + * If the pair hasn't been bound before, bind it. */ newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -112,17 +113,17 @@ public class BoundLazyPair implements IPai } @Override - public IPair bindRight( - final Function> rightBinder) { - if(rightBinder == null) throw new NullPointerException("Right binder must not be null"); + public IPair + bindRight(final Function> rightBinder) { + if (rightBinder == null) + throw new NullPointerException("Right binder must not be null"); final Supplier rightSupp = () -> { IPair newPair = boundPair; - if(!pairBound) { + if (!pairBound) { /* - * If the pair hasn't been bound before, bind - * it. + * If the pair hasn't been bound before, bind it. */ newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -134,35 +135,37 @@ public class BoundLazyPair implements IPai } @Override - public IPair combine( - final IPair otherPair, - final BiFunction leftCombiner, - final BiFunction rightCombiner) { - if(otherPair == null) { + public + IPair + combine(final IPair otherPair, + final BiFunction leftCombiner, + final BiFunction rightCombiner) { + if (otherPair == null) { throw new NullPointerException("Other pair must not be null"); - } else if(leftCombiner == null) { + } else if (leftCombiner == null) { throw new NullPointerException("Left combiner must not be null"); - } else if(rightCombiner == null) { + } else if (rightCombiner == null) { throw new NullPointerException("Right combiner must not be null"); } - return otherPair.bind((otherLeft, otherRight) -> { - return bind((leftVal, rightVal) -> { - CombinedLeft cLeft = leftCombiner.apply(leftVal, otherLeft); - CombinedRight cRight = rightCombiner.apply(rightVal, otherRight); + 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); - }); - }); + return new LazyPair<>(cLeft, cRight); + })); } @Override - public IPair mapLeft(final Function mapper) { - if(mapper == null) throw new NullPointerException("Mapper must not be null"); + public IPair + mapLeft(final Function mapper) { + if (mapper == null) + throw new NullPointerException("Mapper must not be null"); final Supplier leftSupp = () -> { - if(!pairBound) { - final NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); + if (!pairBound) { + final NewLeft leftVal + = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return mapper.apply(leftVal); } @@ -171,7 +174,8 @@ public class BoundLazyPair implements IPai }; final Supplier rightSupp = () -> { - if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); + if (!pairBound) + return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); return boundPair.getRight(); }; @@ -180,19 +184,22 @@ public class BoundLazyPair implements IPai } @Override - public IPair mapRight(final Function mapper) { - if(mapper == null) throw new NullPointerException("Mapper must not be null"); + public IPair + mapRight(final Function mapper) { + if (mapper == null) + throw new NullPointerException("Mapper must not be null"); final Supplier leftSupp = () -> { - if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); + if (!pairBound) + return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return boundPair.getLeft(); }; final Supplier rightSupp = () -> { - if(!pairBound) { - final NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()) - .getRight(); + if (!pairBound) { + final NewRight rightVal = binder + .apply(leftSupplier.get(), rightSupplier.get()).getRight(); return mapper.apply(rightVal); } @@ -204,10 +211,12 @@ public class BoundLazyPair implements IPai } @Override - public MergedType merge(final BiFunction merger) { - if(merger == null) throw new NullPointerException("Merger must not be null"); + public MergedType + merge(final BiFunction merger) { + if (merger == null) + throw new NullPointerException("Merger must not be null"); - if(!pairBound) { + if (!pairBound) { /* * If the pair isn't bound yet, bind it. */ @@ -221,7 +230,8 @@ public class BoundLazyPair implements IPai @Override public String toString() { - if(pairBound) return boundPair.toString(); + if (pairBound) + return boundPair.toString(); return "(un-materialized)"; } -- cgit v1.2.3