aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataSort.java
blob: 4fb44492a02b10c13fd4714a95fcd940c00dd396 (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.query.term;

import org.jetbrains.annotations.Nullable;

public record DataSort<T>(Class<T> type) implements Sort {
	public static final DataSort<Integer> INT = new DataSort<>(Integer.class);

	public static final DataSort<Boolean> BOOL = new DataSort<>(Boolean.class);

	@Override
	public boolean isInstance(Variable variable) {
		return variable instanceof DataVariable<?> dataVariable && type.equals(dataVariable.getType());
	}

	@Override
	public DataVariable<T> newInstance(@Nullable String name) {
		return Variable.of(name, type);
	}

	@Override
	public DataVariable<T> newInstance() {
		return newInstance(null);
	}

	@Override
	public String toString() {
		return type.getName();
	}
}