You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2026/05/11 23:07:47 UTC
(datasketches-memory) branch update_7.0.X updated: Update working 7.0.X
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch update_7.0.X
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
The following commit(s) were added to refs/heads/update_7.0.X by this push:
new 6a262987 Update working 7.0.X
6a262987 is described below
commit 6a2629870c473dff5395bd4b76033c2e7668e0bf
Author: Lee Rhodes <le...@gmail.com>
AuthorDate: Mon May 11 16:07:35 2026 -0700
Update working 7.0.X
---
.../org/apache/datasketches/memory/Resource.java | 10 +-
.../datasketches/memory/internal/ResourceImpl.java | 46 ++--
.../datasketches/memory/internal/UnsafeUtil.java | 5 -
.../internal/AllocateDirectMapMemoryTest.java | 2 +-
.../AllocateDirectWritableMapMemoryTest.java | 2 +-
.../memory/internal/MemoryCloseExceptionTest.java | 25 ---
.../datasketches/memory/internal/ResourceTest.java | 38 ++--
.../datasketches/memory/internal/TestUtil.java | 242 ---------------------
.../datasketches/memory/internal/ThreadTest.java | 2 +-
.../datasketches/memory/internal/UtilTest.java | 48 +---
.../memory/internal/UtilitiesForTest.java | 122 +++++++++++
.../org/apache/datasketches/memory/Memory.java | 40 +++-
.../org/apache/datasketches/memory/Resource.java | 79 ++++++-
.../apache/datasketches/memory/WritableMemory.java | 36 ++-
.../datasketches/memory/internal/ResourceImpl.java | 56 ++---
.../datasketches/memory/internal/UnsafeUtil.java | 1 -
.../apache/datasketches/memory/internal/Util.java | 173 ---------------
.../memory/internal/CommonMemoryTest.java | 46 ----
.../memory/internal/MemoryCloseExceptionTest.java | 25 ---
.../datasketches/memory/internal/MemoryTest.java | 4 -
.../datasketches/memory/internal/ResourceTest.java | 38 ++--
.../datasketches/memory/internal/UtilTest.java | 55 +----
22 files changed, 352 insertions(+), 743 deletions(-)
diff --git a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/Resource.java b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/Resource.java
index 8b001287..49b5ad74 100644
--- a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/Resource.java
+++ b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/Resource.java
@@ -81,8 +81,6 @@ public interface Resource extends AutoCloseable {
*/
void setMemoryRequestServer(MemoryRequestServer memReqSvr);
- //***
-
/**
* Closes this resource if this can be closed via <em>AutoCloseable</em>.
* If this operation completes without exceptions, this resource will be marked as <em>not alive</em>,
@@ -262,7 +260,7 @@ public interface Resource extends AutoCloseable {
boolean isLoaded();
/**
- * If true, this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API.
+ * If {@code true}, this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API.
* The Memory API is the principal API for this Memory Component.
* It provides a rich variety of direct manipulations of four types of resources:
* On-heap memory, off-heap memory, memory-mapped files, and ByteBuffers.
@@ -272,14 +270,14 @@ public interface Resource extends AutoCloseable {
* similar to that in <i>ByteBuffer</i>. The positional API is a convenience when iterating over structured
* arrays, or buffering input or output streams (thus the name).</p>
*
- * @return true if this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API,
+ * @return {@code true} if this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API,
* otherwise this is a <i>Buffer</i> or <i>WritableBuffer</i> instance, which provides the Buffer API.
*/
boolean isMemory();
/**
- * Returns true if the backing resource is a memory-mapped file.
- * @return true if the backing resource is a memory-mapped file.
+ * Returns {@code true} if the backing resource is a memory-mapped file.
+ * @return {@code true} if the backing resource is a memory-mapped file.
*/
boolean isMapped();
diff --git a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
index b970476a..0b6f3e81 100644
--- a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
+++ b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
@@ -37,8 +37,8 @@ import org.apache.datasketches.memory.Resource;
*/
//@SuppressWarnings("restriction")
public abstract class ResourceImpl implements Resource {
- static final String JDK;
- static final int JDK_MAJOR; //8, 11, 17, etc
+ public static final int JDK_MAJOR; //11, 17, 21
+ public static final String unsupportedJDK;
//Used to convert "type" to bytes: bytes = longs << LONG_SHIFT
static final int BOOLEAN_SHIFT = 0;
@@ -84,9 +84,9 @@ public abstract class ResourceImpl implements Resource {
static {
final String jdkVer = System.getProperty("java.version");
- final int[] p = parseJavaVersion(jdkVer);
- JDK = p[0] + "." + p[1];
- JDK_MAJOR = (p[0] == 1) ? p[1] : p[0];
+ JDK_MAJOR = parseJavaVersion(jdkVer);
+ checkJavaVersion(JDK_MAJOR);
+ unsupportedJDK = "Not supported for this JDK " + JDK_MAJOR + ". Please use JDK 11.";
}
//set by the leaf nodes
@@ -142,18 +142,13 @@ public abstract class ResourceImpl implements Resource {
}
/**
- * Checks the runtime Java Version string. Note that Java 17 and 21 is allowed only because some clients do not use the
- * WritableMemory.allocateDirect(..) and related functions, which will not work with Java versions >= 14.
- * The on-heap functions may work with 17 and 21, nonetheless, versions > Java 11 are not officially supported.
- * Caveat emptor.
- * @param jdkVer the <i>System.getProperty("java.version")</i> string of the form "p0.p1.X"
- * @param p0 The first number group
- * @param p1 The second number group
+ * Checks the runtime Java Version string.
+ * @param jdkMajor the first number from the <i>System.getProperty("java.version")</i> string."
*/
- static void checkJavaVersion(final String jdkVer, final int p0, final int p1 ) {
- final boolean ok = ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11) || (p0 == 17 || (p0 == 21) || (p0 == 25));
+ static void checkJavaVersion(final int jdkMajor) {
+ final boolean ok = jdkMajor == 11;
if (!ok) { throw new IllegalArgumentException(
- "Unsupported JDK Major Version. It must be one of 1.8, 8, 11, 17, 21, 25: " + jdkVer);
+ "Unsupported JDK Major Version. It must be 11: " + jdkMajor);
}
}
@@ -373,23 +368,22 @@ public abstract class ResourceImpl implements Resource {
}
/**
- * Returns first two number groups of the java version string.
- * @param jdkVer the java version string from System.getProperty("java.version").
- * @return first two number groups of the java version string.
+ * Returns the JDK major version.
+ * @return the JDK major version.
* @throws IllegalArgumentException for an improper Java version string.
*/
- static int[] parseJavaVersion(final String jdkVer) {
- final int p0, p1;
+ static final int parseJavaVersion(final String jdkVer) {
+ final int jdkMajor;
try {
String[] parts = jdkVer.trim().split("^0-9\\.");//grab only number groups and "."
parts = parts[0].split("\\."); //split out the number groups
- p0 = Integer.parseInt(parts[0]); //the first number group
- p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; //2nd number group, or 0
+ final int p0 = Integer.parseInt(parts[0]); //the first number group
+ final int p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; //2nd number group, or 0
+ jdkMajor = (p0 == 1) ? p1 : p0;
} catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) {
- throw new IllegalArgumentException("Improper Java -version string: " + jdkVer + LS + e);
+ throw new IllegalArgumentException("Improper Java version string: " + jdkVer + LS + e);
}
- checkJavaVersion(jdkVer, p0, p1);
- return new int[] {p0, p1};
+ return jdkMajor;
}
//REACHABILITY FENCE
@@ -450,7 +444,7 @@ public abstract class ResourceImpl implements Resource {
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
sb.append("Type Byte Order : ").append(state.getTypeByteOrder().toString()).append(LS);
sb.append("Native Byte Order : ").append(ByteOrder.nativeOrder().toString()).append(LS);
- sb.append("JDK Runtime Version : ").append(JDK).append(LS);
+ sb.append("JDK Runtime Version : ").append(JDK_MAJOR).append(LS);
//Data detail
if (withData) {
sb.append("Data, bytes : 0 1 2 3 4 5 6 7");
diff --git a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
index 8c4d1fa9..1e4e04ac 100644
--- a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
+++ b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
@@ -86,11 +86,6 @@ public final class UnsafeUtil {
unsafeConstructor.setAccessible(true);
unsafe = unsafeConstructor.newInstance();
- // Alternative, but may not work across different JVMs.
- // Field field = Unsafe.class.getDeclaredField("theUnsafe");
- // field.setAccessible(true);
- // unsafe = (Unsafe) field.get(null);
-
} catch (final InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 38617f05..4a67b946 100644
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -39,7 +39,7 @@ public class AllocateDirectMapMemoryTest {
@BeforeClass
public void setReadOnly() {
- gettyFile = TestUtil.setResourceReadOnly("GettysburgAddress.txt");
+ gettyFile = UtilitiesForTest.setResourceReadOnly("GettysburgAddress.txt");
gettySize = gettyFile.length();
}
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
index 4ce59464..59807b6d 100644
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
+++ b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
@@ -43,7 +43,7 @@ public class AllocateDirectWritableMapMemoryTest {
@BeforeClass
public void setReadOnly() {
- gettyFile = TestUtil.setResourceReadOnly("GettysburgAddress.txt");
+ gettyFile = UtilitiesForTest.setResourceReadOnly("GettysburgAddress.txt");
}
@Test
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/MemoryCloseExceptionTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/MemoryCloseExceptionTest.java
deleted file mode 100644
index b4d5980b..00000000
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/MemoryCloseExceptionTest.java
+++ /dev/null
@@ -1,25 +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.memory.internal;
-
-public class MemoryCloseExceptionTest {
-
-}
-
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java
index e9b498c1..b72d8bf7 100644
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java
+++ b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java
@@ -125,61 +125,57 @@ public class ResourceTest {
@Test
public void checkJdkString() {
String jdkVer;
- int[] p = new int[2];
- String[] good1_Strings = {"1.8.0_121", "8", "11", "17", "21"};
+ int jdkMaj;
+ String[] good1_Strings = {"11.1.21_abc", "11", "11.0._abc"};
int len = good1_Strings.length;
for (int i = 0; i < len; i++) {
jdkVer = good1_Strings[i];
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
- int jdkMajor = (p[0] == 1) ? p[1] : p[0]; //model the actual JDK_MAJOR
- if (p[0] == 1) { assertTrue(jdkMajor == p[1]); }
- if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); }
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj);
}
try {
- jdkVer = "14.0.4";
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
+ jdkVer = "14.0.4"; //invalid string
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
- jdkVer = "1.7.0_80";
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
+ jdkVer = "1.7.0_80"; //invalid string
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
- jdkVer = "1.6.0_65";
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
+ jdkVer = "1.6.0_65"; //invalid string
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = "b"; //invalid string
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = ""; //invalid string
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
}
-
/********************/
@Test
public void printlnTest() {
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/TestUtil.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/TestUtil.java
deleted file mode 100644
index 002b7ea8..00000000
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/TestUtil.java
+++ /dev/null
@@ -1,242 +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.memory.internal;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
-import java.util.Objects;
-import java.util.Random;
-
-import org.apache.datasketches.memory.Memory;
-
-public class TestUtil {
-
- /**
- * Searches a range of the specified array of longs for the specified value using the binary
- * search algorithm. The range must be sorted method) prior to making this call.
- * If it is not sorted, the results are undefined. If the range contains
- * multiple elements with the specified value, there is no guarantee which one will be found.
- * @param mem the Memory to be searched
- * @param fromLongIndex the index of the first element (inclusive) to be searched
- * @param toLongIndex the index of the last element (exclusive) to be searched
- * @param key the value to be searched for
- * @return index of the search key, if it is contained in the array within the specified range;
- * otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which
- * the key would be inserted into the array: the index of the first element in the range greater
- * than the key, or toIndex if all elements in the range are less than the specified key.
- * Note that this guarantees that the return value will be ≥ 0 if and only if the key is found.
- */
- public static long binarySearchLongs(final Memory mem, final long fromLongIndex,
- final long toLongIndex, final long key) {
- ResourceImpl.checkBounds(fromLongIndex << 3, (toLongIndex - fromLongIndex) << 3, mem.getCapacity());
- long low = fromLongIndex;
- long high = toLongIndex - 1L;
-
- while (low <= high) {
- final long mid = (low + high) >>> 1;
- final long midVal = mem.getLong(mid << 3);
-
- if (midVal < key) { low = mid + 1; }
- else if (midVal > key) { high = mid - 1; }
- else { return mid; } // key found
- }
- return -(low + 1); // key not found.
- }
-
- /**
- * Creates random valid Character Code Points (as integers). By definition, valid CodePoints
- * are integers in the range 0 to Character.MAX_CODE_POINT, and exclude the surrogate values.
- * This is used in unit testing and characterization testing of the UTF8 class. Because the
- * characterization tools are in a separate package, this must remain public.
- *
- * @author Lee Rhodes
- */
- public static class RandomCodePoints {
- private Random rand; //
- private static final int ALL_CP = Character.MAX_CODE_POINT + 1;
- private static final int MIN_SUR = Character.MIN_SURROGATE;
- private static final int MAX_SUR = Character.MAX_SURROGATE;
-
- /**
- * @param deterministic if true, configure java.util.Random with a fixed seed.
- */
- public RandomCodePoints(final boolean deterministic) {
- rand = deterministic ? new Random(0) : new Random();
- }
-
- /**
- * Fills the given array with random valid Code Points from 0, inclusive, to
- * <i>Character.MAX_CODE_POINT</i>, inclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @param cpArr the array to fill
- */
- public final void fillCodePointArray(final int[] cpArr) {
- fillCodePointArray(cpArr, 0, ALL_CP);
- }
-
- /**
- * Fills the given array with random valid Code Points from <i>startCP</i>, inclusive, to
- * <i>endCP</i>, exclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @param cpArr the array to fill
- * @param startCP the starting Code Point, included.
- * @param endCP the ending Code Point, excluded. This value cannot exceed 0x110000.
- */
- public final void fillCodePointArray(final int[] cpArr, final int startCP, final int endCP) {
- final int arrLen = cpArr.length;
- final int numCP = Math.min(endCP, 0X110000) - Math.min(0, startCP);
- int idx = 0;
- while (idx < arrLen) {
- final int cp = startCP + rand.nextInt(numCP);
- if ((cp >= MIN_SUR) && (cp <= MAX_SUR)) {
- continue;
- }
- cpArr[idx++] = cp;
- }
- }
-
- /**
- * Return a single valid random Code Point from 0, inclusive, to
- * <i>Character.MAX_CODE_POINT</i>, inclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @return a single valid random CodePoint.
- */
- public final int getCodePoint() {
- return getCodePoint(0, ALL_CP);
- }
-
- /**
- * Return a single valid random Code Point from <i>startCP</i>, inclusive, to
- * <i>endCP</i>, exclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @param startCP the starting Code Point, included.
- * @param endCP the ending Code Point, excluded. This value cannot exceed 0x110000.
- * @return a single valid random CodePoint.
- */
- public final int getCodePoint(final int startCP, final int endCP) {
- final int numCP = Math.min(endCP, 0X110000) - Math.min(0, startCP);
- while (true) {
- final int cp = startCP + rand.nextInt(numCP);
- if ((cp < MIN_SUR) || (cp > MAX_SUR)) {
- return cp;
- }
- }
- }
- } //End class RandomCodePoints
-
- /**
- * Windows, POSIX, and JAR friendly, returns a byte array of the contents of the file defined by the given
- * resourceName. This is only used in test.
- * If the resource is in a JAR it will be copied into the File System as a temporary file first.
- *
- * @param resourceName the short name or the full path name.
- * @return a byte array of the contents of the file defined by the given resourceName.
- */
- public static byte[] getResourceBytes(final String resourceName) {
- Objects.requireNonNull(resourceName, "Given resourceName must not be null");
-
- String normalizedName = resourceName.replace('\\', '/');
- if (normalizedName.startsWith("/")) {
- normalizedName = normalizedName.substring(1);
- }
-
- final ClassLoader loader = Util.class.getClassLoader();
- try (InputStream in = loader.getResourceAsStream(normalizedName)) {
- if (in == null) {
- throw new IllegalArgumentException("Resource not found: " + normalizedName);
- }
- return in.readAllBytes();
- } catch (final IOException e) {
- throw new IllegalArgumentException("Cannot read resource: " + normalizedName + Util.LS + e);
- }
- }
-
- /**
- * Windows, POSIX, and JAR friendly get Resource File. This is only used in test.
- * If the resource is in a JAR it will be copied into the File System as a temporary file first.
- * @param resourceName the simple file name or full path name.
- * Any back-slashes will be converted to forward slashes and a leading forward slash will be removed.
- * No other special characters allowed.
- * @return a File System File
- */
- public static File getResourceFile(final String resourceName) {
- Objects.requireNonNull(resourceName, "Given resourceName must not be null");
- if (resourceName.isEmpty()) { throw new IllegalArgumentException("Given resourceName must not be empty"); }
- // Normalize name: ClassLoaders MUST use forward slashes even on Windows
- String normalizedName = resourceName.replace('\\', '/');
- if (normalizedName.startsWith("/")) { normalizedName = normalizedName.substring(1); }
-
- final ClassLoader loader = Util.class.getClassLoader();
- final URL url = loader.getResource(normalizedName);
- if (url == null) { throw new IllegalArgumentException("Resource not found: " + normalizedName); }
-
- // If it's a real file, return it directly
- if ("file".equals(url.getProtocol())) {
- try {
- final URI uri = url.toURI();
- return new File(uri); }
- catch (final URISyntaxException e) { return new File(url.getPath()); }
- }
-
- // If it's in a JAR, we must extract it for Memory.map() to work
- // We use a prefix that won't collide with Windows reserved names
- final File tempFile;
- try { tempFile = File.createTempFile("datasketches-", ".bin"); }
- catch (final IOException e1) { throw new IllegalArgumentException(e1); }
- tempFile.deleteOnExit();
-
- try (InputStream in = loader.getResourceAsStream(normalizedName)) {
- if (in == null) { throw new IllegalArgumentException("Could not open stream for " + normalizedName); }
-
- // Use REPLACE_EXISTING to avoid "File Already Exists" errors on Windows retries
- Files.copy(in, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
- } catch (final IOException e) { throw new IllegalArgumentException(e); }
-
- // Final Windows Fix: Ensure the file is actually writable if you need to setReadOnly later
- //tempFile.setWritable(true);
-
- return tempFile;
- }
-
- /**
- * Windows, POSIX, and JAR friendly, checks if the given resourceName exists and sets it to Read-Only.
- * This is only used in test.
- * If the resource is in a JAR it will be copied into the File System as a temporary file first.
- * This will not work if the file is currently memory-mapped.
- * If it is memory-mapped, close the mapping first.
- * @param resourceName the given resource.
- * @return the read only file.
- */
- public static File setResourceReadOnly(final String resourceName) {
- final File file = getResourceFile(resourceName);
- file.setReadOnly();
- return file;
- }
-}
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java
index eb8b4573..abd74357 100644
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java
+++ b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java
@@ -39,7 +39,7 @@ public class ThreadTest {
@BeforeClass
public void prepareFileAndMemory() throws IOException {
- gettyFile = TestUtil.setResourceReadOnly("GettysburgAddress.txt");
+ gettyFile = UtilitiesForTest.setResourceReadOnly("GettysburgAddress.txt");
}
void initMap() throws IOException {
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
index 8cdf2131..549f3739 100644
--- a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
+++ b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
@@ -35,7 +35,6 @@ import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermissions;
import org.apache.datasketches.memory.MemoryBoundsException;
-import org.apache.datasketches.memory.WritableMemory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -46,24 +45,9 @@ public class UtilTest {
@BeforeClass
public void setReadOnly() {
- gettyFile = TestUtil.setResourceReadOnly("GettysburgAddress.txt");
+ gettyFile = UtilitiesForTest.setResourceReadOnly("GettysburgAddress.txt");
gettySize = gettyFile.length();
}
-
- //Binary Search
- @Test
- public void checkBinarySearch() {
- int k = 1024; //longs
- WritableMemory wMem = WritableMemory.allocate(k << 3); //1024 longs
- for (int i = 0; i < k; i++) { wMem.putLong(i << 3, i); }
- long idx = TestUtil.binarySearchLongs(wMem, 0, k - 1, k / 2);
- long val = wMem.getLong(idx << 3);
- assertEquals(idx, k / 2);
- assertEquals(val, k / 2);
-
- idx = TestUtil.binarySearchLongs(wMem, 0, k - 1, k);
- assertEquals(idx, -1024);
- }
@Test(expectedExceptions = MemoryBoundsException.class)
public void checkBoundsTest() {
@@ -93,32 +77,6 @@ public class UtilTest {
}
}
- @Test
- public void checkCodePointArr() {
- final TestUtil.RandomCodePoints rvcp = new TestUtil.RandomCodePoints(true);
- final int n = 1000;
- final int[] cpArr = new int[n];
- rvcp.fillCodePointArray(cpArr);
- for (int i = 0; i < n; i++) {
- int cp = cpArr[i];
- if ((cp >= Character.MIN_SURROGATE) && (cp <= Character.MAX_SURROGATE)) {
- fail();
- }
- }
- }
-
- @Test
- public void checkCodePoint() {
- final TestUtil.RandomCodePoints rvcp = new TestUtil.RandomCodePoints(true);
- final int n = 1000;
- for (int i = 0; i < n; i++) {
- int cp = rvcp.getCodePoint();
- if ((cp >= Character.MIN_SURROGATE) && (cp <= Character.MAX_SURROGATE)) {
- fail();
- }
- }
- }
-
static final String getFileAttributes(File file) {
try {
PosixFileAttributes attrs = Files.getFileAttributeView(
@@ -144,7 +102,7 @@ public class UtilTest {
@Test
public void resourceFileNotFound() {
final String shortFileName = "GettysburgAddress.txt";
- try { TestUtil.getResourceFile(shortFileName + "123"); }
+ try { UtilitiesForTest.getResourceFile(shortFileName + "123"); }
catch (IllegalArgumentException e) { //OK
}
}
@@ -157,7 +115,7 @@ public class UtilTest {
@Test
public void resourceBytesFileNotFound() {
final String shortFileName = "GettysburgAddress.txt";
- try { TestUtil.getResourceBytes(shortFileName + "123"); }
+ try { UtilitiesForTest.getResourceBytes(shortFileName + "123"); }
catch (IllegalArgumentException e) { //OK
}
}
diff --git a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilitiesForTest.java b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilitiesForTest.java
new file mode 100644
index 00000000..ae95e74a
--- /dev/null
+++ b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilitiesForTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.memory.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Objects;
+
+public class UtilitiesForTest {
+
+ /**
+ * Windows, POSIX, and JAR friendly, returns a byte array of the contents of the file defined by the given
+ * resourceName. This is only used in test.
+ * If the resource is in a JAR it will be copied into the File System as a temporary file first.
+ *
+ * @param resourceName the short name or the full path name.
+ * @return a byte array of the contents of the file defined by the given resourceName.
+ */
+ public static byte[] getResourceBytes(final String resourceName) {
+ Objects.requireNonNull(resourceName, "Given resourceName must not be null");
+
+ String normalizedName = resourceName.replace('\\', '/');
+ if (normalizedName.startsWith("/")) {
+ normalizedName = normalizedName.substring(1);
+ }
+
+ final ClassLoader loader = Util.class.getClassLoader();
+ try (InputStream in = loader.getResourceAsStream(normalizedName)) {
+ if (in == null) {
+ throw new IllegalArgumentException("Resource not found: " + normalizedName);
+ }
+ return in.readAllBytes();
+ } catch (final IOException e) {
+ throw new IllegalArgumentException("Cannot read resource: " + normalizedName + Util.LS + e);
+ }
+ }
+
+ /**
+ * Windows, POSIX, and JAR friendly get Resource File. This is only used in test.
+ * If the resource is in a JAR it will be copied into the File System as a temporary file first.
+ * @param resourceName the simple file name or full path name.
+ * Any back-slashes will be converted to forward slashes and a leading forward slash will be removed.
+ * No other special characters allowed.
+ * @return a File System File
+ */
+ public static File getResourceFile(final String resourceName) {
+ Objects.requireNonNull(resourceName, "Given resourceName must not be null");
+ if (resourceName.isEmpty()) { throw new IllegalArgumentException("Given resourceName must not be empty"); }
+ // Normalize name: ClassLoaders MUST use forward slashes even on Windows
+ String normalizedName = resourceName.replace('\\', '/');
+ if (normalizedName.startsWith("/")) { normalizedName = normalizedName.substring(1); }
+
+ final ClassLoader loader = Util.class.getClassLoader();
+ final URL url = loader.getResource(normalizedName);
+ if (url == null) { throw new IllegalArgumentException("Resource not found: " + normalizedName); }
+
+ // If it's a real file, return it directly
+ if ("file".equals(url.getProtocol())) {
+ try {
+ final URI uri = url.toURI();
+ return new File(uri); }
+ catch (final URISyntaxException e) { return new File(url.getPath()); }
+ }
+
+ // If it's in a JAR, we must extract it for Memory.map() to work
+ // We use a prefix that won't collide with Windows reserved names
+ final File tempFile;
+ try { tempFile = File.createTempFile("datasketches-", ".bin"); }
+ catch (final IOException e1) { throw new IllegalArgumentException(e1); }
+ tempFile.deleteOnExit();
+
+ try (InputStream in = loader.getResourceAsStream(normalizedName)) {
+ if (in == null) { throw new IllegalArgumentException("Could not open stream for " + normalizedName); }
+
+ // Use REPLACE_EXISTING to avoid "File Already Exists" errors on Windows retries
+ Files.copy(in, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ } catch (final IOException e) { throw new IllegalArgumentException(e); }
+
+ // Final Windows Fix: Ensure the file is actually writable if you need to setReadOnly later
+ //tempFile.setWritable(true);
+
+ return tempFile;
+ }
+
+ /**
+ * Windows, POSIX, and JAR friendly, checks if the given resourceName exists and sets it to Read-Only.
+ * This is only used in test.
+ * If the resource is in a JAR it will be copied into the File System as a temporary file first.
+ * This will not work if the file is currently memory-mapped.
+ * If it is memory-mapped, close the mapping first.
+ * @param resourceName the given resource.
+ * @return the read only file.
+ */
+ public static File setResourceReadOnly(final String resourceName) {
+ final File file = getResourceFile(resourceName);
+ file.setReadOnly();
+ return file;
+ }
+}
diff --git a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Memory.java b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Memory.java
index ef490910..ab50e172 100644
--- a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -19,6 +19,9 @@
package org.apache.datasketches.memory;
+import static org.apache.datasketches.memory.internal.ResourceImpl.unsupportedJDK;
+
+import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -66,8 +69,41 @@ public interface Memory extends Resource {
//Duplicates make no sense here
- //No Mapping in Java 17 or 21
-
+ //MAP
+ /**
+ * NOTE: This operation is unsupported for JDKs 17 and 21.
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Maps the given file into <i>Memory</i> for read operations.</p>
+ * Calling this method is equivalent to calling
+ * {@link #map(File, long, long, ByteOrder)
+ * map(file, 0, file.length(), ByteOrder.nativeOrder())}.
+ * @param file the given file to map. It must be non-null with a non-negative length and readable.
+ * @return <i>Memory</i> for managing the mapped memory.
+ */
+ static Memory map(final File file) {
+ return map(file, 0, file.length(), ByteOrder.nativeOrder());
+ }
+
+ /**
+ * NOTE: This operation is unsupported for JDKs 17 and 21.
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Maps the specified portion of the given file into <i>Memory</i> for read operations.</p>
+ * @param file the given file to map. It must be non-null, readable and length ≥ 0.
+ * @param fileOffsetBytes the position in the given file in bytes. It must be ≥ 0.
+ * @param capacityBytes the size of the mapped memory. It must be ≥ 0.
+ * @param byteOrder the byte order to be used. It must be non-null.
+ * @return <i>Memory</i> for managing the mapped memory.
+ */
+ static Memory map(
+ final File file,
+ final long fileOffsetBytes,
+ final long capacityBytes,
+ final ByteOrder byteOrder) {
+ throw new UnsupportedOperationException(unsupportedJDK);
+ }
+
//NO ALLOCATE OFF-HEAP, makes no sense
//REGIONS
diff --git a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Resource.java b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Resource.java
index 4cb4281c..ec9bfbe3 100644
--- a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Resource.java
+++ b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/Resource.java
@@ -19,6 +19,8 @@
package org.apache.datasketches.memory;
+import static org.apache.datasketches.memory.internal.ResourceImpl.unsupportedJDK;
+
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -81,8 +83,6 @@ public interface Resource extends AutoCloseable {
*/
void setMemoryRequestServer(MemoryRequestServer memReqSvr);
- //***
-
/**
* Closes this resource if this can be closed via <em>AutoCloseable</em>.
* If this operation completes without exceptions, this resource will be marked as <em>not alive</em>,
@@ -135,6 +135,30 @@ public interface Resource extends AutoCloseable {
long thatOffsetBytes,
long lengthBytes);
+ /**
+ * NOTE: This operation is unsupported for JDKs 17 and 21.
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Forces any changes made to the contents of this memory-mapped Resource to be written to the storage
+ * device described by the configured file descriptor.</p>
+ *
+ * <p>If the file descriptor associated with this memory-mapped Resource resides on a local storage device then when
+ * this method returns, it is guaranteed that all changes made to this mapped Resource since it was created, or since
+ * this method was last invoked, will have been written to that device.</p>
+ *
+ * <p>If the file descriptor associated with this memory-mapped Resource does not reside on a local device then no
+ * such guarantee is made.</p>
+ *
+ * <p>If this memory-mapped Resource was not mapped in read/write mode
+ * ({@link java.nio.channels.FileChannel.MapMode#READ_WRITE}) then invoking this method may have no effect.
+ * In particular, this method has no effect for files mapped in read-only or private
+ * mapping modes. This method may or may not have an effect for implementation-specific mapping modes.</p>
+ *
+ */
+ default void force() {
+ throw new UnsupportedOperationException(unsupportedJDK);
+ }
+
/**
* Gets the capacity of this object in bytes
* @return the capacity of this object in bytes
@@ -216,7 +240,29 @@ public interface Resource extends AutoCloseable {
boolean isHeap();
/**
- * If true, this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API.
+ * NOTE: This operation returns {@code false} for JDKs 17 and 21..
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Tells whether or not the contents of this memory-mapped Resource is resident in physical memory.</p>
+ *
+ * <p>A return value of {@code true} implies that it is highly likely that all of the data in this memory-mapped
+ * Resource is resident in physical memory and may therefore be accessed without incurring any virtual-memory page
+ * faults or I/O operations.</p>
+ *
+ * <p>A return value of {@code false} does not necessarily imply that all of the data in this memory-mapped Resource
+ * is not resident in physical memory.</p>
+ *
+ * <p>The returned value is a hint, rather than a guarantee, because the underlying operating system may have paged
+ * out some of this Resource's data by the time that an invocation of this method returns.</p>
+ *
+ * @return true if it is likely that all of the data in this memory-mapped Resource is resident in physical memory
+ */
+ default boolean isLoaded() {
+ return false;
+ }
+
+ /**
+ * If {@code true}, this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API.
* The Memory API is the principal API for this Memory Component.
* It provides a rich variety of direct manipulations of four types of resources:
* On-heap memory, off-heap memory, memory-mapped files, and ByteBuffers.
@@ -226,16 +272,21 @@ public interface Resource extends AutoCloseable {
* similar to that in <i>ByteBuffer</i>. The positional API is a convenience when iterating over structured
* arrays, or buffering input or output streams (thus the name).</p>
*
- * @return true if this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API,
+ * @return {@code true} if this is a <i>Memory</i> or <i>WritableMemory</i> instance, which provides the Memory API,
* otherwise this is a <i>Buffer</i> or <i>WritableBuffer</i> instance, which provides the Buffer API.
*/
boolean isMemory();
/**
- * Returns true if the backing resource is a memory-mapped file.
- * @return true if the backing resource is a memory-mapped file.
+ * NOTE: This operation returns {@code false} for JDKs 17 and 21..
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Returns {@code true} if the backing resource is a memory-mapped file.</p>
+ * @return {@code true} if the backing resource is a memory-mapped file.
*/
- boolean isMapped();
+ default boolean isMapped() {
+ return false;
+ }
/**
* If true, all put and get operations will assume the non-native ByteOrder.
@@ -273,6 +324,20 @@ public interface Resource extends AutoCloseable {
*/
boolean isAlive();
+ /**
+ * NOTE: This operation is unsupported for JDKs 17 and 21.
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Loads the contents of this memory-mapped Resource into physical memory.</p>
+ *
+ * <p>This method makes a best effort to ensure that, when it returns, this contents of the memory-mapped Resource is
+ * resident in physical memory. Invoking this method may cause some number of page faults and
+ * I/O operations to occur.</p>
+ */
+ default void load() {
+ throw new UnsupportedOperationException(unsupportedJDK);
+ }
+
/**
* Returns a description of this object with an optional formatted hex string of the data
* for the specified a range. Used primarily for testing.
diff --git a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index b2628aab..4b495f46 100644
--- a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -19,8 +19,10 @@
package org.apache.datasketches.memory;
+import static org.apache.datasketches.memory.internal.ResourceImpl.unsupportedJDK;
import static org.apache.datasketches.memory.internal.Util.negativeCheck;
+import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Objects;
@@ -70,7 +72,39 @@ public interface WritableMemory extends Memory {
//Duplicates make no sense here
- //No Mapping in Java 17 or 21
+ //MAP
+ /**
+ * NOTE: This operation is unsupported for JDKs 17 and 21.
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Maps the entire given file into native-ordered WritableMemory for write operations.</p>
+ * Calling this method is equivalent to calling
+ * {@link #writableMap(File, long, long, ByteOrder) writableMap(file, 0, file.length(), ByteOrder.nativeOrder())}.
+ * @param file the given file to map. It must be non-null and writable.
+ * @return a file-mapped WritableMemory
+ */
+ static WritableMemory writableMap(final File file) {
+ return writableMap(file, 0, file.length(), ByteOrder.nativeOrder());
+ }
+
+ /**
+ * NOTE: This operation is unsupported for JDKs 17 and 21.
+ * Please use datasketches-java 9.0+, which supports JDK 25.
+ *
+ * <p>Maps the specified portion of the given file into Memory for write operations.</p>
+ * @param file the given file to map. It must be non-null and writable.
+ * @param fileOffsetBytes the position in the given file in bytes. It must be ≥ 0.
+ * @param capacityBytes the size of the mapped Memory. It must be ≥ 0.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
+ * @return a file-mapped WritableMemory.
+ */
+ static WritableMemory writableMap(
+ final File file,
+ final long fileOffsetBytes,
+ final long capacityBytes,
+ final ByteOrder byteOrder) {
+ throw new UnsupportedOperationException(unsupportedJDK);
+ }
//ALLOCATE OFF-HEAP
diff --git a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
index cccb0e75..eedeb274 100644
--- a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
+++ b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
@@ -37,8 +37,8 @@ import org.apache.datasketches.memory.Resource;
*/
//@SuppressWarnings("restriction")
public abstract class ResourceImpl implements Resource {
- static final String JDK;
- static final int JDK_MAJOR; //8, 11, 17, etc
+ public static final int JDK_MAJOR; //11, 17, 21
+ public static final String unsupportedJDK;
//Used to convert "type" to bytes: bytes = longs << LONG_SHIFT
static final int BOOLEAN_SHIFT = 0;
@@ -84,9 +84,9 @@ public abstract class ResourceImpl implements Resource {
static {
final String jdkVer = System.getProperty("java.version");
- final int[] p = parseJavaVersion(jdkVer);
- JDK = p[0] + "." + p[1];
- JDK_MAJOR = (p[0] == 1) ? p[1] : p[0];
+ JDK_MAJOR = parseJavaVersion(jdkVer);
+ checkJavaVersion(JDK_MAJOR);
+ unsupportedJDK = "Not supported for this JDK " + JDK_MAJOR + ". Please use JDK 17 or 21.";
}
//set by the leaf nodes
@@ -142,18 +142,13 @@ public abstract class ResourceImpl implements Resource {
}
/**
- * Checks the runtime Java Version string. Note that Java 17 and 21 is allowed only because some clients do not use the
- * WritableMemory.allocateDirect(..) and related functions, which will not work with Java versions >= 14.
- * The on-heap functions may work with 17 and 21, nonetheless, versions > Java 11 are not officially supported.
- * Caveat emptor.
- * @param jdkVer the <i>System.getProperty("java.version")</i> string of the form "p0.p1.X"
- * @param p0 The first number group
- * @param p1 The second number group
+ * Checks the runtime Java Version string.
+ * @param jdkMajor the first number from the <i>System.getProperty("java.version")</i> string."
*/
- static void checkJavaVersion(final String jdkVer, final int p0, final int p1 ) {
- final boolean ok = ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11) || (p0 == 17 || (p0 == 21) || (p0 == 25));
+ static void checkJavaVersion(final int jdkMajor) {
+ final boolean ok = ( (jdkMajor == 17) || (jdkMajor == 21) );
if (!ok) { throw new IllegalArgumentException(
- "Unsupported JDK Major Version. It must be one of 1.8, 8, 11, 17, 21, 25: " + jdkVer);
+ "Unsupported JDK Major Version. It must be either 17 or 21: " + jdkMajor);
}
}
@@ -232,11 +227,6 @@ public abstract class ResourceImpl implements Resource {
return CompareAndCopy.equals(this, thisOffsetBytes, (ResourceImpl) that, thatOffsetBytes, lengthBytes);
}
-// @Override
-// public void force() { //overridden by Map Leaves
-// throw new UnsupportedOperationException(NOT_MAPPED_FILE_RESOURCE);
-// }
-
//Overridden by ByteBuffer Leaves. Used internally and for tests.
ByteBuffer getByteBuffer() {
return null;
@@ -309,11 +299,6 @@ public abstract class ResourceImpl implements Resource {
return getUnsafeObject() != null;
}
- @Override
- public boolean isMapped() {
- return false;
- }
-
@Override
public boolean isMemory() {
return (getTypeId() & BUFFER) == 0;
@@ -363,23 +348,22 @@ public abstract class ResourceImpl implements Resource {
}
/**
- * Returns first two number groups of the java version string.
- * @param jdkVer the java version string from System.getProperty("java.version").
- * @return first two number groups of the java version string.
+ * Returns the JDK major version.
+ * @return the JDK major version.
* @throws IllegalArgumentException for an improper Java version string.
*/
- static int[] parseJavaVersion(final String jdkVer) {
- final int p0, p1;
+ static final int parseJavaVersion(final String jdkVer) {
+ final int jdkMajor;
try {
String[] parts = jdkVer.trim().split("^0-9\\.");//grab only number groups and "."
parts = parts[0].split("\\."); //split out the number groups
- p0 = Integer.parseInt(parts[0]); //the first number group
- p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; //2nd number group, or 0
+ final int p0 = Integer.parseInt(parts[0]); //the first number group
+ final int p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; //2nd number group, or 0
+ jdkMajor = (p0 == 1) ? p1 : p0;
} catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) {
- throw new IllegalArgumentException("Improper Java -version string: " + jdkVer + LS + e);
+ throw new IllegalArgumentException("Improper Java version string: " + jdkVer + LS + e);
}
- checkJavaVersion(jdkVer, p0, p1);
- return new int[] {p0, p1};
+ return jdkMajor;
}
//REACHABILITY FENCE
@@ -440,7 +424,7 @@ public abstract class ResourceImpl implements Resource {
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
sb.append("Type Byte Order : ").append(state.getTypeByteOrder().toString()).append(LS);
sb.append("Native Byte Order : ").append(ByteOrder.nativeOrder().toString()).append(LS);
- sb.append("JDK Runtime Version : ").append(JDK).append(LS);
+ sb.append("JDK Runtime Version : ").append(JDK_MAJOR).append(LS);
//Data detail
if (withData) {
sb.append("Data, bytes : 0 1 2 3 4 5 6 7");
diff --git a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
index 92520074..1e4e04ac 100644
--- a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
+++ b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java
@@ -118,7 +118,6 @@ public final class UnsafeUtil {
* @param fieldName the declared field name
* @return the field offset in bytes.
*/
- @SuppressWarnings("deprecation") //for Java 21
public static long getFieldOffset(final Class<?> c, final String fieldName) {
try {
return unsafe.objectFieldOffset(c.getDeclaredField(fieldName));
diff --git a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/Util.java b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/Util.java
index 3cf917a1..d597cfd2 100644
--- a/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/Util.java
+++ b/datasketches-memory-java21/src/main/java/org/apache/datasketches/memory/internal/Util.java
@@ -22,9 +22,6 @@ package org.apache.datasketches.memory.internal;
import static java.util.Arrays.fill;
import java.nio.ByteOrder;
-import java.util.Random;
-
-import org.apache.datasketches.memory.Memory;
/**
* @author Lee Rhodes
@@ -82,38 +79,6 @@ public final class Util {
return ByteOrder.nativeOrder() == byteOrder;
}
- /**
- * Searches a range of the specified array of longs for the specified value using the binary
- * search algorithm. The range must be sorted method) prior to making this call.
- * If it is not sorted, the results are undefined. If the range contains
- * multiple elements with the specified value, there is no guarantee which one will be found.
- * @param mem the Memory to be searched
- * @param fromLongIndex the index of the first element (inclusive) to be searched
- * @param toLongIndex the index of the last element (exclusive) to be searched
- * @param key the value to be searched for
- * @return index of the search key, if it is contained in the array within the specified range;
- * otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which
- * the key would be inserted into the array: the index of the first element in the range greater
- * than the key, or toIndex if all elements in the range are less than the specified key.
- * Note that this guarantees that the return value will be ≥ 0 if and only if the key is found.
- */
- public static long binarySearchLongs(final Memory mem, final long fromLongIndex,
- final long toLongIndex, final long key) {
- ResourceImpl.checkBounds(fromLongIndex << 3, (toLongIndex - fromLongIndex) << 3, mem.getCapacity());
- long low = fromLongIndex;
- long high = toLongIndex - 1L;
-
- while (low <= high) {
- final long mid = (low + high) >>> 1;
- final long midVal = mem.getLong(mid << 3);
-
- if (midVal < key) { low = mid + 1; }
- else if (midVal > key) { high = mid - 1; }
- else { return mid; } // key found
- }
- return -(low + 1); // key not found.
- }
-
/**
* Prepend the given string with zeros. If the given string is equal or greater than the given
* field length, it will be returned without modification.
@@ -146,143 +111,6 @@ public final class Util {
return s;
}
- /**
- * Return true if all the masked bits of value are zero
- * @param value the value to be tested
- * @param bitMask defines the bits of interest
- * @return true if all the masked bits of value are zero
- */
- public static final boolean isAllBitsClear(final long value, final long bitMask) {
- return (~value & bitMask) == bitMask;
- }
-
- /**
- * Return true if all the masked bits of value are one
- * @param value the value to be tested
- * @param bitMask defines the bits of interest
- * @return true if all the masked bits of value are one
- */
- public static final boolean isAllBitsSet(final long value, final long bitMask) {
- return (value & bitMask) == bitMask;
- }
-
- /**
- * Return true if any the masked bits of value are zero
- * @param value the value to be tested
- * @param bitMask defines the bits of interest
- * @return true if any the masked bits of value are zero
- */
- public static final boolean isAnyBitsClear(final long value, final long bitMask) {
- return (~value & bitMask) != 0;
- }
-
- /**
- * Return true if any the masked bits of value are one
- * @param value the value to be tested
- * @param bitMask defines the bits of interest
- * @return true if any the masked bits of value are one
- */
- public static final boolean isAnyBitsSet(final long value, final long bitMask) {
- return (value & bitMask) != 0;
- }
-
- /**
- * Creates random valid Character Code Points (as integers). By definition, valid CodePoints
- * are integers in the range 0 to Character.MAX_CODE_POINT, and exclude the surrogate values.
- * This is used in unit testing and characterization testing of the UTF8 class. Because the
- * characterization tools are in a separate package, this must remain public.
- *
- * @author Lee Rhodes
- */
- public static class RandomCodePoints {
- private Random rand; //
- private static final int ALL_CP = Character.MAX_CODE_POINT + 1;
- private static final int MIN_SUR = Character.MIN_SURROGATE;
- private static final int MAX_SUR = Character.MAX_SURROGATE;
-
- /**
- * @param deterministic if true, configure java.util.Random with a fixed seed.
- */
- public RandomCodePoints(final boolean deterministic) {
- rand = deterministic ? new Random(0) : new Random();
- }
-
- /**
- * Fills the given array with random valid Code Points from 0, inclusive, to
- * <i>Character.MAX_CODE_POINT</i>, inclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @param cpArr the array to fill
- */
- public final void fillCodePointArray(final int[] cpArr) {
- fillCodePointArray(cpArr, 0, ALL_CP);
- }
-
- /**
- * Fills the given array with random valid Code Points from <i>startCP</i>, inclusive, to
- * <i>endCP</i>, exclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @param cpArr the array to fill
- * @param startCP the starting Code Point, included.
- * @param endCP the ending Code Point, excluded. This value cannot exceed 0x110000.
- */
- public final void fillCodePointArray(final int[] cpArr, final int startCP, final int endCP) {
- final int arrLen = cpArr.length;
- final int numCP = Math.min(endCP, 0X110000) - Math.min(0, startCP);
- int idx = 0;
- while (idx < arrLen) {
- final int cp = startCP + rand.nextInt(numCP);
- if ((cp >= MIN_SUR) && (cp <= MAX_SUR)) {
- continue;
- }
- cpArr[idx++] = cp;
- }
- }
-
- /**
- * Return a single valid random Code Point from 0, inclusive, to
- * <i>Character.MAX_CODE_POINT</i>, inclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @return a single valid random CodePoint.
- */
- public final int getCodePoint() {
- return getCodePoint(0, ALL_CP);
- }
-
- /**
- * Return a single valid random Code Point from <i>startCP</i>, inclusive, to
- * <i>endCP</i>, exclusive.
- * The surrogate range, which is from <i>Character.MIN_SURROGATE</i>, inclusive, to
- * <i>Character.MAX_SURROGATE</i>, inclusive, is always <u>excluded</u>.
- * @param startCP the starting Code Point, included.
- * @param endCP the ending Code Point, excluded. This value cannot exceed 0x110000.
- * @return a single valid random CodePoint.
- */
- public final int getCodePoint(final int startCP, final int endCP) {
- final int numCP = Math.min(endCP, 0X110000) - Math.min(0, startCP);
- while (true) {
- final int cp = startCP + rand.nextInt(numCP);
- if ((cp < MIN_SUR) || (cp > MAX_SUR)) {
- return cp;
- }
- }
- }
- } //End class RandomCodePoints
-
- /**
- * Checks if given value is ≤ zero.
- * @param value the given value
- * @param arg a meaningful name of the actual argument.
- * @throws IllegalArgumentException if value is ≤ 0.
- */
- public static final void zeroCheck(final long value, final String arg) {
- if (value <= 0) {
- throw new IllegalArgumentException("The argument '" + arg + "' may not be negative or zero.");
- }
- }
-
/**
* Checks if given value is < zero.
* @param value the given value
@@ -294,5 +122,4 @@ public final class Util {
throw new IllegalArgumentException("The argument '" + arg + "' may not be negative.");
}
}
-
}
diff --git a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
index a1d2e7fb..776289ff 100644
--- a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
+++ b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
@@ -19,13 +19,7 @@
package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.internal.Util.isAllBitsClear;
-import static org.apache.datasketches.memory.internal.Util.isAllBitsSet;
-import static org.apache.datasketches.memory.internal.Util.isAnyBitsClear;
-import static org.apache.datasketches.memory.internal.Util.isAnyBitsSet;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
import org.apache.datasketches.memory.WritableMemory;
import org.testng.annotations.Test;
@@ -222,46 +216,6 @@ public class CommonMemoryTest {
}
}
- @Test
- public void checkSetClearIsBits() throws Exception {
- int memCapacity = 8;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
- assertEquals(memCapacity, mem.getCapacity());
- mem.clear();
- setClearIsBitsTests(mem);
- }
- }
-
- public static void setClearIsBitsTests(WritableMemory mem) {
- //single bits
- for (int i = 0; i < 8; i++) {
- long bitMask = (1 << i);
- long v = mem.getByte(0) & 0XFFL;
- assertTrue(isAnyBitsClear(v, bitMask));
- mem.setBits(0, (byte) bitMask);
- v = mem.getByte(0) & 0XFFL;
- assertTrue(isAnyBitsSet(v, bitMask));
- mem.clearBits(0, (byte) bitMask);
- v = mem.getByte(0) & 0XFFL;
- assertTrue(isAnyBitsClear(v, bitMask));
- }
-
- //multiple bits
- for (int i = 0; i < 7; i++) {
- long bitMask1 = (1 << i);
- long bitMask2 = (3 << i);
- long v = mem.getByte(0) & 0XFFL;
- assertTrue(isAnyBitsClear(v, bitMask1));
- assertTrue(isAnyBitsClear(v, bitMask2));
- mem.setBits(0, (byte) bitMask1); //set one bit
- v = mem.getByte(0) & 0XFFL;
- assertTrue(isAnyBitsSet(v, bitMask2));
- assertTrue(isAnyBitsClear(v, bitMask2));
- assertFalse(isAllBitsSet(v, bitMask2));
- assertFalse(isAllBitsClear(v, bitMask2));
- }
- }
-
@Test
public void checkSetClearMemoryRegions() throws Exception {
int memCapacity = 64; //must be 64
diff --git a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryCloseExceptionTest.java b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryCloseExceptionTest.java
deleted file mode 100644
index b4d5980b..00000000
--- a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryCloseExceptionTest.java
+++ /dev/null
@@ -1,25 +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.memory.internal;
-
-public class MemoryCloseExceptionTest {
-
-}
-
diff --git a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index f3be613d..818d0e3b 100644
--- a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -17,10 +17,6 @@
* under the License.
*/
-/*
- * Note: Lincoln's Gettysburg Address is in the public domain. See LICENSE.
- */
-
package org.apache.datasketches.memory.internal;
import static org.testng.Assert.assertEquals;
diff --git a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java
index e9b498c1..dac187ff 100644
--- a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java
+++ b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java
@@ -125,61 +125,57 @@ public class ResourceTest {
@Test
public void checkJdkString() {
String jdkVer;
- int[] p = new int[2];
- String[] good1_Strings = {"1.8.0_121", "8", "11", "17", "21"};
+ int jdkMaj;
+ String[] good1_Strings = {"17.1.21_abc", "17", "21", "21.0._abc"};
int len = good1_Strings.length;
for (int i = 0; i < len; i++) {
jdkVer = good1_Strings[i];
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
- int jdkMajor = (p[0] == 1) ? p[1] : p[0]; //model the actual JDK_MAJOR
- if (p[0] == 1) { assertTrue(jdkMajor == p[1]); }
- if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); }
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj);
}
try {
- jdkVer = "14.0.4";
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
+ jdkVer = "14.0.4"; //invalid string
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
- jdkVer = "1.7.0_80";
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
+ jdkVer = "1.7.0_80"; //invalid string
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
- jdkVer = "1.6.0_65";
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
+ jdkVer = "1.6.0_65"; //invalid string
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = "b"; //invalid string
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = ""; //invalid string
- p = ResourceImpl.parseJavaVersion(jdkVer);
- ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
+ jdkMaj = ResourceImpl.parseJavaVersion(jdkVer);
+ ResourceImpl.checkJavaVersion(jdkMaj); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
}
-
/********************/
@Test
public void printlnTest() {
diff --git a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
index 890f5ac0..46db0236 100644
--- a/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
+++ b/datasketches-memory-java21/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
@@ -17,42 +17,21 @@
* under the License.
*/
-/*
- * Note: Lincoln's Gettysburg Address is in the public domain. See LICENSE.
- */
-
package org.apache.datasketches.memory.internal;
import static org.apache.datasketches.memory.internal.Util.characterPad;
import static org.apache.datasketches.memory.internal.Util.negativeCheck;
-import static org.apache.datasketches.memory.internal.Util.zeroCheck;
import static org.apache.datasketches.memory.internal.Util.zeroPad;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import org.apache.datasketches.memory.MemoryBoundsException;
-import org.apache.datasketches.memory.WritableMemory;
import org.testng.annotations.Test;
public class UtilTest {
private static final String LS = System.getProperty("line.separator");
- //Binary Search
- @Test
- public void checkBinarySearch() {
- int k = 1024; //longs
- WritableMemory wMem = WritableMemory.allocate(k << 3); //1024 longs
- for (int i = 0; i < k; i++) { wMem.putLong(i << 3, i); }
- long idx = Util.binarySearchLongs(wMem, 0, k - 1, k / 2);
- long val = wMem.getLong(idx << 3);
- assertEquals(idx, k / 2);
- assertEquals(val, k / 2);
-
- idx = Util.binarySearchLongs(wMem, 0, k - 1, k);
- assertEquals(idx, -1024);
- }
-
@Test(expectedExceptions = MemoryBoundsException.class)
public void checkBoundsTest() {
ResourceImpl.checkBounds(999, 2, 1000);
@@ -72,13 +51,7 @@ public class UtilTest {
}
@Test
- public void checkZeroNegativeChecks() {
- try {
- zeroCheck(0, "Test Long");
- fail();
- } catch (IllegalArgumentException e) {
- //OK
- }
+ public void checkNegativeChecks() {
try {
negativeCheck(-1L, "Test Long");
fail();
@@ -87,32 +60,6 @@ public class UtilTest {
}
}
- @Test
- public void checkCodePointArr() {
- final Util.RandomCodePoints rvcp = new Util.RandomCodePoints(true);
- final int n = 1000;
- final int[] cpArr = new int[n];
- rvcp.fillCodePointArray(cpArr);
- for (int i = 0; i < n; i++) {
- int cp = cpArr[i];
- if ((cp >= Character.MIN_SURROGATE) && (cp <= Character.MAX_SURROGATE)) {
- fail();
- }
- }
- }
-
- @Test
- public void checkCodePoint() {
- final Util.RandomCodePoints rvcp = new Util.RandomCodePoints(true);
- final int n = 1000;
- for (int i = 0; i < n; i++) {
- int cp = rvcp.getCodePoint();
- if ((cp >= Character.MIN_SURROGATE) && (cp <= Character.MAX_SURROGATE)) {
- fail();
- }
- }
- }
-
@Test
public void printlnTest() {
println("PRINTING: " + this.getClass().getName());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org