-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathIntTuple.java
More file actions
55 lines (41 loc) · 1.08 KB
/
IntTuple.java
File metadata and controls
55 lines (41 loc) · 1.08 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
package de.peeeq.datastructures;
import org.eclipse.jdt.annotation.Nullable;
import java.util.Arrays;
public class IntTuple {
private final int[] ar;
private IntTuple(int len) {
ar = new int[len];
}
public static IntTuple of(int... is) {
IntTuple r = new IntTuple(is.length);
System.arraycopy(is, 0, r.ar, 0, is.length);
return r;
}
public int head() {
return ar[0];
}
public IntTuple tail() {
IntTuple r = new IntTuple(ar.length - 1);
System.arraycopy(ar, 1, r.ar, 0, ar.length - 1);
return r;
}
@Override
public String toString() {
return Arrays.toString(ar);
}
@Override
public int hashCode() {
return Arrays.hashCode(ar);
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IntTuple other = (IntTuple) obj;
return Arrays.equals(ar, other.ar);
}
}