Fix/improve hashCode for Functions
Some types of Function had hashCode methods which didn't match the behavior of equals, while others could simply be rewritten in a simpler way by using Objects.hash.
This commit is contained in:
parent
0c316226e6
commit
a74f047655
@ -133,10 +133,10 @@ public abstract class FunctionDynamic implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract FunctionDynamic clone();
|
public abstract FunctionDynamic clone();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return functions.hashCode() + 883 * super.hashCode();
|
return Arrays.hashCode(functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,6 +6,8 @@ import it.cavallium.warppi.util.Errors;
|
|||||||
import it.cavallium.warppi.util.Utils;
|
import it.cavallium.warppi.util.Utils;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class FunctionOperator implements Function {
|
public abstract class FunctionOperator implements Function {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,7 +177,7 @@ public abstract class FunctionOperator implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return parameter1.hashCode() + 7 * parameter2.hashCode() + 883 * super.hashCode();
|
return Objects.hash(parameter1, parameter2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,6 +4,8 @@ import it.cavallium.warppi.math.rules.Rule;
|
|||||||
import it.cavallium.warppi.util.Error;
|
import it.cavallium.warppi.util.Error;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class FunctionSingle implements Function {
|
public abstract class FunctionSingle implements Function {
|
||||||
|
|
||||||
private boolean simplified;
|
private boolean simplified;
|
||||||
@ -117,7 +119,7 @@ public abstract class FunctionSingle implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return parameter.hashCode() + 883 * super.hashCode();
|
return Objects.hash(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,6 +8,8 @@ import it.cavallium.warppi.math.rules.Rule;
|
|||||||
import it.cavallium.warppi.util.Error;
|
import it.cavallium.warppi.util.Error;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Variable implements Function {
|
public class Variable implements Function {
|
||||||
|
|
||||||
protected char var;
|
protected char var;
|
||||||
@ -84,7 +86,7 @@ public class Variable implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return toString().hashCode();
|
return Objects.hash(var, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user