-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Containers in Depth: Exercise 28 - Initial commit
- Loading branch information
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class FiveTuple<A, B, C, D, E> extends FourTuple<A, B, C, D> { | ||
public final E fifth; | ||
|
||
public FiveTuple(A a, B b, C c, D d, E e) { | ||
super(a, b, c, d); | ||
fifth = e; | ||
} | ||
|
||
public String toString() { | ||
return "(" + first + ", " + second + ", " + | ||
third + ", " + fourth + ", " + fifth + ")"; | ||
} | ||
|
||
public int hashCode() { | ||
|
||
} | ||
|
||
public boolean equals() { | ||
|
||
} | ||
|
||
public int compareTo(TwoTuple other) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class FourTuple<A, B, C, D> extends ThreeTuple<A, B, C> { | ||
public final D fourth; | ||
|
||
public FourTuple(A a, B b, C c, D d) { | ||
super(a, b, c); | ||
fourth = d; | ||
} | ||
|
||
public String toString() { | ||
return "(" + first + ", " + second + ", " + | ||
third + ", " + fourth + ")"; | ||
} | ||
|
||
public int hashCode() { | ||
|
||
} | ||
|
||
public boolean equals() { | ||
|
||
} | ||
|
||
public int compareTo(TwoTuple other) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class ThreeTuple<A, B, C> extends TwoTuple<A, B> { | ||
public final C third; | ||
|
||
public ThreeTuple(A a, B b, C c) { | ||
super(a, b); | ||
third = c; | ||
} | ||
|
||
public String toString() { | ||
return "(" + first + ", " + second + ", " + third + ")"; | ||
} | ||
|
||
public int hashCode() { | ||
|
||
} | ||
|
||
public boolean equals() { | ||
|
||
} | ||
|
||
public int compareTo(TwoTuple other) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Tuple { | ||
public static <A, B> TwoTuple<A, B> tuple(A a, B b) { | ||
return new TwoTuple<A, B>(a, b); | ||
} | ||
|
||
public static <A, B, C> ThreeTuple<A, B, C> tuple(A a, B b, C c) { | ||
return new ThreeTuple<A, B, C>(a, b, c); | ||
} | ||
|
||
public static <A, B, C, D> FourTuple<A, B, C, D> tuple(A a, B b, C c, D d) { | ||
return new FourTuple<A, B, C, D>(a, b, c, d); | ||
} | ||
|
||
public static <A, B, C, D, E> FiveTuple<A, B, C, D, E> tuple(A a, B b, C c, D d, E e) { | ||
return new FiveTuple<A, B, C, D, E>(a, b, c, d, e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
public class TwoTuple<A, B> implements Comparable { | ||
public final A first; | ||
public final B second; | ||
|
||
public TwoTuple(A a, B b) { | ||
first = a; | ||
second = b; | ||
} | ||
|
||
public String toString() { | ||
return "(" + first + ", " + second + ")"; | ||
} | ||
|
||
public int hashCode() { | ||
int result = 17; | ||
result = 37 * result + first.hashCode(); | ||
result = 37 * result + second.hashCode(); | ||
return result; | ||
} | ||
|
||
public boolean equals(Object object) { | ||
return object instanceof TwoTuple && | ||
(first != null && first.equals(((TwoTuple) object).first)) && | ||
(second != null && second.equals(((TwoTuple) object).second)); | ||
} | ||
|
||
public int compareTo(TwoTuple other) { | ||
|
||
} | ||
} |