From 61fd71f69e080790da722e0e03b71ecd7c2538a2 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 10 May 2016 16:02:45 -0400 Subject: General update --- BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Pair.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java index 0d2c1b0..eb421bc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -15,7 +15,9 @@ import java.util.function.Function; */ public class Pair implements IPair { + // The left value private LeftType leftValue; + // The right value private RightType rightValue; /** @@ -40,24 +42,40 @@ public class Pair @Override public IPair bind( BiFunction> binder) { + if (binder == null) { + throw new NullPointerException("Binder must not be null."); + } + return binder.apply(leftValue, rightValue); } @Override public IPair bindLeft( Function> leftBinder) { + if (leftBinder == null) { + throw new NullPointerException("Binder must not be null"); + } + return leftBinder.apply(leftValue); } @Override public IPair bindRight( Function> rightBinder) { + if (rightBinder == null) { + throw new NullPointerException("Binder must not be null"); + } + return rightBinder.apply(rightValue); } @Override public MergedType merge(BiFunction merger) { + if (merger == null) { + throw new NullPointerException("Merger must not be null"); + } + return merger.apply(leftValue, rightValue); } @@ -70,12 +88,20 @@ public class Pair @Override public IPair mapLeft(Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + return new Pair<>(mapper.apply(leftValue), rightValue); } @Override public IPair mapRight(Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + return new Pair<>(leftValue, mapper.apply(rightValue)); } } \ No newline at end of file -- cgit v1.2.3