This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch remove_unused_code
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git

commit f59e7d41abfefd03c7e54205f5e131fb160519ca
Author: Lee Rhodes <[email protected]>
AuthorDate: Thu Aug 24 14:32:28 2023 -0700

    Remove unused code.
    
    After converting uses of FileOutputStream to its NIO equivalent, we can
    remove some unnecessary code and test methods.
---
 .../java/org/apache/datasketches/common/Util.java  | 60 ----------------------
 .../org/apache/datasketches/common/UtilTest.java   | 32 ------------
 .../apache/datasketches/cpc/CpcCBinariesTest.java  | 42 +++++++--------
 .../org/apache/datasketches/tuple/TestUtil.java    | 59 ---------------------
 4 files changed, 21 insertions(+), 172 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/common/Util.java 
b/src/main/java/org/apache/datasketches/common/Util.java
index 323f6929..758ee7ca 100644
--- a/src/main/java/org/apache/datasketches/common/Util.java
+++ b/src/main/java/org/apache/datasketches/common/Util.java
@@ -25,15 +25,7 @@ import static java.lang.Math.log;
 import static java.lang.Math.pow;
 import static java.lang.Math.round;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Comparator;
-import java.util.Objects;
 
 /**
  * Common utility functions.
@@ -752,58 +744,6 @@ public final class Util {
     return (n & 1L) == 1L;
   }
 
-  //Get Resources
-
-  /**
-   * Gets the absolute path of the given resource file's shortName.
-   *
-   * <p>Note that the ClassLoader.getResource(shortName) returns a URL,
-   * which can have special characters, e.g., "%20" for spaces. This method
-   * obtains the URL, converts it to a URI, then does a uri.getPath(), which
-   * decodes any special characters in the URI path. This is required to make
-   * obtaining resources operating-system independent.</p>
-   *
-   * @param shortFileName the last name in the pathname's name sequence.
-   * @return the absolute path of the given resource file's shortName.
-   */
-  public static String getResourcePath(final String shortFileName) {
-    Objects.requireNonNull(shortFileName, "input parameter " + shortFileName + 
" cannot be null.");
-    try {
-      final URL url = Util.class.getClassLoader().getResource(shortFileName);
-      Objects.requireNonNull(url, "resource " + shortFileName + " could not be 
acquired.");
-      final URI uri = url.toURI();
-      //decodes any special characters
-      final String path = uri.isAbsolute() ? 
Paths.get(uri).toAbsolutePath().toString() : uri.getPath();
-      return path;
-    } catch (final URISyntaxException e) {
-      throw new SketchesArgumentException("Cannot find resource: " + 
shortFileName + LS + e);
-    }
-  }
-
-  /**
-   * Gets the file defined by the given resource file's shortFileName.
-   * @param shortFileName the last name in the pathname's name sequence.
-   * @return the file defined by the given resource file's shortFileName.
-   */
-  public static File getResourceFile(final String shortFileName) {
-    return new File(getResourcePath(shortFileName));
-  }
-
-  /**
-   * Returns a byte array of the contents of the file defined by the given 
resource file's
-   * shortFileName.
-   * @param shortFileName the last name in the pathname's name sequence.
-   * @return a byte array of the contents of the file defined by the given 
resource file's
-   * shortFileName.
-   */
-  public static byte[] getResourceBytes(final String shortFileName) {
-    try {
-      return Files.readAllBytes(Paths.get(getResourcePath(shortFileName)));
-    } catch (final IOException e) {
-      throw new SketchesArgumentException("Cannot read resource: " + 
shortFileName + LS + e);
-    }
-  }
-
   /**
    * Computes the number of decimal digits of the number n
    * @param n the given number
diff --git a/src/test/java/org/apache/datasketches/common/UtilTest.java 
b/src/test/java/org/apache/datasketches/common/UtilTest.java
index 092457bf..a6867168 100644
--- a/src/test/java/org/apache/datasketches/common/UtilTest.java
+++ b/src/test/java/org/apache/datasketches/common/UtilTest.java
@@ -37,8 +37,6 @@ import static 
org.apache.datasketches.common.Util.exactLog2OfInt;
 import static org.apache.datasketches.common.Util.exactLog2OfLong;
 import static org.apache.datasketches.common.Util.floorPowerBaseOfDouble;
 import static org.apache.datasketches.common.Util.floorPowerOf2;
-import static org.apache.datasketches.common.Util.getResourceBytes;
-import static org.apache.datasketches.common.Util.getResourceFile;
 import static org.apache.datasketches.common.Util.intToBytes;
 import static org.apache.datasketches.common.Util.invPow2;
 import static org.apache.datasketches.common.Util.isEven;
@@ -64,8 +62,6 @@ import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
-import java.io.File;
-
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -455,34 +451,6 @@ public class UtilTest {
     assertEquals(s, "00000000090a0b0c");
   }
 
-  //Resources
-
-  @Test
-  public void resourcefileExists() {
-    final String shortFileName = "cpc-empty.sk";
-    final File file = getResourceFile(shortFileName);
-    assertTrue(file.exists());
-  }
-
-  @Test(expectedExceptions = NullPointerException.class)
-  public void resourceFileNotFound() {
-    final String shortFileName = "cpc-empty.sk";
-    getResourceFile(shortFileName + "123");
-  }
-
-  @Test
-  public void resourceBytesCorrect() {
-    final String shortFileName = "cpc-empty.sk";
-    final byte[] bytes = getResourceBytes(shortFileName);
-    assertTrue(bytes.length == 8);
-  }
-
-  @Test(expectedExceptions = NullPointerException.class)
-  public void resourceBytesFileNotFound() {
-    final String shortFileName = "cpc-empty.sk";
-    getResourceBytes(shortFileName + "123");
-  }
-
   @Test
   public void printlnTest() {
     println("PRINTING: " + this.getClass().getName());
diff --git a/src/test/java/org/apache/datasketches/cpc/CpcCBinariesTest.java 
b/src/test/java/org/apache/datasketches/cpc/CpcCBinariesTest.java
index 01743e49..46a6e857 100644
--- a/src/test/java/org/apache/datasketches/cpc/CpcCBinariesTest.java
+++ b/src/test/java/org/apache/datasketches/cpc/CpcCBinariesTest.java
@@ -25,7 +25,7 @@ import static org.apache.datasketches.common.TestUtil.cppPath;
 import static org.apache.datasketches.common.TestUtil.javaPath;
 import static org.testng.Assert.assertEquals;
 
-import java.io.File;
+import java.nio.file.Path;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.nio.file.Files;
@@ -44,8 +44,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkEmptyBin() {
-    final File file = cppPath.resolve("cpc-empty.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-empty.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory wmem = mh.get();
       println(PreambleUtil.toString(wmem, true));
       final CpcSketch sk = CpcSketch.heapify(wmem);
@@ -57,8 +57,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkSparseBin() {
-    final File file = cppPath.resolve("cpc-sparse.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-sparse.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       println("CPP GENERATED SKETCH FROM BINARY FILE LgK=11, U0 to U99");
       println("PreambleUtil.toString(mem, true)" + LS);
@@ -82,8 +82,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkHybridBin() {
-    final File file = cppPath.resolve("cpc-hybrid.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-hybrid.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       println("CPP GENERATED SKETCH FROM BINARY FILE LgK=11, U0 to U199");
       println("PreambleUtil.toString(mem, true)" + LS);
@@ -107,8 +107,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkPinnedBin() {
-    final File file = cppPath.resolve("cpc-pinned.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-pinned.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       println("CPP GENERATED SKETCH FROM BINARY FILE LgK=11, U0 to U1999");
       println("PreambleUtil.toString(mem, true)" + LS);
@@ -132,8 +132,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkSlidingBin() {
-    final File file = cppPath.resolve("cpc-sliding.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-sliding.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       println("CPP GENERATED SKETCH FROM BINARY FILE LgK=11, U0 to U19999");
       println("PreambleUtil.toString(mem, true)" + LS);
@@ -159,8 +159,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkEmptyImages() {
-    final File file = cppPath.resolve("cpc-empty.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-empty.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       final int cap = (int) mem.getCapacity();
       final byte[] memByteArr = new byte[cap];
@@ -178,8 +178,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkSparseImages() {
-    final File file = cppPath.resolve("cpc-sparse.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-sparse.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       final int cap = (int) mem.getCapacity();
       final byte[] memByteArr = new byte[cap];
@@ -198,8 +198,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkHybridImages() {
-    final File file = cppPath.resolve("cpc-hybrid.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-hybrid.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       final int cap = (int) mem.getCapacity();
       final byte[] memByteArr = new byte[cap];
@@ -218,8 +218,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkPinnedImages() {
-    final File file = cppPath.resolve("cpc-pinned.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-pinned.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       final int cap = (int) mem.getCapacity();
       final byte[] cppMemByteArr = new byte[cap];
@@ -238,8 +238,8 @@ public class CpcCBinariesTest {
 
   @Test(groups = {CHECK_CPP_FILES})
   public void checkSlidingImages() {
-    final File file = cppPath.resolve("cpc-sliding.sk").toFile();
-    try (MapHandle mh = Memory.map(file)) {
+    final Path path = cppPath.resolve("cpc-sliding.sk");
+    try (MapHandle mh = Memory.map(path.toFile())) {
       final Memory mem = mh.get();
       final int cap = (int) mem.getCapacity();
       final byte[] memByteArr = new byte[cap];
diff --git a/src/test/java/org/apache/datasketches/tuple/TestUtil.java 
b/src/test/java/org/apache/datasketches/tuple/TestUtil.java
deleted file mode 100644
index 37809624..00000000
--- a/src/test/java/org/apache/datasketches/tuple/TestUtil.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 org.apache.datasketches.tuple;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class TestUtil {
-  public static List<Double> asList(final double[] array) {
-    final List<Double> list = new ArrayList<>(array.length);
-    for (int i = 0; i < array.length; i++) {
-      list.add(array[i]);
-    }
-    return list;
-  }
-
-  public static List<Float> asList(final float[] array) {
-    final List<Float> list = new ArrayList<>(array.length);
-    for (int i = 0; i < array.length; i++) {
-      list.add(array[i]);
-    }
-    return list;
-  }
-
-  public static List<Long> asList(final long[] array) {
-    final List<Long> list = new ArrayList<>(array.length);
-    for (int i = 0; i < array.length; i++) {
-      list.add(array[i]);
-    }
-    return list;
-  }
-
-  public static void writeBytesToFile(final byte[] bytes, final String 
fileName) throws IOException {
-    try (FileOutputStream out = new FileOutputStream(new File(fileName))) {
-      out.write(bytes);
-    }
-  }
-
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to