Skip to content

Commit fadc8cc

Browse files
committed
Add equals and hashCode to ArrayPropertyGetter
1 parent dad07a5 commit fadc8cc

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

rulesengine/src/main/java/software/amazon/smithy/java/rulesengine/ArrayPropertyGetter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
package software.amazon.smithy.java.rulesengine;
77

8+
import java.util.Arrays;
9+
810
/**
911
* Lightweight PropertyGetter backed by an interleaved value/key array.
1012
* Layout: [value0, key0, value1, key1, ...]. Keys are at odd indices.
1113
* More efficient than Map for small fixed-key lookups (linear scan beats hashing for ~4 entries).
14+
*
15+
* <p>Equality is value-based on the contents of {@code data} so callers can use instances as cache keys.
1216
*/
1317
record ArrayPropertyGetter(Object[] data) implements PropertyGetter {
1418
@Override
@@ -20,4 +24,14 @@ public Object getProperty(String name) {
2024
}
2125
return null;
2226
}
27+
28+
@Override
29+
public boolean equals(Object o) {
30+
return o instanceof ArrayPropertyGetter other && Arrays.equals(data, other.data);
31+
}
32+
33+
@Override
34+
public int hashCode() {
35+
return Arrays.hashCode(data);
36+
}
2337
}

0 commit comments

Comments
 (0)