From 889fac2bdf993dc86f64a8893c0260fdcf848acb Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 16:40:33 -0400 Subject: Cleanup --- .../bjc/utils/data/internals/BoundLazyPair.java | 99 +++++++++++----------- 1 file changed, 50 insertions(+), 49 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java index de290a6..9333e15 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java @@ -1,14 +1,14 @@ 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; - /* * Implements a lazy pair that has been bound */ @@ -17,16 +17,16 @@ public class BoundLazyPair implements IPai /* * The supplier of the left value */ - private Supplier leftSupplier; + private final Supplier leftSupplier; /* * The supplier of the right value */ - private Supplier rightSupplier; + private final Supplier rightSupplier; /* * The binder to transform values */ - private BiFunction> binder; + private final BiFunction> binder; /* * The bound pair @@ -38,8 +38,8 @@ public class BoundLazyPair implements IPai */ private boolean pairBound; - public BoundLazyPair(Supplier leftSupp, Supplier rightSupp, - BiFunction> bindr) { + public BoundLazyPair(final Supplier leftSupp, final Supplier rightSupp, + final BiFunction> bindr) { leftSupplier = leftSupp; rightSupplier = rightSupp; binder = bindr; @@ -47,14 +47,14 @@ public class BoundLazyPair implements IPai @Override public IPair bind( - BiFunction> bindr) { - if(bindr == null) throw new NullPointerException("Binder must not be null"); + final BiFunction> bindr) { + if (bindr == null) throw new NullPointerException("Binder must not be null"); - IHolder> newPair = new Identity<>(boundPair); - IHolder newPairMade = new Identity<>(pairBound); + final IHolder> newPair = new Identity<>(boundPair); + final IHolder newPairMade = new Identity<>(pairBound); - Supplier leftSupp = () -> { - if(!newPairMade.getValue()) { + final Supplier leftSupp = () -> { + if (!newPairMade.getValue()) { newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); newPairMade.replace(true); @@ -63,8 +63,8 @@ public class BoundLazyPair implements IPai return newPair.unwrap((pair) -> pair.getLeft()); }; - Supplier rightSupp = () -> { - if(!newPairMade.getValue()) { + final Supplier rightSupp = () -> { + if (!newPairMade.getValue()) { newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); newPairMade.replace(true); @@ -78,13 +78,13 @@ public class BoundLazyPair implements IPai @Override public IPair bindLeft( - Function> leftBinder) { - if(leftBinder == null) throw new NullPointerException("Left binder must not be null"); + final Function> leftBinder) { + if (leftBinder == null) throw new NullPointerException("Left binder must not be null"); - Supplier leftSupp = () -> { + final Supplier leftSupp = () -> { IPair newPair = boundPair; - if(!pairBound) { + if (!pairBound) { newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -96,13 +96,13 @@ public class BoundLazyPair implements IPai @Override public IPair bindRight( - Function> rightBinder) { - if(rightBinder == null) throw new NullPointerException("Right binder must not be null"); + final Function> rightBinder) { + if (rightBinder == null) throw new NullPointerException("Right binder must not be null"); - Supplier rightSupp = () -> { + final Supplier rightSupp = () -> { IPair newPair = boundPair; - if(!pairBound) { + if (!pairBound) { newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -114,14 +114,14 @@ public class BoundLazyPair implements IPai @Override public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { - if(otherPair == null) + 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) throw new NullPointerException("Right combiner must not be null"); + else if (rightCombiner == null) throw new NullPointerException("Right combiner must not be null"); return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { @@ -132,12 +132,12 @@ public class BoundLazyPair implements IPai } @Override - public IPair mapLeft(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"); - Supplier leftSupp = () -> { - if(!pairBound) { - NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); + final Supplier leftSupp = () -> { + if (!pairBound) { + final NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return mapper.apply(leftVal); } @@ -145,8 +145,8 @@ public class BoundLazyPair implements IPai return mapper.apply(boundPair.getLeft()); }; - Supplier rightSupp = () -> { - if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); + final Supplier rightSupp = () -> { + if (!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); return boundPair.getRight(); }; @@ -155,18 +155,19 @@ public class BoundLazyPair implements IPai } @Override - public IPair mapRight(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"); - Supplier leftSupp = () -> { - if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); + final Supplier leftSupp = () -> { + if (!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return boundPair.getLeft(); }; - Supplier rightSupp = () -> { - if(!pairBound) { - NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); + final Supplier rightSupp = () -> { + if (!pairBound) { + final NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()) + .getRight(); return mapper.apply(rightVal); } @@ -178,10 +179,10 @@ public class BoundLazyPair implements IPai } @Override - public MergedType merge(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) { boundPair = binder.apply(leftSupplier.get(), rightSupplier.get()); pairBound = true; @@ -192,7 +193,7 @@ 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