From fff6dc5d43539af05ae2679640240b8545b36947 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 10 May 2016 21:58:08 -0400 Subject: Added interface to JDK collector API --- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 48 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/IPair.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java index 707724b..f94d656 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -81,7 +81,8 @@ public interface IPair "This function can only be applied to instances of IPair"); } - IPair argPair = (IPair) argumentPair; + IPair argPair = + (IPair) argumentPair; return argPair.mapLeft(func); }; @@ -98,7 +99,8 @@ public interface IPair "This function can only be applied to instances of IPair"); } - IPair argPair = (IPair) argumentPair; + IPair argPair = + (IPair) argumentPair; return argPair.mapRight(func); }; @@ -163,4 +165,46 @@ public interface IPair */ public MergedType merge(BiFunction merger); + + /** + * Combine the contents of two pairs together + * + * @param + * The type of the left value of the other pair + * @param + * The type of the right value of the other pair + * @param + * The type of the left value of the combined pair + * @param + * The type of the right value of the combined pair + * @param otherPair + * The other pair to combine with + * @param leftCombiner + * @param rightCombiner + * @return A pair with its values combined + */ + public + IPair + combine(IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner); + + /** + * Pairwise combine two pairs together + * + * @param + * The left type of the other pair + * @param + * The right type of the other pair + * @param otherPair + * The pair to combine with + * @return The pairs, pairwise combined together + */ + public default + IPair, IPair> + combine(IPair otherPair) { + return combine(otherPair, + (left, otherLeft) -> new Pair<>(left, otherLeft), + (right, otherRight) -> new Pair<>(right, otherRight)); + } } -- cgit v1.2.3