From 4cc3ed81e90cde2f2e73ffa652d2012aeef36ab9 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Tue, 24 Oct 2023 13:49:14 -0600 Subject: [PATCH] Fix tests Signed-off-by: Taylor Smock --- .../maproulette/api/model/RecordUtils.java | 109 ++++++++---------- 1 file changed, 48 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/model/RecordUtils.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/model/RecordUtils.java index c9c50bb..c3486bd 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/model/RecordUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/model/RecordUtils.java @@ -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 } @@ -40,26 +39,22 @@ static 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); } @@ -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); } @@ -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); }