-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTuple5.java
More file actions
144 lines (118 loc) · 3.99 KB
/
Copy pathTuple5.java
File metadata and controls
144 lines (118 loc) · 3.99 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package jaskell.util;
import java.util.Objects;
/**
* @param <T>
* @param <U>
* @param <V>
* @param <W>
* @param <X>
*/
public class Tuple5<T, U, V, W, X>
implements Tuple<T, Tuple4<U, V, W, X>, X, Tuple4<T, U, V, W>> {
final T item0;
final U item1;
final V item2;
final W item3;
final X item4;
public T getItem0() {
return item0;
}
public U getItem1() {
return item1;
}
public V getItem2() {
return item2;
}
public W getItem3() {
return item3;
}
public X getItem4() {
return item4;
}
public Tuple5(T item0, U item1, V item2, W item3, X item4) {
this.item0 = item0;
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
this.item4 = item4;
}
public <R> R uncurry(Function5<T, U, V, W, X, R> functor) throws Exception {
return functor.apply(getItem0(), getItem1(), getItem2(), getItem3(), getItem4());
}
public <R> Try<R> tryIt(Function5<T, U, V, W, X, R> functor) {
return functor.collect(getItem0(), getItem1(), getItem2(), getItem3(), getItem4());
}
public <Y> Tuple5<Y, U, V, W, X> item0(Y item) {
return new Tuple5<>(item, getItem1(), getItem2(), getItem3(), getItem4());
}
public <Y> Tuple5<T, Y, V, W, X> item1(Y item) {
return new Tuple5<>(getItem0(), item, getItem2(), getItem3(), getItem4());
}
public <Y> Tuple5<T, U, Y, W, X> item2(Y item) {
return new Tuple5<>(getItem0(), getItem1(), item, getItem3(), getItem4());
}
public <Y> Tuple5<T, U, V, Y, X> item3(Y item) {
return new Tuple5<>(getItem0(), getItem1(), getItem2(), item, getItem4());
}
public <Y> Tuple5<T, U, V, W, Y> item4(Y item) {
return new Tuple5<>(getItem0(), getItem1(), getItem2(), getItem3(), item);
}
public <Y> Tuple6<T, U, V, W, X, Y> add(Y item) {
return new Tuple6<>(getItem0(), getItem1(), getItem2(), getItem3(), getItem4(), item);
}
public <Y> Try<Tuple6<T, U, V, W, X, Y>> tryAdd(Try<Y> tryItem) {
return tryItem.map(item -> new Tuple6<>(getItem0(), getItem1(), getItem2(), getItem3(), getItem4(), item));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Tuple5)) return false;
Tuple5<?, ?, ?, ?, ?> tuple5 = (Tuple5<?, ?, ?, ?, ?>) o;
return Objects.equals(getItem0(), tuple5.getItem0()) && Objects.equals(getItem1(), tuple5.getItem1()) && Objects.equals(getItem2(), tuple5.getItem2()) && Objects.equals(getItem3(), tuple5.getItem3()) && Objects.equals(getItem4(), tuple5.getItem4());
}
@Override
public int hashCode() {
return Objects.hash(getItem0(), getItem1(), getItem2(), getItem3(), getItem4());
}
public static <T, U, V, W, X> Try<Tuple5<T, U, V, W, X>> liftA(Try<T> t0, Try<U> t1, Try<V> t2,
Try<W> t3, Try<X> t4) {
return Try.joinMap5(t0, t1, t2, t3, t4, Tuple5::new);
}
@Override
public int size() {
return 5;
}
@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();
case 4:
return getItem4();
default:
throw new IndexOutOfBoundsException("tuple5 only accept pos in range [0, 4]");
}
}
@Override
public T head() {
return getItem0();
}
@Override
public Tuple4<U, V, W, X> tail() {
return new Tuple4<>(getItem1(), getItem2(), getItem3(), getItem4());
}
@Override
public X last() {
return getItem4();
}
@Override
public Tuple4<T, U, V, W> butLast() {
return new Tuple4<>(getItem0(), getItem1(), getItem2(), getItem3());
}
}