From ba9cf27de7e9f31dfa97a7266979f300101d67f9 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 10 Nov 2016 19:44:22 -0500 Subject: Doc updates --- .../src/main/java/bjc/utils/data/Either.java | 61 ++++++++++++++++------ 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Either.java') 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); } } -- cgit v1.2.3