Remove atomix.utils.misc 92/104692/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Mar 2023 08:27:01 +0000 (09:27 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Mar 2023 08:27:58 +0000 (09:27 +0100)
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 <robert.varga@pantheon.tech>
third-party/atomix/storage/src/test/java/io/atomix/storage/journal/TestEntry.java
third-party/atomix/utils/src/main/java/io/atomix/utils/misc/ArraySizeHashPrinter.java [deleted file]
third-party/atomix/utils/src/main/java/io/atomix/utils/misc/package-info.java [deleted file]
third-party/atomix/utils/src/test/java/io/atomix/utils/ArraySizeHashPrinterTest.java [deleted file]

index dfbc004318c528a7137ccb25d0b43d813ab2348c..9c3f92974a5171ade8d096d7fc4d32109aa02e60 100644 (file)
@@ -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 (file)
index 0bf5d0d..0000000
+++ /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 (file)
index 4a3a245..0000000
+++ /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 (file)
index 404a97e..0000000
+++ /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());
-  }
-}