aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple.java
blob: bf844c6dc8c7ca3d316c1911eef29646b3f674b8 (plain) (blame)
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
package tools.refinery.store.tuple;

public sealed interface Tuple extends TupleLike permits Tuple0, Tuple1, Tuple2, TupleN {
	@Override
	default Tuple toTuple() {
		return this;
	}

	static Tuple of() {
		return Tuple0.INSTANCE;
	}

	static Tuple of(int value) {
		return Tuple1.Cache.INSTANCE.getOrCreate(value);
	}

	static Tuple of(int value1, int value2) {
		return new Tuple2(value1, value2);
	}

	static Tuple of(int... values) {
		return switch (values.length) {
			case 0 -> of();
			case 1 -> of(values[0]);
			case 2 -> of(values[0], values[1]);
			default -> new TupleN(values);
		};
	}
}