Skip to content

Commit

Permalink
Containers in Depth: Exercise 28 - Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kean0212 committed May 24, 2017
1 parent 6fa9b53 commit 86ab9e7
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ContainersInDepth/FiveTuple.java
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) {

}
}
25 changes: 25 additions & 0 deletions ContainersInDepth/FourTuple.java
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) {

}
}
24 changes: 24 additions & 0 deletions ContainersInDepth/ThreeTuple.java
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) {

}
}
17 changes: 17 additions & 0 deletions ContainersInDepth/Tuple.java
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);
}
}
30 changes: 30 additions & 0 deletions ContainersInDepth/TwoTuple.java
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) {

}
}

0 comments on commit 86ab9e7

Please sign in to comment.