From 504ca816530efdff06bc202e0432ebd354aec304 Mon Sep 17 00:00:00 2001 From: EVE Date: Tue, 14 Mar 2017 12:07:14 -0400 Subject: Cleanup --- .../bjc/utils/data/internals/BoundLazyPair.java | 66 ++++++++-------------- 1 file changed, 23 insertions(+), 43 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 d425d99..6ab8121 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 */ @@ -47,15 +47,13 @@ public class BoundLazyPair implements IPai @Override public IPair bind( BiFunction> bindr) { - if (bindr == null) { - throw new NullPointerException("Binder must not be null"); - } + if(bindr == null) throw new NullPointerException("Binder must not be null"); IHolder> newPair = new Identity<>(boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); newPairMade.replace(true); @@ -65,7 +63,7 @@ public class BoundLazyPair implements IPai }; Supplier rightSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); newPairMade.replace(true); @@ -80,14 +78,12 @@ public class BoundLazyPair implements IPai @Override public IPair bindLeft( Function> leftBinder) { - if (leftBinder == null) { - throw new NullPointerException("Left binder must not be null"); - } + if(leftBinder == null) throw new NullPointerException("Left binder must not be null"); Supplier leftSupp = () -> { IPair newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -100,14 +96,12 @@ public class BoundLazyPair implements IPai @Override public IPair bindRight( Function> rightBinder) { - if (rightBinder == null) { - throw new NullPointerException("Right binder must not be null"); - } + if(rightBinder == null) throw new NullPointerException("Right binder must not be null"); Supplier rightSupp = () -> { IPair newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -122,13 +116,11 @@ public class BoundLazyPair implements IPai IPair otherPair, BiFunction leftCombiner, BiFunction rightCombiner) { - if (otherPair == null) { + 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) -> { @@ -140,12 +132,10 @@ public class BoundLazyPair implements IPai @Override public IPair mapLeft(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); Supplier leftSupp = () -> { - if (!pairBound) { + if(!pairBound) { NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return mapper.apply(leftVal); @@ -155,9 +145,7 @@ public class BoundLazyPair implements IPai }; 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(); }; @@ -167,20 +155,16 @@ public class BoundLazyPair implements IPai @Override public IPair mapRight(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); 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(); }; Supplier rightSupp = () -> { - if (!pairBound) { + if(!pairBound) { NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); return mapper.apply(rightVal); @@ -194,11 +178,9 @@ public class BoundLazyPair implements IPai @Override public MergedType merge(BiFunction merger) { - if (merger == null) { - throw new NullPointerException("Merger must not be null"); - } + if(merger == null) throw new NullPointerException("Merger must not be null"); - if (!pairBound) { + if(!pairBound) { boundPair = binder.apply(leftSupplier.get(), rightSupplier.get()); pairBound = true; @@ -209,9 +191,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