diff options
author | 2023-06-18 14:12:20 +0200 | |
---|---|---|
committer | 2023-06-18 14:12:20 +0200 | |
commit | 2069579ce57dbaf04bff610f8151409e25bf114a (patch) | |
tree | 1f64df9abe0cdf3b5f87de44fcf1d4815fed970e /subprojects/store/src/main/java/tools | |
parent | fix: further Dnf tests and fixes (diff) | |
download | refinery-2069579ce57dbaf04bff610f8151409e25bf114a.tar.gz refinery-2069579ce57dbaf04bff610f8151409e25bf114a.tar.zst refinery-2069579ce57dbaf04bff610f8151409e25bf114a.zip |
refactor: clean up Symbol constructor
Shorthad syntax for the most commonly used symbol types.
Diffstat (limited to 'subprojects/store/src/main/java/tools')
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/representation/Symbol.java | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/representation/Symbol.java b/subprojects/store/src/main/java/tools/refinery/store/representation/Symbol.java index aad88921..cc748180 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/representation/Symbol.java +++ b/subprojects/store/src/main/java/tools/refinery/store/representation/Symbol.java | |||
@@ -7,18 +7,19 @@ package tools.refinery.store.representation; | |||
7 | 7 | ||
8 | public record Symbol<T>(String name, int arity, Class<T> valueType, T defaultValue) implements AnySymbol { | 8 | public record Symbol<T>(String name, int arity, Class<T> valueType, T defaultValue) implements AnySymbol { |
9 | @Override | 9 | @Override |
10 | public boolean equals(Object o) { | 10 | public String toString() { |
11 | return this == o; | 11 | return "%s/%d".formatted(name, arity); |
12 | } | 12 | } |
13 | 13 | ||
14 | @Override | 14 | public static Symbol<Boolean> of(String name, int arity) { |
15 | public int hashCode() { | 15 | return of(name, arity, Boolean.class, false); |
16 | // Compare by identity to make hash table lookups more efficient. | ||
17 | return System.identityHashCode(this); | ||
18 | } | 16 | } |
19 | 17 | ||
20 | @Override | 18 | public static <T> Symbol<T> of(String name, int arity, Class<T> valueType) { |
21 | public String toString() { | 19 | return of(name, arity, valueType, null); |
22 | return "%s/%d".formatted(name, arity); | 20 | } |
21 | |||
22 | public static <T> Symbol<T> of(String name, int arity, Class<T> valueType, T defaultValue) { | ||
23 | return new Symbol<>(name, arity, valueType, defaultValue); | ||
23 | } | 24 | } |
24 | } | 25 | } |