Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Oct 24, 2023
1 parent 6077d12 commit 4cc3ed8
Showing 1 changed file with 48 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* Utils for {@link Record} classes with array fields
*/
final class RecordUtils {
private static final String UNKNOWN_TYPE = "Unknown primitive type: ";
private RecordUtils() {
// Hide constructor
}
Expand All @@ -40,26 +39,22 @@ static <T extends Record> boolean equals(@Nonnull T first, @Nonnull T second) {
}

private static boolean arrayEquals(Class<?> type, Object first, Object second) {
if (type.isPrimitive()) {
if (int.class.equals(type)) {
return Arrays.equals((int[]) first, (int[]) second);
} else if (byte.class.equals(type)) {
return Arrays.equals((byte[]) first, (byte[]) second);
} else if (short.class.equals(type)) {
return Arrays.equals((short[]) first, (short[]) second);
} else if (long.class.equals(type)) {
return Arrays.equals((long[]) first, (long[]) second);
} else if (float.class.equals(type)) {
return Arrays.equals((float[]) first, (float[]) second);
} else if (double.class.equals(type)) {
return Arrays.equals((double[]) first, (double[]) second);
} else if (boolean.class.equals(type)) {
return Arrays.equals((boolean[]) first, (boolean[]) second);
} else if (char.class.equals(type)) {
return Arrays.equals((char[]) first, (char[]) second);
} else {
throw new JosmRuntimeException(UNKNOWN_TYPE + type);
}
if (int[].class.equals(type)) {
return Arrays.equals((int[]) first, (int[]) second);
} else if (byte[].class.equals(type)) {
return Arrays.equals((byte[]) first, (byte[]) second);
} else if (short[].class.equals(type)) {
return Arrays.equals((short[]) first, (short[]) second);
} else if (long[].class.equals(type)) {
return Arrays.equals((long[]) first, (long[]) second);
} else if (float[].class.equals(type)) {
return Arrays.equals((float[]) first, (float[]) second);
} else if (double[].class.equals(type)) {
return Arrays.equals((double[]) first, (double[]) second);
} else if (boolean[].class.equals(type)) {
return Arrays.equals((boolean[]) first, (boolean[]) second);
} else if (char[].class.equals(type)) {
return Arrays.equals((char[]) first, (char[]) second);
} else {
return Arrays.equals((Object[]) first, (Object[]) second);
}
Expand All @@ -86,26 +81,22 @@ static int hashCode(@Nonnull Record hashCode) {
}

private static int arrayHashCode(Class<?> type, Object field) {
if (type.isPrimitive()) {
if (int.class.equals(type)) {
return Arrays.hashCode((int[]) field);
} else if (byte.class.equals(type)) {
return Arrays.hashCode((byte[]) field);
} else if (short.class.equals(type)) {
return Arrays.hashCode((short[]) field);
} else if (long.class.equals(type)) {
return Arrays.hashCode((long[]) field);
} else if (float.class.equals(type)) {
return Arrays.hashCode((float[]) field);
} else if (double.class.equals(type)) {
return Arrays.hashCode((double[]) field);
} else if (boolean.class.equals(type)) {
return Arrays.hashCode((boolean[]) field);
} else if (char.class.equals(type)) {
return Arrays.hashCode((char[]) field);
} else {
throw new JosmRuntimeException(UNKNOWN_TYPE + type);
}
if (int[].class.equals(type)) {
return Arrays.hashCode((int[]) field);
} else if (byte[].class.equals(type)) {
return Arrays.hashCode((byte[]) field);
} else if (short[].class.equals(type)) {
return Arrays.hashCode((short[]) field);
} else if (long[].class.equals(type)) {
return Arrays.hashCode((long[]) field);
} else if (float[].class.equals(type)) {
return Arrays.hashCode((float[]) field);
} else if (double[].class.equals(type)) {
return Arrays.hashCode((double[]) field);
} else if (boolean[].class.equals(type)) {
return Arrays.hashCode((boolean[]) field);
} else if (char[].class.equals(type)) {
return Arrays.hashCode((char[]) field);
} else {
return Arrays.hashCode((Object[]) field);
}
Expand Down Expand Up @@ -136,26 +127,22 @@ static String toString(@Nonnull Record toString) {
}

private static String getArrayString(Class<?> type, Object field) {
if (type.isPrimitive()) {
if (int.class.equals(type)) {
return Arrays.toString((int[]) field);
} else if (byte.class.equals(type)) {
return Arrays.toString((byte[]) field);
} else if (short.class.equals(type)) {
return Arrays.toString((short[]) field);
} else if (long.class.equals(type)) {
return Arrays.toString((long[]) field);
} else if (float.class.equals(type)) {
return Arrays.toString((float[]) field);
} else if (double.class.equals(type)) {
return Arrays.toString((double[]) field);
} else if (boolean.class.equals(type)) {
return Arrays.toString((boolean[]) field);
} else if (char.class.equals(type)) {
return Arrays.toString((char[]) field);
} else {
throw new JosmRuntimeException(UNKNOWN_TYPE + type);
}
if (int[].class.equals(type)) {
return Arrays.toString((int[]) field);
} else if (byte[].class.equals(type)) {
return Arrays.toString((byte[]) field);
} else if (short[].class.equals(type)) {
return Arrays.toString((short[]) field);
} else if (long[].class.equals(type)) {
return Arrays.toString((long[]) field);
} else if (float[].class.equals(type)) {
return Arrays.toString((float[]) field);
} else if (double[].class.equals(type)) {
return Arrays.toString((double[]) field);
} else if (boolean[].class.equals(type)) {
return Arrays.toString((boolean[]) field);
} else if (char[].class.equals(type)) {
return Arrays.toString((char[]) field);
} else {
return Arrays.toString((Object[]) field);
}
Expand Down

0 comments on commit 4cc3ed8

Please sign in to comment.