From ba9cf27de7e9f31dfa97a7266979f300101d67f9 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 10 Nov 2016 19:44:22 -0500 Subject: Doc updates --- .../main/java/bjc/utils/data/BoundLazyPair.java | 31 +++++++++++ .../main/java/bjc/utils/data/BoundListHolder.java | 26 ++++++++- .../src/main/java/bjc/utils/data/Either.java | 61 ++++++++++++++++------ .../java/bjc/utils/data/HalfBoundLazyPair.java | 21 ++++---- .../src/main/java/bjc/utils/data/package-info.java | 3 +- 5 files changed, 112 insertions(+), 30 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java index 2b3fb29..c7eb965 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java @@ -80,6 +80,10 @@ class BoundLazyPair @Override public IPair bindLeft( Function> leftBinder) { + if (leftBinder == null) { + throw new NullPointerException("Left binder must not be null"); + } + Supplier leftSupp = () -> { IPair newPair = boundPair; @@ -97,6 +101,11 @@ class BoundLazyPair @Override public IPair bindRight( Function> rightBinder) { + if (rightBinder == null) { + throw new NullPointerException( + "Right binder must not be null"); + } + Supplier rightSupp = () -> { IPair newPair = boundPair; @@ -116,6 +125,16 @@ class BoundLazyPair IPair otherPair, BiFunction leftCombiner, BiFunction rightCombiner) { + if (otherPair == null) { + throw new NullPointerException("Other pair must not be 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"); + } + return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( @@ -128,6 +147,10 @@ class BoundLazyPair @Override public IPair mapLeft( Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + Supplier leftSupp = () -> { if (!pairBound) { NewLeft leftVal = binder @@ -156,6 +179,10 @@ class BoundLazyPair @Override public IPair mapRight( Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + Supplier leftSupp = () -> { if (!pairBound) { return binder @@ -184,6 +211,10 @@ class BoundLazyPair @Override public MergedType merge( BiFunction merger) { + if (merger == null) { + throw new NullPointerException("Merger must not be null"); + } + if (!pairBound) { boundPair = binder.apply(leftSupplier.get(), rightSupplier.get()); diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java index fe47dcc..a967383 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java @@ -5,6 +5,9 @@ import java.util.function.UnaryOperator; import bjc.utils.funcdata.IList; +/* + * Holds a list, converted into a holder + */ class BoundListHolder implements IHolder { private IList> heldHolders; @@ -15,6 +18,10 @@ class BoundListHolder implements IHolder { @Override public IHolder bind( Function> binder) { + if (binder == null) { + throw new NullPointerException("Binder must not be null"); + } + IList> boundHolders = heldHolders .map((containedHolder) -> { return containedHolder.bind(binder); @@ -26,6 +33,11 @@ class BoundListHolder implements IHolder { @Override public Function> lift( Function func) { + if (func == null) { + throw new NullPointerException( + "Function to lift must not be null"); + } + return (val) -> { return new ListHolder<>(func.apply(val)); }; @@ -34,6 +46,10 @@ class BoundListHolder implements IHolder { @Override public IHolder map( Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + IList> mappedHolders = heldHolders .map((containedHolder) -> { return containedHolder.map(mapper); @@ -45,6 +61,10 @@ class BoundListHolder implements IHolder { @Override public IHolder transform( UnaryOperator transformer) { + if (transformer == null) { + throw new NullPointerException("Transformer must not be null"); + } + heldHolders.forEach((containedHolder) -> { containedHolder.transform(transformer); }); @@ -55,6 +75,10 @@ class BoundListHolder implements IHolder { @Override public UnwrappedType unwrap( Function unwrapper) { + if (unwrapper == null) { + throw new NullPointerException("Unwrapper must not be null"); + } + return heldHolders.randItem().unwrap(unwrapper); } -} +} \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java index aa38959..3ab4c00 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java @@ -26,9 +26,8 @@ public class Either * The value to put on the left * @return An either with the left side occupied */ - public static Either fromLeft( - LeftType left) { + public static Either fromLeft( + LeftType left) { return new Either<>(left, null); } @@ -43,9 +42,8 @@ public class Either * The value to put on the right * @return An either with the right side occupied */ - public static Either fromRight( - RightType right) { + public static Either fromRight( + RightType right) { return new Either<>(null, right); } @@ -55,7 +53,7 @@ public class Either private boolean isLeft; - private Either(LeftType left, RightType right) { + private Either( LeftType left, RightType right) { if (left == null) { rightVal = right; } else { @@ -67,14 +65,21 @@ public class Either @Override public IPair bind( - BiFunction> binder) { + BiFunction> binder) { + if (binder == null) { + throw new NullPointerException("Binder must not be null"); + } + return binder.apply(leftVal, rightVal); } @Override public IPair bindLeft( Function> leftBinder) { + if (leftBinder == null) { + throw new NullPointerException("Left binder must not be null"); + } + if (isLeft) { return leftBinder.apply(leftVal); } @@ -85,6 +90,11 @@ public class Either @Override public IPair bindRight( Function> rightBinder) { + if (rightBinder == null) { + throw new NullPointerException( + "Right binder must not be null"); + } + if (isLeft) { return new Either<>(leftVal, null); } @@ -93,13 +103,20 @@ public class Either } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { + if (otherPair == null) { + throw new NullPointerException("Other pair must not be 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"); + } + if (isLeft) { return otherPair.bind((otherLeft, otherRight) -> { return new Either<>(leftCombiner.apply(leftVal, otherLeft), @@ -116,6 +133,10 @@ public class Either @Override public IPair mapLeft( Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + if (isLeft) { return new Either<>(mapper.apply(leftVal), null); } @@ -126,6 +147,10 @@ public class Either @Override public IPair mapRight( Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + if (isLeft) { return new Either<>(leftVal, null); } @@ -136,6 +161,10 @@ public class Either @Override public MergedType merge( BiFunction merger) { + if (merger == null) { + throw new NullPointerException("Merger must not be null"); + } + return merger.apply(leftVal, rightVal); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java index 72c0bdf..58c375b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java @@ -4,6 +4,9 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; +/* + * A lazy pair, with only one side bound + */ class HalfBoundLazyPair implements IPair { private Supplier oldSupplier; @@ -21,10 +24,9 @@ class HalfBoundLazyPair @Override public IPair bind( - BiFunction> bindr) { - IHolder> newPair = new Identity<>(boundPair); + BiFunction> bindr) { + IHolder> newPair = new Identity<>( + boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { @@ -81,13 +83,10 @@ class HalfBoundLazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java index f5039bc..7b97a72 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java @@ -4,5 +4,4 @@ * @author ben * */ -@org.eclipse.jdt.annotation.NonNullByDefault -package bjc.utils.data; \ No newline at end of file +package bjc.utils.data; -- cgit v1.2.3