From 44be6e6cd7671dd243056107ffa6201504f7fbce Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sun, 25 Jun 2023 15:50:38 -0400 Subject: Update a number of things --- src/main/java/bjc/data/Triple.java | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/bjc/data/Triple.java (limited to 'src/main/java/bjc/data/Triple.java') diff --git a/src/main/java/bjc/data/Triple.java b/src/main/java/bjc/data/Triple.java new file mode 100644 index 0000000..296a169 --- /dev/null +++ b/src/main/java/bjc/data/Triple.java @@ -0,0 +1,78 @@ +package bjc.data; + +/** + * Represents a tuple of three values + * @author bjcul + * + * @param The type of the first value + * @param The type of the second value + * @param The type of the third value + */ +public interface Triple { + // TODO: fill this out more; mapping and the like + /** + * Get the left value for this triple. + * + * @return The left value for this triple. + */ + public Left left(); + + /** + * Get the right value for this triple. + * + * @return The right value for this triple. + */ + public Right right(); + + /** + * Get the middle value for this triple. + * + * @return The middle value for this triple. + */ + public Middle middle(); + + /** + * Create a new triple + * + * @param The type for the left + * @param The type for the middle + * @param The type for the right + * + * @param l The left value + * @param m The middle value + * @param r The right value + * + * @return A triple of the given values + */ + public static Triple of(Left l, Middle m, Right r) { + return new SimpleTriple<>(r, m, l); + } +} + +final class SimpleTriple implements Triple { + private final Right r; + private final Middle m; + private final Left l; + + SimpleTriple(Right r, Middle m, Left l) { + this.r = r; + this.m = m; + this.l = l; + } + + + @Override + public Left left() { + return l; + } + + @Override + public Right right() { + return r; + } + + @Override + public Middle middle() { + return m; + } +} \ No newline at end of file -- cgit v1.2.3