use pattern variables

This commit is contained in:
dfsek
2021-11-27 08:34:03 -07:00
parent 2d316fa042
commit 2307897b31
16 changed files with 33 additions and 58 deletions

View File

@@ -79,10 +79,8 @@ public final class Either<L, R> {
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Either)) return false;
Either<?, ?> that = (Either<?, ?>) obj;
if(!(obj instanceof Either<?, ?> that)) return false;
return (this.leftPresent && that.leftPresent && Objects.equals(this.left, that.left))
|| (!this.leftPresent && !that.leftPresent && Objects.equals(this.right, that.right));
}

View File

@@ -52,8 +52,7 @@ public final class ReflectionUtil {
public static Class<?> getRawType(Type type) {
if(type instanceof Class<?>) {
return (Class<?>) type;
} else if(type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
} else if(type instanceof ParameterizedType parameterizedType) {
Type rawType = parameterizedType.getRawType();
return (Class<?>) rawType;
} else if(type instanceof GenericArrayType) {

View File

@@ -38,39 +38,31 @@ public class TypeKey<T> {
return true;
} else if(a instanceof Class) {
return a.equals(b);
} else if(a instanceof ParameterizedType) {
if(!(b instanceof ParameterizedType)) {
} else if(a instanceof ParameterizedType pa) {
if(!(b instanceof ParameterizedType pb)) {
return false;
}
ParameterizedType pa = (ParameterizedType) a;
ParameterizedType pb = (ParameterizedType) b;
return Objects.equals(pa.getOwnerType(), pb.getOwnerType())
&& pa.getRawType().equals(pb.getRawType())
&& Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());
} else if(a instanceof GenericArrayType) {
if(!(b instanceof GenericArrayType)) {
} else if(a instanceof GenericArrayType ga) {
if(!(b instanceof GenericArrayType gb)) {
return false;
}
GenericArrayType ga = (GenericArrayType) a;
GenericArrayType gb = (GenericArrayType) b;
return equals(ga.getGenericComponentType(), gb.getGenericComponentType());
} else if(a instanceof WildcardType) {
if(!(b instanceof WildcardType)) {
} else if(a instanceof WildcardType wa) {
if(!(b instanceof WildcardType wb)) {
return false;
}
WildcardType wa = (WildcardType) a;
WildcardType wb = (WildcardType) b;
return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
&& Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());
} else if(a instanceof TypeVariable) {
if(!(b instanceof TypeVariable)) {
} else if(a instanceof TypeVariable<?> va) {
if(!(b instanceof TypeVariable<?> vb)) {
return false;
}
TypeVariable<?> va = (TypeVariable<?>) a;
TypeVariable<?> vb = (TypeVariable<?>) b;
return va.getGenericDeclaration() == vb.getGenericDeclaration()
&& va.getName().equals(vb.getName());
} else {

View File

@@ -189,8 +189,7 @@ public class Vector2 implements Cloneable {
}
public boolean equals(Object obj) {
if(!(obj instanceof Vector2)) return false;
Vector2 other = (Vector2) obj;
if(!(obj instanceof Vector2 other)) return false;
return MathUtil.equals(this.x, other.x) && MathUtil.equals(this.z, other.z);
}

View File

@@ -328,8 +328,7 @@ public class Vector3 implements Cloneable {
*/
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Vector3)) return false;
Vector3 other = (Vector3) obj;
if(!(obj instanceof Vector3 other)) return false;
return MathUtil.equals(x, other.getX()) && MathUtil.equals(y, other.getY()) && MathUtil.equals(z, other.getZ());
}