diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Pair.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 26 |
1 files changed, 26 insertions, 0 deletions
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<LeftType, RightType> implements IPair<LeftType, RightType> { + // The left value private LeftType leftValue; + // The right value private RightType rightValue; /** @@ -40,24 +42,40 @@ public class Pair<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + if (binder == null) { + throw new NullPointerException("Binder must not be null."); + } + return binder.apply(leftValue, rightValue); } @Override public <BoundLeft> IPair<BoundLeft, RightType> bindLeft( Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) { + if (leftBinder == null) { + throw new NullPointerException("Binder must not be null"); + } + return leftBinder.apply(leftValue); } @Override public <BoundRight> IPair<LeftType, BoundRight> bindRight( Function<RightType, IPair<LeftType, BoundRight>> rightBinder) { + if (rightBinder == null) { + throw new NullPointerException("Binder must not be null"); + } + return rightBinder.apply(rightValue); } @Override public <MergedType> MergedType merge(BiFunction<LeftType, RightType, MergedType> merger) { + if (merger == null) { + throw new NullPointerException("Merger must not be null"); + } + return merger.apply(leftValue, rightValue); } @@ -70,12 +88,20 @@ public class Pair<LeftType, RightType> @Override public <NewLeft> IPair<NewLeft, RightType> mapLeft(Function<LeftType, NewLeft> mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + return new Pair<>(mapper.apply(leftValue), rightValue); } @Override public <NewRight> IPair<LeftType, NewRight> mapRight(Function<RightType, NewRight> 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 |
