summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-05-10 16:02:45 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-05-10 16:02:45 -0400
commit61fd71f69e080790da722e0e03b71ecd7c2538a2 (patch)
treee5c1150b27b84d550f807e44ac82688216451f00 /BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
parent87ae1dfc8d8cb7b51d7bda4750ce841bbe691cfc (diff)
General update
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.java26
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