Skip to content

Commit fb760d2

Browse files
committed
new: hashCode and equals for spline mixin
1 parent 3815533 commit fb760d2

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/mixin/MixinSplineImplementation.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import org.spongepowered.asm.mixin.Overwrite;
99
import org.spongepowered.asm.mixin.Shadow;
1010

11+
import java.util.Arrays;
1112
import java.util.List;
13+
import java.util.Objects;
1214

1315
@Mixin(Spline.Implementation.class)
1416
public abstract class MixinSplineImplementation<C, I extends ToFloatFunction<C>> {
1517

1618
/**
17-
* @author
18-
* @reason
19+
* @author ishland
20+
* @reason inline binary search
1921
*/
2022
@Overwrite
2123
private static int findRangeForLocation(float[] locations, float x) {
@@ -50,8 +52,8 @@ protected static float sampleOutsideRange(float point, float[] locations, float
5052
@Shadow @Final private float[] derivatives;
5153

5254
/**
53-
* @author
54-
* @reason
55+
* @author ishland
56+
* @reason simplify method a bit
5557
*/
5658
@Overwrite
5759
public float apply(C x) {
@@ -76,5 +78,23 @@ public float apply(C x) {
7678
}
7779
}
7880

81+
@Override
82+
public boolean equals(Object o) {
83+
if (this == o) return true;
84+
if (o == null || getClass() != o.getClass()) return false;
85+
Spline.Implementation<?, ?> that = (Spline.Implementation<?, ?>) o;
86+
return Objects.equals(locationFunction, that.locationFunction()) && Arrays.equals(locations, that.locations()) && Objects.equals(values, that.values()) && Arrays.equals(derivatives, that.derivatives());
87+
}
88+
89+
@Override
90+
public int hashCode() {
91+
int result = 1;
7992

93+
result = 31 * result + Objects.hashCode(locationFunction);
94+
result = 31 * result + Arrays.hashCode(locations);
95+
result = 31 * result + Objects.hashCode(values);
96+
result = 31 * result + Arrays.hashCode(derivatives);
97+
98+
return result;
99+
}
80100
}

0 commit comments

Comments
 (0)