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 | 51 |
1 files changed, 25 insertions, 26 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 1fc0d19..1000fc0 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -70,24 +70,19 @@ public class Pair<LeftType, RightType> } @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); - } - - @Override - public String toString() { - return "pair[l=" + leftValue.toString() + ", r=" - + rightValue.toString() + "]"; + public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + return otherPair.bind((otherLeft, otherRight) -> { + return new Pair<>(leftCombiner.apply(leftValue, otherLeft), + rightCombiner.apply(rightValue, otherRight)); + }); } @Override - public <NewLeft> IPair<NewLeft, RightType> - mapLeft(Function<LeftType, NewLeft> mapper) { + public <NewLeft> IPair<NewLeft, RightType> mapLeft( + Function<LeftType, NewLeft> mapper) { if (mapper == null) { throw new NullPointerException("Mapper must not be null"); } @@ -96,8 +91,8 @@ public class Pair<LeftType, RightType> } @Override - public <NewRight> IPair<LeftType, NewRight> - mapRight(Function<RightType, NewRight> mapper) { + public <NewRight> IPair<LeftType, NewRight> mapRight( + Function<RightType, NewRight> mapper) { if (mapper == null) { throw new NullPointerException("Mapper must not be null"); } @@ -106,14 +101,18 @@ public class Pair<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> - IPair<CombinedLeft, CombinedRight> - combine(IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { - return otherPair.bind((otherLeft, otherRight) -> { - return new Pair<>(leftCombiner.apply(leftValue, otherLeft), - rightCombiner.apply(rightValue, otherRight)); - }); + 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); + } + + @Override + public String toString() { + return "pair[l=" + leftValue.toString() + ", r=" + + rightValue.toString() + "]"; } }
\ No newline at end of file |
