-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTuple4.java
More file actions
124 lines (99 loc) · 3.32 KB
/
Copy pathTuple4.java
File metadata and controls
124 lines (99 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package jaskell.util;
import java.util.Objects;
public class Tuple4<T, U, V, W> implements Tuple<T, Tuple3<U, V, W>, W, Tuple3<T, U, V>> {
final T item0;
final U item1;
final V item2;
final W item3;
public T getItem0() {
return item0;
}
public U getItem1() {
return item1;
}
public V getItem2() {
return item2;
}
public W getItem3() {
return item3;
}
public Tuple4(T item0, U item1, V item2, W item3) {
this.item0 = item0;
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
}
public <R> R uncurry(Function4<T, U, V, W, R> functor) throws Exception {
return functor.apply(getItem0(), getItem1(), getItem2(), getItem3());
}
public <R> Try<R> tryIt(Function4<T, U, V, W, R> functor) throws Exception {
return functor.collect(getItem0(), getItem1(), getItem2(), getItem3());
}
public <X> Tuple4<X, U, V, W> item0(X item) {
return new Tuple4<>(item, getItem1(), getItem2(), getItem3());
}
public <X> Tuple4<T, X, V, W> item1(X item) {
return new Tuple4<>(getItem0(), item, getItem2(), getItem3());
}
public <X> Tuple4<T, U, X, W> item2(X item) {
return new Tuple4<>(getItem0(), getItem1(), item, getItem3());
}
public <X> Tuple4<T, U, V, X> item3(X item) {
return new Tuple4<>(getItem0(), getItem1(), getItem2(), item);
}
public <X> Tuple5<T, U, V, W, X> add(X item) {
return new Tuple5<>(getItem0(), getItem1(), getItem2(), getItem3(), item);
}
public <X> Try<Tuple5<T, U, V, W, X>> tryAdd(Try<X> tryItem) {
return tryItem.map(item -> new Tuple5<>(getItem0(), getItem1(), getItem2(), getItem3(), item));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Tuple4)) return false;
Tuple4<?, ?, ?, ?> tuple4 = (Tuple4<?, ?, ?, ?>) o;
return Objects.equals(getItem0(), tuple4.getItem0()) && Objects.equals(getItem1(), tuple4.getItem1()) && Objects.equals(getItem2(), tuple4.getItem2()) && Objects.equals(getItem3(), tuple4.getItem3());
}
@Override
public int hashCode() {
return Objects.hash(getItem0(), getItem1(), getItem2(), getItem3());
}
public static <T, U, V, W> Try<Tuple4<T, U, V, W>> liftA(Try<T> t0, Try<U> t1, Try<V> t2, Try<W> t3) {
return Try.joinMap4(t0, t1, t2, t3, Tuple4::new);
}
@Override
public int size() {
return 4;
}
@Override
public Object get(int pos) throws IndexOutOfBoundsException {
switch (pos) {
case 0:
return getItem0();
case 1:
return getItem1();
case 2:
return getItem2();
case 3:
return getItem3();
default:
throw new IndexOutOfBoundsException("tuple4 only accept pos in range [0, 3]");
}
}
@Override
public T head() {
return getItem0();
}
@Override
public Tuple3<U, V, W> tail() {
return new Tuple3<>(getItem1(), getItem2(), getItem3());
}
@Override
public W last() {
return getItem3();
}
@Override
public Tuple3<T, U, V> butLast() {
return new Tuple3<>(getItem0(), getItem1(), getItem2());
}
}