Add equals and hashcode to PType (#1691)
This commit is contained in:
1 parent
f7cac257ad
commit
dd6939ab3f
3 files changed
+170
No files matched your search
@@ -80,6 +80,17 @@ public abstract class PType implements Serializable {
|
||||
public String toString() {
|
||||
return ValueFormatter.basic().formatStringValue(literal, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof StringLiteral that && literal.equals(that.literal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return literal.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Class extends PType {
|
||||
@@ -125,6 +136,19 @@ public abstract class PType implements Serializable {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof Class that
|
||||
&& pClass.equals(that.pClass)
|
||||
&& typeArguments.equals(that.typeArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * pClass.hashCode() + typeArguments.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Nullable extends PType {
|
||||
@@ -146,6 +170,17 @@ public abstract class PType implements Serializable {
|
||||
? "(" + baseType + ")?"
|
||||
: baseType + "?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof Nullable that && baseType.equals(that.baseType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return baseType.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Constrained extends PType {
|
||||
@@ -176,6 +211,19 @@ public abstract class PType implements Serializable {
|
||||
+ String.join(", ", constraints)
|
||||
+ ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof Constrained that
|
||||
&& baseType.equals(that.baseType)
|
||||
&& constraints.equals(that.constraints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * baseType.hashCode() + constraints.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Alias extends PType {
|
||||
@@ -223,6 +271,19 @@ public abstract class PType implements Serializable {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof Alias that
|
||||
&& typeAlias.equals(that.typeAlias)
|
||||
&& typeArguments.equals(that.typeArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * typeAlias.hashCode() + typeArguments.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Function extends PType {
|
||||
@@ -251,6 +312,19 @@ public abstract class PType implements Serializable {
|
||||
+ ") -> "
|
||||
+ returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof Function that
|
||||
&& parameterTypes.equals(that.parameterTypes)
|
||||
&& returnType.equals(that.returnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * parameterTypes.hashCode() + returnType.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Union extends PType {
|
||||
@@ -270,6 +344,17 @@ public abstract class PType implements Serializable {
|
||||
public String toString() {
|
||||
return elementTypes.stream().map(Object::toString).collect(Collectors.joining(" | "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof Union that && elementTypes.equals(that.elementTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return elementTypes.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TypeVariable extends PType {
|
||||
@@ -293,5 +378,16 @@ public abstract class PType implements Serializable {
|
||||
public String toString() {
|
||||
return typeParameter.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@org.jspecify.annotations.Nullable Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof TypeVariable that && typeParameter.equals(that.typeParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return typeParameter.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user