From 302e500d76d6fd27826bbb4470a28502a41ca50a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 2 Mar 2023 09:27:01 +0100 Subject: [PATCH] Remove atomix.utils.misc The only remnant here is ArraySizeHashPrinter, which is only used in TestEntry.toString(). Replace its use and ditch the entire package. JIRA: CONTROLLER-2071 Change-Id: Id4c70fe2d33bbc11c65ab7df6fa2a004affd1c63 Signed-off-by: Robert Varga --- .../io/atomix/storage/journal/TestEntry.java | 5 +- .../utils/misc/ArraySizeHashPrinter.java | 144 ------------------ .../io/atomix/utils/misc/package-info.java | 20 --- .../utils/ArraySizeHashPrinterTest.java | 32 ---- 4 files changed, 3 insertions(+), 198 deletions(-) delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/misc/ArraySizeHashPrinter.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/misc/package-info.java delete mode 100644 third-party/atomix/utils/src/test/java/io/atomix/utils/ArraySizeHashPrinterTest.java diff --git a/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/TestEntry.java b/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/TestEntry.java index dfbc004318..9c3f92974a 100644 --- a/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/TestEntry.java +++ b/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/TestEntry.java @@ -15,7 +15,7 @@ */ package io.atomix.storage.journal; -import io.atomix.utils.misc.ArraySizeHashPrinter; +import java.util.Arrays; import static com.google.common.base.MoreObjects.toStringHelper; @@ -42,7 +42,8 @@ public class TestEntry { @Override public String toString() { return toStringHelper(this) - .add("bytes", ArraySizeHashPrinter.of(bytes)) + .add("length", bytes.length) + .add("hash", Arrays.hashCode(bytes)) .toString(); } } diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/misc/ArraySizeHashPrinter.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/misc/ArraySizeHashPrinter.java deleted file mode 100644 index 0bf5d0da0e..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/misc/ArraySizeHashPrinter.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2014-present Open Networking Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.atomix.utils.misc; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -import java.lang.reflect.Array; -import java.util.Arrays; - -/** - * Helper to print Object[] length and hashCode. - */ -public final class ArraySizeHashPrinter { - - /** - * Returns ByteArraySizeHashPrinter wrapping given short[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(byte[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), byte[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given short[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(short[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), short[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given int[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(int[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), int[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given long[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(long[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), long[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given float[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(float[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), float[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given double[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(double[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), double[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given boolean[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(boolean[] array) { - return new ArraySizeHashPrinter(toObjectArray(array), boolean[].class); - } - - /** - * Returns ByteArraySizeHashPrinter wrapping given Object[]. - * - * @param array arrays to wrap around - * @return ObjectArraySizeHashPrinter - */ - public static ArraySizeHashPrinter of(Object[] array) { - return new ArraySizeHashPrinter(array, Object[].class); - } - - private static Object[] toObjectArray(Object val) { - if (val == null) { - return null; - } - if (val instanceof Object[]) { - return (Object[]) val; - } - int length = Array.getLength(val); - Object[] outputArray = new Object[length]; - for (int i = 0; i < length; ++i) { - outputArray[i] = Array.get(val, i); - } - return outputArray; - } - - private final Object[] array; - private final Class type; - - public ArraySizeHashPrinter(Object[] array, Class type) { - this.array = array; - this.type = type; - } - - @Override - public String toString() { - ToStringHelper helper = MoreObjects.toStringHelper(type); - if (array != null) { - helper.add("length", array.length) - .add("hash", Arrays.hashCode(array)); - } else { - helper.addValue(array); - } - return helper.toString(); - } -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/misc/package-info.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/misc/package-info.java deleted file mode 100644 index 4a3a245d5c..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/misc/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2019-present Open Networking Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Miscellaneous utilities. - */ -package io.atomix.utils.misc; diff --git a/third-party/atomix/utils/src/test/java/io/atomix/utils/ArraySizeHashPrinterTest.java b/third-party/atomix/utils/src/test/java/io/atomix/utils/ArraySizeHashPrinterTest.java deleted file mode 100644 index 404a97e379..0000000000 --- a/third-party/atomix/utils/src/test/java/io/atomix/utils/ArraySizeHashPrinterTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017-present Open Networking Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.atomix.utils; - -import io.atomix.utils.misc.ArraySizeHashPrinter; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Array size hash printer test. - */ -public class ArraySizeHashPrinterTest { - @Test - public void testArraySizeHashPrinter() throws Exception { - ArraySizeHashPrinter printer = ArraySizeHashPrinter.of(new byte[]{1, 2, 3}); - assertEquals("byte[]{length=3, hash=30817}", printer.toString()); - } -} -- 2.36.6