Skip to content

Commit

Permalink
fix: implement equals, hashCode and toString methods for ArrayValue
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Dec 26, 2023
1 parent 75c3827 commit d2a45a0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/team/unnamed/mocha/runtime/value/ArrayValue.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package team.unnamed.mocha.runtime.value;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

import static java.util.Objects.requireNonNull;

Expand All @@ -22,4 +25,22 @@ private ArrayValue(final @NotNull Value @NotNull ... values) {
public @NotNull Value get(final Value index) {
return values[(int) index.getAsNumber()];
}

@Override
public @NotNull String toString() {
return "ArrayValue[" + Arrays.toString(values) + "]";
}

@Override
public boolean equals(final @Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final ArrayValue that = (ArrayValue) o;
return Arrays.equals(values, that.values);
}

@Override
public int hashCode() {
return Arrays.hashCode(values);
}
}

0 comments on commit d2a45a0

Please sign in to comment.