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 2021/05/18 19:57:14 UTC
[datasketches-memory] 07/08: Finished refactoring Buffer tree,
which completes main.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch CreateInternal2
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit 8a570265dbf3b159a65279390a605c9065e113db
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon May 17 20:55:06 2021 -0700
Finished refactoring Buffer tree, which completes main.
Next to refactor the tests. Lots of errors, which is expected.
---
.../org/apache/datasketches/memory/BaseBuffer.java | 126 ++++++++
.../org/apache/datasketches/memory/BaseState.java | 21 +-
.../datasketches/memory/{internal => }/Buffer.java | 125 +++-----
.../memory/DefaultMemoryRequestServer.java | 2 +-
.../org/apache/datasketches/memory/Memory.java | 44 ++-
.../memory/{internal => }/WritableBuffer.java | 142 ++++-----
.../apache/datasketches/memory/WritableMemory.java | 74 ++---
.../internal/BBNonNativeWritableBufferImpl.java | 2 +-
.../memory/internal/BBWritableBufferImpl.java | 4 +-
.../{BaseBuffer.java => BaseBufferImpl.java} | 109 ++-----
.../memory/internal/BaseStateImpl.java | 6 +-
.../memory/internal/BaseWritableBufferImpl.java | 46 +--
.../memory/internal/BaseWritableMemoryImpl.java | 22 +-
.../datasketches/memory/internal/BufferImpl.java | 161 ++++++++++
.../memory/internal/CompareAndCopy.java | 2 +-
.../DirectNonNativeWritableBufferImpl.java | 2 +-
.../memory/internal/DirectWritableBufferImpl.java | 4 +-
.../internal/HeapNonNativeWritableBufferImpl.java | 2 +-
.../memory/internal/HeapWritableBufferImpl.java | 4 +-
.../internal/MapNonNativeWritableBufferImpl.java | 2 +-
.../memory/internal/MapWritableBufferImpl.java | 4 +-
.../datasketches/memory/internal/MemoryImpl.java | 4 +-
...fferImpl.java => NativeWritableBufferImpl.java} | 6 +-
.../internal/NonNativeWritableBufferImpl.java | 4 +-
.../memory/internal/WritableBufferImpl.java | 343 +++++----------------
.../memory/internal/WritableMemoryImpl.java | 4 +-
.../datasketches/memory/internal/package-info.java | 10 +-
.../datasketches/memory/test/BaseBufferTest.java | 8 +-
.../datasketches/memory/test/BaseStateTest.java | 8 +-
.../datasketches/memory/test/Buffer2Test.java | 70 ++---
.../memory/test/BufferInvariantsTest.java | 40 +--
.../memory/test/BufferReadWriteSafetyTest.java | 14 +-
.../datasketches/memory/test/BufferTest.java | 56 ++--
.../datasketches/memory/test/CommonBufferTest.java | 24 +-
.../datasketches/memory/test/LeafImplTest.java | 18 +-
.../memory/test/MemoryBoundaryCheckTest.java | 4 +-
.../test/NonNativeWritableBufferImplTest.java | 40 +--
.../datasketches/memory/test/SpecificLeafTest.java | 36 +--
.../memory/test/WritableBufferImplTest.java | 136 ++++----
.../memory/test/WritableMemoryImplTest.java | 12 +-
.../memory/test/WritableMemoryTest.java | 4 +-
41 files changed, 852 insertions(+), 893 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/memory/BaseBuffer.java b/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
new file mode 100644
index 0000000..68c18c3
--- /dev/null
+++ b/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
@@ -0,0 +1,126 @@
+/*
+ * 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;
+
+public interface BaseBuffer {
+
+ /**
+ * Increments the current position by the given increment.
+ * Asserts that the resource is valid and that the positional invariants are not violated,
+ * otherwise, if asserts are enabled throws an {@link AssertionError}.
+ * @param increment the given increment
+ * @return BaseBuffer
+ */
+ BaseBuffer incrementPosition(long increment);
+
+ /**
+ * Increments the current position by the given increment.
+ * Checks that the resource is valid and that the positional invariants are not violated,
+ * otherwise throws an {@link IllegalArgumentException}.
+ * @param increment the given increment
+ * @return BaseBuffer
+ */
+ BaseBuffer incrementAndCheckPosition(final long increment);
+
+ /**
+ * Gets the end position
+ * @return the end position
+ */
+ long getEnd();
+
+ /**
+ * Gets the current position
+ * @return the current position
+ */
+ long getPosition();
+
+ /**
+ * Gets start position
+ * @return start position
+ */
+ long getStart();
+
+ /**
+ * The number of elements remaining between the current position and the end position
+ * @return {@code (end - position)}
+ */
+ long getRemaining();
+
+ /**
+ * Returns true if there are elements remaining between the current position and the end position
+ * @return {@code (end - position) > 0}
+ */
+ boolean hasRemaining();
+
+ /**
+ * Resets the current position to the start position,
+ * This does not modify any data.
+ * @return BaseBuffer
+ */
+ BaseBuffer resetPosition();
+
+ /**
+ * Sets the current position.
+ * Asserts that the positional invariants are not violated,
+ * otherwise, if asserts are enabled throws an {@link AssertionError}.
+ * @param position the given current position.
+ * @return BaseBuffer
+ */
+ BaseBuffer setPosition(long position);
+
+ /**
+ * Sets the current position.
+ * Checks that the positional invariants are not violated,
+ * otherwise, throws an {@link IllegalArgumentException}.
+ * @param position the given current position.
+ * @return BaseBuffer
+ */
+ BaseBuffer setAndCheckPosition(long position);
+
+ /**
+ * Sets start position, current position, and end position.
+ * Asserts that the positional invariants are not violated,
+ * otherwise, if asserts are enabled throws an {@link AssertionError}.
+ * @param start the start position in the buffer
+ * @param position the current position between the start and end
+ * @param end the end position in the buffer
+ * @return BaseBuffer
+ */
+ BaseBuffer setStartPositionEnd(long start, long position, long end);
+
+ /**
+ * Sets start position, current position, and end position.
+ * Checks that the positional invariants are not violated,
+ * otherwise, throws an {@link IllegalArgumentException}.
+ * @param start the start position in the buffer
+ * @param position the current position between the start and end
+ * @param end the end position in the buffer
+ * @return BaseBuffer
+ */
+ BaseBuffer setAndCheckStartPositionEnd(long start, long position, long end);
+
+
+
+
+
+
+
+
+}
diff --git a/src/main/java/org/apache/datasketches/memory/BaseState.java b/src/main/java/org/apache/datasketches/memory/BaseState.java
index ac1e4f2..0734fbd 100644
--- a/src/main/java/org/apache/datasketches/memory/BaseState.java
+++ b/src/main/java/org/apache/datasketches/memory/BaseState.java
@@ -49,7 +49,7 @@ public interface BaseState {
* @return true if the Native ByteOrder is the same as the ByteOrder of the
* current Buffer or Memory and the same ByteOrder as the given byteOrder.
*/
- boolean isByteOrderCompatible(final ByteOrder byteOrder);
+ boolean isByteOrderCompatible(ByteOrder byteOrder);
/**
* Returns true if the given object is an instance of this class and has equal data contents.
@@ -57,7 +57,7 @@ public interface BaseState {
* @return true if the given Object is an instance of this class and has equal data contents.
*/
@Override
- boolean equals(final Object that);
+ boolean equals(Object that);
/**
* Returns true if the given object is an instance of this class and has equal contents to
@@ -70,8 +70,8 @@ public interface BaseState {
* @return true if the given object has equal contents to this object in the given range of
* bytes.
*/
- boolean equalTo(final long thisOffsetBytes, final Object that,
- final long thatOffsetBytes, final long lengthBytes);
+ boolean equalTo(long thisOffsetBytes, Object that,
+ long thatOffsetBytes, long lengthBytes);
/**
* Gets the backing ByteBuffer if it exists, otherwise returns null.
@@ -103,7 +103,7 @@ public interface BaseState {
* @return the cumulative offset in bytes of this object from the backing resource including the
* given offsetBytes.
*/
- long getCumulativeOffset(final long offsetBytes);
+ long getCumulativeOffset(long offsetBytes);
/**
* Returns the offset of address zero of this object relative to the address zero of the
@@ -122,7 +122,7 @@ public interface BaseState {
* backing resource plus the given offsetBytes but not including the size of any Java object
* header.
*/
- long getRegionOffset(final long offsetBytes);
+ long getRegionOffset(long offsetBytes);
/**
* Returns true if this object is backed by an on-heap primitive array
@@ -156,7 +156,7 @@ public interface BaseState {
* @return the 64-bit hash of the sequence of bytes in this object specified by
* <i>offsetBytes</i> and <i>lengthBytes</i>.
*/
- long xxHash64(final long offsetBytes, final long lengthBytes, final long seed);
+ long xxHash64(long offsetBytes, long lengthBytes, long seed);
/**
* Returns true if this Memory is backed by a ByteBuffer.
@@ -185,7 +185,7 @@ public interface BaseState {
* @return true if the backing resource of <i>this</i> is the same as the backing resource
* of <i>that</i>.
*/
- boolean isSameResource(final Object that);
+ boolean isSameResource(Object that);
/**
* Returns true if this object is valid and has not been closed.
@@ -201,7 +201,7 @@ public interface BaseState {
* @param offsetBytes the given offset in bytes of this object
* @param lengthBytes the given length in bytes of this object
*/
- void checkValidAndBounds(final long offsetBytes, final long lengthBytes);
+ void checkValidAndBounds(long offsetBytes, long lengthBytes);
//Monitoring
@@ -247,7 +247,6 @@ public interface BaseState {
* @param lengthBytes number of bytes to convert to a hex string
* @return a formatted hex string in a human readable array
*/
- String toHexString(final String header, final long offsetBytes,
- final int lengthBytes);
+ String toHexString(String header, long offsetBytes, int lengthBytes);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Buffer.java b/src/main/java/org/apache/datasketches/memory/Buffer.java
similarity index 76%
rename from src/main/java/org/apache/datasketches/memory/internal/Buffer.java
rename to src/main/java/org/apache/datasketches/memory/Buffer.java
index 824a4a5..c3389bf 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/Buffer.java
+++ b/src/main/java/org/apache/datasketches/memory/Buffer.java
@@ -17,27 +17,15 @@
* under the License.
*/
-package org.apache.datasketches.memory.internal;
+
+package org.apache.datasketches.memory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-/**
- * Provides read-only, positional primitive and primitive array methods to any of the four resources
- * mentioned in the package level documentation.
- *
- * @author Roman Leventov
- * @author Lee Rhodes
- *
- * @see org.apache.datasketches.memory.internal
- */
-public abstract class Buffer extends BaseBuffer {
+import org.apache.datasketches.memory.internal.BufferImpl;
- //Pass-through ctor
- Buffer(final Object unsafeObj, final long nativeBaseOffset,
- final long regionOffset, final long capacityBytes) {
- super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
- }
+public interface Buffer extends BaseBuffer {
//BYTE BUFFER
/**
@@ -47,8 +35,8 @@ public abstract class Buffer extends BaseBuffer {
* @param byteBuf the given ByteBuffer, must not be null.
* @return a new Buffer for read-only operations on the given ByteBuffer.
*/
- public static Buffer wrap(final ByteBuffer byteBuf) {
- return wrap(byteBuf, byteBuf.order());
+ static Buffer wrap(ByteBuffer byteBuf) {
+ return BufferImpl.wrap(byteBuf);
}
/**
@@ -61,17 +49,10 @@ public abstract class Buffer extends BaseBuffer {
* state of the given ByteBuffer
* @return a new Buffer for read-only operations on the given ByteBuffer.
*/
- public static Buffer wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
- final BaseWritableMemoryImpl wmem =
- BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, true, byteOrder);
- final WritableBuffer wbuf = wmem.asWritableBufferImpl(true, byteOrder);
- wbuf.setStartPositionEnd(0, byteBuf.position(), byteBuf.limit());
- return wbuf;
+ static Buffer wrap(ByteBuffer byteBuf, ByteOrder byteOrder) {
+ return BufferImpl.wrap(byteBuf, byteOrder);
}
-
- //MAP
- //Use MemoryImpl for mapping files and the asBuffer()
-
+
//DUPLICATES
/**
* Returns a read-only duplicate view of this Buffer with the same but independent values of
@@ -90,7 +71,7 @@ public abstract class Buffer extends BaseBuffer {
* @return a read-only duplicate view of this Buffer with the same but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
*/
- public abstract Buffer duplicate();
+ Buffer duplicate();
/**
* Returns a read-only duplicate view of this Buffer with the same but independent values of
@@ -110,7 +91,7 @@ public abstract class Buffer extends BaseBuffer {
* @return a read-only duplicate view of this Buffer with the same but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
*/
- public abstract Buffer duplicate(ByteOrder byteOrder);
+ Buffer duplicate(ByteOrder byteOrder);
//REGIONS
/**
@@ -129,7 +110,7 @@ public abstract class Buffer extends BaseBuffer {
* @return a new <i>Buffer</i> representing the defined region based on the current
* <i>position</i> and <i>end</i>.
*/
- public abstract Buffer region();
+ Buffer region();
/**
* A region is a read-only view of this object.
@@ -146,8 +127,8 @@ public abstract class Buffer extends BaseBuffer {
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing storage and byte order are unspecified.
*
- * <p><b>Note: The MemoryImpl returned with </b><i>asMemory()</i> will have the originating
- * <i>MemoryImpl</i> byte order.</p>
+ * <p><b>Note: The Memory returned with </b><i>asMemory()</i> will have the originating
+ * <i>Memory</i> byte order.</p>
*
* @param offsetBytes the starting offset with respect to the origin of this <i>WritableBuffer</i>
* @param capacityBytes the <i>capacity</i> of the returned region in bytes
@@ -155,22 +136,18 @@ public abstract class Buffer extends BaseBuffer {
* @return a new <i>Buffer</i> representing the defined writable region
* based on the current <i>position</i>, <i>end</i> and byteOrder.
*/
- public abstract Buffer region(long offsetBytes, long capacityBytes,
+ Buffer region(long offsetBytes, long capacityBytes,
ByteOrder byteOrder);
//MEMORY
/**
- * Convert this Buffer to a MemoryImpl. The current <i>start</i>, <i>position</i> and <i>end</i>
+ * Convert this Buffer to a Memory. The current <i>start</i>, <i>position</i> and <i>end</i>
* are ignored.
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing resource and byte order are unspecified.
- * @return MemoryImpl
+ * @return Memory
*/
- public abstract MemoryImpl asMemory();
-
- //ACCESS PRIMITIVE HEAP ARRAYS for readOnly
- // use MemoryImpl or WritableMemoryImpl and then asBuffer().
- //END OF CONSTRUCTOR-TYPE METHODS
+ Memory asMemory();
//PRIMITIVE getX() and getXArray()
/**
@@ -178,15 +155,15 @@ public abstract class Buffer extends BaseBuffer {
* Increments the position by 1.
* @return the boolean at the current position
*/
- public abstract boolean getBoolean();
+ boolean getBoolean();
/**
* Gets the boolean value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the boolean at the given offset
*/
- public abstract boolean getBoolean(long offsetBytes);
+ boolean getBoolean(long offsetBytes);
/**
* Gets the boolean array at the current position.
@@ -195,7 +172,7 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetBooleans offset in array units
* @param lengthBooleans number of array units to transfer
*/
- public abstract void getBooleanArray(boolean[] dstArray, int dstOffsetBooleans,
+ void getBooleanArray(boolean[] dstArray, int dstOffsetBooleans,
int lengthBooleans);
/**
@@ -203,15 +180,15 @@ public abstract class Buffer extends BaseBuffer {
* Increments the position by <i>Byte.BYTES</i>.
* @return the byte at the current position
*/
- public abstract byte getByte();
+ byte getByte();
/**
* Gets the byte value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the byte at the given offset
*/
- public abstract byte getByte(long offsetBytes);
+ byte getByte(long offsetBytes);
/**
* Gets the byte array at the current position.
@@ -220,22 +197,22 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- public abstract void getByteArray(byte[] dstArray, int dstOffsetBytes, int lengthBytes);
+ void getByteArray(byte[] dstArray, int dstOffsetBytes, int lengthBytes);
/**
* Gets the char value at the current position.
* Increments the position by <i>Character.BYTES</i>.
* @return the char at the current position
*/
- public abstract char getChar();
+ char getChar();
/**
* Gets the char value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the char at the given offset
*/
- public abstract char getChar(long offsetBytes);
+ char getChar(long offsetBytes);
/**
* Gets the char array at the current position.
@@ -244,22 +221,22 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- public abstract void getCharArray(char[] dstArray, int dstOffsetChars, int lengthChars);
+ void getCharArray(char[] dstArray, int dstOffsetChars, int lengthChars);
/**
* Gets the double value at the current position.
* Increments the position by <i>Double.BYTES</i>.
* @return the double at the current position
*/
- public abstract double getDouble();
+ double getDouble();
/**
* Gets the double value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the double at the given offset
*/
- public abstract double getDouble(long offsetBytes);
+ double getDouble(long offsetBytes);
/**
* Gets the double array at the current position.
@@ -268,22 +245,22 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- public abstract void getDoubleArray(double[] dstArray, int dstOffsetDoubles, int lengthDoubles);
+ void getDoubleArray(double[] dstArray, int dstOffsetDoubles, int lengthDoubles);
/**
* Gets the float value at the current position.
* Increments the position by <i>Float.BYTES</i>.
* @return the float at the current position
*/
- public abstract float getFloat();
+ float getFloat();
/**
* Gets the float value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the float at the given offset
*/
- public abstract float getFloat(long offsetBytes);
+ float getFloat(long offsetBytes);
/**
* Gets the float array at the current position.
@@ -292,22 +269,22 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- public abstract void getFloatArray(float[] dstArray, int dstOffsetFloats, int lengthFloats);
+ void getFloatArray(float[] dstArray, int dstOffsetFloats, int lengthFloats);
/**
* Gets the int value at the current position.
* Increments the position by <i>Integer.BYTES</i>.
* @return the int at the current position
*/
- public abstract int getInt();
+ int getInt();
/**
* Gets the int value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the int at the given offset
*/
- public abstract int getInt(long offsetBytes);
+ int getInt(long offsetBytes);
/**
* Gets the int array at the current position.
@@ -316,22 +293,22 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- public abstract void getIntArray(int[] dstArray, int dstOffsetInts, int lengthInts);
+ void getIntArray(int[] dstArray, int dstOffsetInts, int lengthInts);
/**
* Gets the long value at the current position.
* Increments the position by <i>Long.BYTES</i>.
* @return the long at the current position
*/
- public abstract long getLong();
+ long getLong();
/**
* Gets the long value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the long at the given offset
*/
- public abstract long getLong(long offsetBytes);
+ long getLong(long offsetBytes);
/**
* Gets the long array at the current position.
@@ -340,22 +317,22 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- public abstract void getLongArray(long[] dstArray, int dstOffsetLongs, int lengthLongs);
+ void getLongArray(long[] dstArray, int dstOffsetLongs, int lengthLongs);
/**
* Gets the short value at the current position.
* Increments the position by <i>Short.BYTES</i>.
* @return the short at the current position
*/
- public abstract short getShort();
+ short getShort();
/**
* Gets the short value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this MemoryImpl start
+ * @param offsetBytes offset bytes relative to this Memory start
* @return the short at the given offset
*/
- public abstract short getShort(long offsetBytes);
+ short getShort(long offsetBytes);
/**
* Gets the short array at the current position.
@@ -364,7 +341,7 @@ public abstract class Buffer extends BaseBuffer {
* @param dstOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- public abstract void getShortArray(short[] dstArray, int dstOffsetShorts, int lengthShorts);
+ void getShortArray(short[] dstArray, int dstOffsetShorts, int lengthShorts);
//SPECIAL PRIMITIVE READ METHODS: compareTo
/**
@@ -382,7 +359,7 @@ public abstract class Buffer extends BaseBuffer {
* @return <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
* : 0;</i>
*/
- public abstract int compareTo(long thisOffsetBytes, long thisLengthBytes, Buffer that,
+ int compareTo(long thisOffsetBytes, long thisLengthBytes, Buffer that,
long thatOffsetBytes, long thatLengthBytes);
}
diff --git a/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java b/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
index a870b9b..851c4c8 100644
--- a/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
+++ b/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
@@ -51,7 +51,7 @@ import org.apache.datasketches.memory.internal.WritableMemoryImpl;
* moveAndResize(mem, newMem);
*
* //You are done with the old memory, so request close.
- * //Note that it is up to the owner of the WritableDirectHandleImpl whether or not to
+ * //Note that it is up to the owner of the WritableDirectHandle whether or not to
* // actually close the resource.
* memReqSvr.requestClose(mem, newMem);
*
diff --git a/src/main/java/org/apache/datasketches/memory/Memory.java b/src/main/java/org/apache/datasketches/memory/Memory.java
index 01d7891..1457376 100644
--- a/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -26,7 +26,6 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;
-import org.apache.datasketches.memory.internal.Buffer;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Utf8CodingException;
import org.apache.datasketches.memory.internal.Util;
@@ -36,7 +35,7 @@ public interface Memory extends BaseState {
//BYTE BUFFER
/**
- * Accesses the given ByteBuffer for read-only operations. The returned <i>MemoryImpl</i> object has
+ * Accesses the given ByteBuffer for read-only operations. The returned <i>Memory</i> object has
* the same byte order, as the given ByteBuffer, unless the capacity of the given ByteBuffer is
* zero, then byte order of the returned <i>Memory</i> object (as well as backing storage) is
* unspecified.
@@ -46,7 +45,7 @@ public interface Memory extends BaseState {
* @param byteBuf the given ByteBuffer, must not be null
* @return a new <i>Memory</i> for read-only operations on the given ByteBuffer.
*/
- static Memory wrap(final ByteBuffer byteBuf) {
+ static Memory wrap(ByteBuffer byteBuf) {
return MemoryImpl.wrap(byteBuf);
}
@@ -63,7 +62,7 @@ public interface Memory extends BaseState {
* state of the given ByteBuffer.
* @return a new <i>Memory</i> for read-only operations on the given ByteBuffer.
*/
- static Memory wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ static Memory wrap(ByteBuffer byteBuf, ByteOrder byteOrder) {
return MemoryImpl.wrap(byteBuf, byteOrder);
}
@@ -80,7 +79,7 @@ public interface Memory extends BaseState {
* @return <i>MapHandle</i> for managing the mapped Memory.
* Please read Javadocs for {@link Handle}.
*/
- static MapHandle map(final File file) {
+ static MapHandle map(File file) {
return MemoryImpl.map(file, 0, file.length(), ByteOrder.nativeOrder());
}
@@ -97,8 +96,7 @@ public interface Memory extends BaseState {
* @return <i>MapHandle</i> for managing the mapped Memory.
* Please read Javadocs for {@link Handle}.
*/
- static MapHandle map(final File file, final long fileOffsetBytes, final long capacityBytes,
- final ByteOrder byteOrder) {
+ static MapHandle map(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) {
return MemoryImpl.map(file, fileOffsetBytes, capacityBytes, byteOrder);
}
@@ -116,7 +114,7 @@ public interface Memory extends BaseState {
* @return a new <i>Memory</i> representing the defined region based on the given
* offsetBytes and capacityBytes.
*/
- MemoryImpl region(long offsetBytes, long capacityBytes);
+ Memory region(long offsetBytes, long capacityBytes);
/**
* A region is a read-only view of this object.
@@ -133,7 +131,7 @@ public interface Memory extends BaseState {
* @return a new <i>Memory</i> representing the defined region based on the given
* offsetBytes, capacityBytes and byteOrder.
*/
- MemoryImpl region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+ Memory region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
//AS BUFFER
/**
@@ -206,13 +204,13 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final boolean[] arr) {
+ static Memory wrap(boolean[] arr) {
return MemoryImpl.wrap(arr);
}
/**
* Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>MemoryImpl</i> object are
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
* unspecified.
*
* <p><b>Note:</b> Always qualify this method with the class name, e.g.,
@@ -220,7 +218,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final byte[] arr) {
+ static Memory wrap(byte[] arr) {
return MemoryImpl.wrap(arr, 0, arr.length, Util.nativeByteOrder);
}
@@ -235,7 +233,7 @@ public interface Memory extends BaseState {
* @param byteOrder the byte order to be used
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final byte[] arr, final ByteOrder byteOrder) {
+ static Memory wrap(byte[] arr, ByteOrder byteOrder) {
return MemoryImpl.wrap(arr, 0, arr.length, byteOrder);
}
@@ -252,8 +250,8 @@ public interface Memory extends BaseState {
* @param byteOrder the byte order to be used
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
- final ByteOrder byteOrder) {
+ static Memory wrap(byte[] arr, int offsetBytes, int lengthBytes,
+ ByteOrder byteOrder) {
return MemoryImpl.wrap(arr, offsetBytes, lengthBytes, byteOrder);
}
@@ -266,7 +264,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final char[] arr) {
+ static Memory wrap(char[] arr) {
return MemoryImpl.wrap(arr);
}
@@ -279,7 +277,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final short[] arr) {
+ static Memory wrap(short[] arr) {
return MemoryImpl.wrap(arr);
}
@@ -292,7 +290,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final int[] arr) {
+ static Memory wrap(int[] arr) {
return MemoryImpl.wrap(arr);
}
@@ -306,7 +304,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final long[] arr) {
+ static Memory wrap(long[] arr) {
return MemoryImpl.wrap(arr);
}
@@ -320,7 +318,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final float[] arr) {
+ static Memory wrap(float[] arr) {
return MemoryImpl.wrap(arr);
}
@@ -334,7 +332,7 @@ public interface Memory extends BaseState {
* @param arr the given primitive array.
* @return a new <i>Memory</i> for read operations
*/
- static Memory wrap(final double[] arr) {
+ static Memory wrap(double[] arr) {
return MemoryImpl.wrap(arr);
}
@@ -421,8 +419,8 @@ public interface Memory extends BaseState {
* @return the number of characters decoded.
* @throws Utf8CodingException in case of malformed or illegal UTF-8 input
*/
- int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
- final StringBuilder dst) throws Utf8CodingException;
+ int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, StringBuilder dst)
+ throws Utf8CodingException;
/**
* Gets the double value at the given offset
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java b/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
similarity index 75%
rename from src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java
rename to src/main/java/org/apache/datasketches/memory/WritableBuffer.java
index 5911ca9..0a4e282 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
@@ -17,28 +17,15 @@
* under the License.
*/
-package org.apache.datasketches.memory.internal;
+
+package org.apache.datasketches.memory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.DefaultMemoryRequestServer;
-import org.apache.datasketches.memory.MemoryRequestServer;
-
-/**
- * Provides read and write, positional primitive and primitive array access to any of the four
- * resources mentioned at the package level.
- *
- * @author Roman Leventov
- * @author Lee Rhodes
- */
-public abstract class WritableBuffer extends Buffer {
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
- //Pass-through ctor
- WritableBuffer(final Object unsafeObj, final long nativeBaseOffset,
- final long regionOffset, final long capacityBytes) {
- super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
- }
+public interface WritableBuffer {
//BYTE BUFFER
/**
@@ -49,8 +36,8 @@ public abstract class WritableBuffer extends Buffer {
* @param byteBuf the given ByteBuffer, must not be null.
* @return a new WritableBuffer for write operations on the given ByteBuffer.
*/
- public static WritableBuffer wrap(final ByteBuffer byteBuf) {
- return wrap(byteBuf, byteBuf.order());
+ static WritableBuffer writableWrap(ByteBuffer byteBuf) {
+ return WritableBufferImpl.writableWrap(byteBuf, byteBuf.order());
}
/**
@@ -63,20 +50,10 @@ public abstract class WritableBuffer extends Buffer {
* state of the given ByteBuffer
* @return a new WritableBuffer for write operations on the given ByteBuffer.
*/
- public static WritableBuffer wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
- final BaseWritableMemoryImpl wmem =
- BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteOrder);
- final WritableBuffer wbuf = wmem.asWritableBufferImpl(false, byteOrder);
- wbuf.setStartPositionEnd(0, byteBuf.position(), byteBuf.limit());
- return wbuf;
- }
-
- //MAP
- //Use WritableMemoryImpl for mapping files and then asWritableBuffer()
-
- //ALLOCATE DIRECT
- //Use WritableMemoryImpl to allocate direct memory and then asWritableBuffer().
-
+ static WritableBuffer writableWrap(ByteBuffer byteBuf, ByteOrder byteOrder) {
+ return WritableBufferImpl.writableWrap(byteBuf, byteOrder);
+ }
+
//DUPLICATES
/**
* Returns a duplicate writable view of this Buffer with the same but independent values of
@@ -95,7 +72,7 @@ public abstract class WritableBuffer extends Buffer {
* @return a duplicate writable view of this Buffer with the same but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
*/
- public abstract WritableBuffer writableDuplicate();
+ WritableBuffer writableDuplicate();
/**
* Returns a duplicate writable view of this Buffer with the same but independent values of
@@ -115,7 +92,7 @@ public abstract class WritableBuffer extends Buffer {
* @return a duplicate writable view of this Buffer with the same but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
*/
- public abstract WritableBuffer writableDuplicate(ByteOrder byteOrder);
+ WritableBuffer writableDuplicate(ByteOrder byteOrder);
//REGIONS
@@ -134,7 +111,7 @@ public abstract class WritableBuffer extends Buffer {
* the backing storage and byte order are unspecified.
* @return a new <i>WritableBuffer</i> representing the defined writable region.
*/
- public abstract WritableBuffer writableRegion();
+ WritableBuffer writableRegion();
/**
* A writable region is a writable view of this object.
@@ -152,28 +129,24 @@ public abstract class WritableBuffer extends Buffer {
* the backing storage and byte order are unspecified.
*
* <p><b>Note: </b><i>asWritableMemory()</i> and <i>asMemory()</i>
- * will return the originating <i>MemoryImpl</i> byte order.</p>
+ * will return the originating <i>Memory</i> byte order.</p>
* @param offsetBytes the starting offset with respect to the origin of this <i>WritableBuffer</i>
* @param capacityBytes the <i>capacity</i> of the returned region in bytes
* @param byteOrder the given byte order
* @return a new <i>WritableBuffer</i> representing the defined writable region
* with the given offsetBytes, capacityBytes and byte order.
*/
- public abstract WritableBuffer writableRegion(long offsetBytes, long capacityBytes,
+ WritableBuffer writableRegion(long offsetBytes, long capacityBytes,
ByteOrder byteOrder);
//AS MEMORY
/**
- * Convert this WritableBuffer to a WritableMemoryImpl.
+ * Convert this WritableBuffer to a WritableMemory.
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing storage and byte order are unspecified.
- * @return WritableMemoryImpl
+ * @return WritableMemory
*/
- public abstract WritableMemoryImpl asWritableMemory();
-
- //ACCESS PRIMITIVE HEAP ARRAYS for write
- //use WritableMemoryImpl and then asWritableBuffer().
- //END OF CONSTRUCTOR-TYPE METHODS
+ WritableMemory asWritableMemory();
//PRIMITIVE putX() and putXArray()
/**
@@ -181,15 +154,15 @@ public abstract class WritableBuffer extends Buffer {
* Increments the position by 1.
* @param value the value to put
*/
- public abstract void putBoolean(boolean value);
+ void putBoolean(boolean value);
/**
* Puts the boolean value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start.
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start.
* @param value the value to put
*/
- public abstract void putBoolean(long offsetBytes, boolean value);
+ void putBoolean(long offsetBytes, boolean value);
/**
* Puts the boolean array at the current position.
@@ -198,7 +171,7 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetBooleans offset in array units
* @param lengthBooleans number of array units to transfer
*/
- public abstract void putBooleanArray(boolean[] srcArray, int srcOffsetBooleans,
+ void putBooleanArray(boolean[] srcArray, int srcOffsetBooleans,
int lengthBooleans);
/**
@@ -206,15 +179,15 @@ public abstract class WritableBuffer extends Buffer {
* Increments the position by <i>Byte.BYTES</i>.
* @param value the value to put
*/
- public abstract void putByte(byte value);
+ void putByte(byte value);
/**
* Puts the byte value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putByte(long offsetBytes, byte value);
+ void putByte(long offsetBytes, byte value);
/**
* Puts the byte array at the current position.
@@ -223,22 +196,22 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- public abstract void putByteArray(byte[] srcArray, int srcOffsetBytes, int lengthBytes);
+ void putByteArray(byte[] srcArray, int srcOffsetBytes, int lengthBytes);
/**
* Puts the char value at the current position.
* Increments the position by <i>Character.BYTES</i>.
* @param value the value to put
*/
- public abstract void putChar(char value);
+ void putChar(char value);
/**
* Puts the char value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putChar(long offsetBytes, char value);
+ void putChar(long offsetBytes, char value);
/**
* Puts the char array at the current position.
@@ -247,22 +220,22 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- public abstract void putCharArray(char[] srcArray, int srcOffsetChars, int lengthChars);
+ void putCharArray(char[] srcArray, int srcOffsetChars, int lengthChars);
/**
* Puts the double value at the current position.
* Increments the position by <i>Double.BYTES</i>.
* @param value the value to put
*/
- public abstract void putDouble(double value);
+ void putDouble(double value);
/**
* Puts the double value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putDouble(long offsetBytes, double value);
+ void putDouble(long offsetBytes, double value);
/**
* Puts the double array at the current position.
@@ -271,22 +244,22 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- public abstract void putDoubleArray(double[] srcArray, int srcOffsetDoubles, int lengthDoubles);
+ void putDoubleArray(double[] srcArray, int srcOffsetDoubles, int lengthDoubles);
/**
* Puts the float value at the current position.
* Increments the position by <i>Float.BYTES</i>.
* @param value the value to put
*/
- public abstract void putFloat(float value);
+ void putFloat(float value);
/**
* Puts the float value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putFloat(long offsetBytes, float value);
+ void putFloat(long offsetBytes, float value);
/**
* Puts the float array at the current position.
@@ -295,22 +268,22 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- public abstract void putFloatArray(float[] srcArray, int srcOffsetFloats, int lengthFloats);
+ void putFloatArray(float[] srcArray, int srcOffsetFloats, int lengthFloats);
/**
* Puts the int value at the current position.
* Increments the position by <i>Integer.BYTES</i>.
* @param value the value to put
*/
- public abstract void putInt(int value);
+ void putInt(int value);
/**
* Puts the int value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putInt(long offsetBytes, int value);
+ void putInt(long offsetBytes, int value);
/**
* Puts the int array at the current position.
@@ -319,22 +292,22 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- public abstract void putIntArray(int[] srcArray, int srcOffsetInts, int lengthInts);
+ void putIntArray(int[] srcArray, int srcOffsetInts, int lengthInts);
/**
* Puts the long value at the current position.
* Increments the position by <i>Long.BYTES</i>.
* @param value the value to put
*/
- public abstract void putLong(long value);
+ void putLong(long value);
/**
* Puts the long value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putLong(long offsetBytes, long value);
+ void putLong(long offsetBytes, long value);
/**
* Puts the long array at the current position.
@@ -343,22 +316,22 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- public abstract void putLongArray(long[] srcArray, int srcOffsetLongs, int lengthLongs);
+ void putLongArray(long[] srcArray, int srcOffsetLongs, int lengthLongs);
/**
* Puts the short value at the current position.
* Increments the position by <i>Short.BYTES</i>.
* @param value the value to put
*/
- public abstract void putShort(short value);
+ void putShort(short value);
/**
* Puts the short value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putShort(long offsetBytes, short value);
+ void putShort(long offsetBytes, short value);
/**
* Puts the short array at the current position.
@@ -367,39 +340,36 @@ public abstract class WritableBuffer extends Buffer {
* @param srcOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- public abstract void putShortArray(short[] srcArray, int srcOffsetShorts, int lengthShorts);
+ void putShortArray(short[] srcArray, int srcOffsetShorts, int lengthShorts);
//OTHER WRITE METHODS
/**
* Returns the primitive backing array, otherwise null.
* @return the primitive backing array, otherwise null.
*/
- public abstract Object getArray();
+ Object getArray();
/**
* Clears all bytes of this Buffer from position to end to zero. The position will be set to end.
*/
- public abstract void clear();
+ void clear();
/**
* Fills this Buffer from position to end with the given byte value.
* The position will be set to <i>end</i>.
* @param value the given byte value
*/
- public abstract void fill(byte value);
+ void fill(byte value);
//OTHER WRITABLE API METHODS
/**
- * For Direct MemoryImpl only. Other types of backing resources will return null.
+ * For Direct Memory only. Other types of backing resources will return null.
* Gets the MemoryRequestServer object used by dynamic off-heap (Direct) memory objects
* to request additional memory.
- * Set using {@link WritableMemoryImpl#allocateDirect(long, MemoryRequestServer)}.
+ * Set using {@link WritableMemory#allocateDirect(long, MemoryRequestServer)}.
* If not explicity set, this returns the {@link DefaultMemoryRequestServer}.
* @return the MemoryRequestServer object (if direct memory) or null.
*/
- @Override
- public MemoryRequestServer getMemoryRequestServer() {
- return null;
- }
+ public MemoryRequestServer getMemoryRequestServer();
}
diff --git a/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index 9b53b65..1f96323 100644
--- a/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -24,7 +24,6 @@ import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.internal.WritableBuffer;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
public interface WritableMemory extends Memory {
@@ -41,8 +40,8 @@ public interface WritableMemory extends Memory {
* @param byteBuf the given ByteBuffer
* @return a new WritableMemory for write operations on the given ByteBuffer.
*/
- static WritableMemory writableWrap(final ByteBuffer byteBuf) {
- return WritableMemoryImpl.writableWrap(byteBuf);
+ static WritableMemory writableWrap(ByteBuffer byteBuf) {
+ return WritableMemoryImpl.writableWrap(byteBuf, byteBuf.order());
}
/**
@@ -58,7 +57,7 @@ public interface WritableMemory extends Memory {
* state of the given ByteBuffer
* @return a new WritableMemory for write operations on the given ByteBuffer.
*/
- static WritableMemory writableWrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ static WritableMemory writableWrap(ByteBuffer byteBuf, ByteOrder byteOrder) {
return WritableMemoryImpl.writableWrap(byteBuf, byteOrder);
}
@@ -74,7 +73,7 @@ public interface WritableMemory extends Memory {
* @return WritableMapHandle for managing the mapped Memory.
* Please read Javadocs for {@link Handle}.
*/
- static WritableMapHandle writableMap(final File file) {
+ static WritableMapHandle writableMap(File file) {
return WritableMemoryImpl.writableMap(file);
}
@@ -91,8 +90,7 @@ public interface WritableMemory extends Memory {
* @return WritableMapHandle for managing the mapped Memory.
* Please read Javadocs for {@link Handle}.
*/
- static WritableMapHandle writableMap(final File file, final long fileOffsetBytes,
- final long capacityBytes, final ByteOrder byteOrder) {
+ static WritableMapHandle writableMap(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) {
return WritableMemoryImpl.writableMap(file, fileOffsetBytes, capacityBytes, byteOrder);
}
@@ -115,7 +113,7 @@ public interface WritableMemory extends Memory {
* @return WritableDirectHandle for this off-heap resource.
* Please read Javadocs for {@link Handle}.
*/
- static WritableDirectHandle allocateDirect(final long capacityBytes) {
+ static WritableDirectHandle allocateDirect(long capacityBytes) {
return WritableMemoryImpl.allocateDirect(capacityBytes);
}
@@ -135,7 +133,7 @@ public interface WritableMemory extends Memory {
* @return WritableHandle for this off-heap resource.
* Please read Javadocs for {@link Handle}.
*/
- static WritableDirectHandle allocateDirect(final long capacityBytes, final MemoryRequestServer memReqSvr) {
+ static WritableDirectHandle allocateDirect(long capacityBytes, MemoryRequestServer memReqSvr) {
return WritableMemoryImpl.allocateDirect(capacityBytes, memReqSvr);
}
@@ -220,7 +218,7 @@ public interface WritableMemory extends Memory {
* @param capacityBytes the given capacity in bytes.
* @return a new WritableMemory for write operations on a new byte array.
*/
- static WritableMemory allocate(final int capacityBytes) {
+ static WritableMemory allocate(int capacityBytes) {
return WritableMemoryImpl.allocate(capacityBytes);
}
@@ -232,7 +230,7 @@ public interface WritableMemory extends Memory {
* @param byteOrder the given byte order to allocate new Memory object with.
* @return a new WritableMemory for write operations on a new byte array.
*/
- static WritableMemory allocate(final int capacityBytes, final ByteOrder byteOrder) {
+ static WritableMemory allocate(int capacityBytes, ByteOrder byteOrder) {
return WritableMemoryImpl.allocate(capacityBytes, byteOrder);
}
@@ -247,7 +245,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final boolean[] arr) {
+ static WritableMemory writableWrap(boolean[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -261,7 +259,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final byte[] arr) {
+ static WritableMemory writableWrap(byte[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -276,7 +274,7 @@ public interface WritableMemory extends Memory {
* @param byteOrder the byte order to be used
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final byte[] arr, final ByteOrder byteOrder) {
+ static WritableMemory writableWrap(byte[] arr, ByteOrder byteOrder) {
return WritableMemoryImpl.writableWrap(arr, byteOrder);
}
@@ -293,8 +291,8 @@ public interface WritableMemory extends Memory {
* @param byteOrder the byte order to be used
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
- final ByteOrder byteOrder) {
+ static WritableMemory writableWrap(byte[] arr, int offsetBytes, int lengthBytes,
+ ByteOrder byteOrder) {
return WritableMemoryImpl.writableWrap(arr, offsetBytes, lengthBytes, byteOrder);
}
@@ -308,7 +306,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final char[] arr) {
+ static WritableMemory writableWrap(char[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -322,7 +320,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final short[] arr) {
+ static WritableMemory writableWrap(short[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -336,7 +334,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final int[] arr) {
+ static WritableMemory writableWrap(int[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -350,7 +348,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final long[] arr) {
+ static WritableMemory writableWrap(long[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -364,7 +362,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final float[] arr) {
+ static WritableMemory writableWrap(float[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
@@ -378,7 +376,7 @@ public interface WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(final double[] arr) {
+ static WritableMemory writableWrap(double[] arr) {
return WritableMemoryImpl.writableWrap(arr);
}
//END OF CONSTRUCTOR-TYPE METHODS
@@ -398,8 +396,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetBooleans offset in array units
* @param lengthBooleans number of array units to transfer
*/
- void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans,
- int lengthBooleans);
+ void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans, int lengthBooleans);
/**
* Puts the byte value at the given offset
@@ -415,8 +412,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes,
- int lengthBytes);
+ void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes, int lengthBytes);
/**
* Puts the char value at the given offset
@@ -432,8 +428,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars,
- int lengthChars);
+ void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars, int lengthChars);
/**
* Encodes characters from the given CharSequence into UTF-8 bytes and puts them into this
@@ -463,8 +458,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- void putDoubleArray(long offsetBytes, double[] srcArray,
- final int srcOffsetDoubles, final int lengthDoubles);
+ void putDoubleArray(long offsetBytes, double[] srcArray, int srcOffsetDoubles, int lengthDoubles);
/**
* Puts the float value at the given offset
@@ -480,8 +474,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- void putFloatArray(long offsetBytes, float[] srcArray,
- final int srcOffsetFloats, final int lengthFloats);
+ void putFloatArray(long offsetBytes, float[] srcArray, int srcOffsetFloats, int lengthFloats);
/**
* Puts the int value at the given offset
@@ -497,8 +490,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- void putIntArray(long offsetBytes, int[] srcArray,
- final int srcOffsetInts, final int lengthInts);
+ void putIntArray(long offsetBytes, int[] srcArray, int srcOffsetInts, int lengthInts);
/**
* Puts the long value at the given offset
@@ -514,8 +506,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- void putLongArray(long offsetBytes, long[] srcArray,
- final int srcOffsetLongs, final int lengthLongs);
+ void putLongArray(long offsetBytes, long[] srcArray, int srcOffsetLongs, int lengthLongs);
/**
* Puts the short value at the given offset
@@ -531,8 +522,7 @@ public interface WritableMemory extends Memory {
* @param srcOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- void putShortArray(long offsetBytes, short[] srcArray,
- final int srcOffsetShorts, final int lengthShorts);
+ void putShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts);
//Atomic Methods
/**
@@ -621,12 +611,4 @@ public interface WritableMemory extends Memory {
*/
MemoryRequestServer getMemoryRequestServer();
-
-
-
-
-
-
}
-
-
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
index 2e631e7..1c798c3 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
@@ -23,7 +23,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableBuffer} for ByteBuffer, non-native byte order.
+ * Implementation of {@link WritableBufferImpl} for ByteBuffer, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
index bf0d2ee..d924f9a 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
@@ -23,12 +23,12 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableBuffer} for ByteBuffer, native byte order.
+ * Implementation of {@link WritableBufferImpl} for ByteBuffer, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class BBWritableBufferImpl extends WritableBufferImpl {
+final class BBWritableBufferImpl extends NativeWritableBufferImpl {
private static final int id = BUFFER | NATIVE | BYTEBUF;
private final Object unsafeObj;
private final long nativeBaseOffset; //used to compute cumBaseOffset
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java b/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
similarity index 64%
rename from src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java
rename to src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
index 901002b..1b58501 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
@@ -19,8 +19,10 @@
package org.apache.datasketches.memory.internal;
+import org.apache.datasketches.memory.BaseBuffer;
+
/**
- * A new positional API. This is different from and simpler than Java Buffer positional approach.
+ * A new positional API. This is different from and simpler than Java BufferImpl positional approach.
* <ul><li>All based on longs instead of ints.</li>
* <li>Eliminated "mark". Rarely used and confusing with its silent side effects.</li>
* <li>The invariants are {@code 0 <= start <= position <= end <= capacity}.</li>
@@ -36,129 +38,78 @@ package org.apache.datasketches.memory.internal;
*
* @author Lee Rhodes
*/
-public abstract class BaseBuffer extends BaseStateImpl {
+public abstract class BaseBufferImpl extends BaseStateImpl implements BaseBuffer {
private long capacity;
private long start = 0;
private long pos = 0;
private long end;
//Pass-through ctor
- BaseBuffer(final Object unsafeObj, final long nativeBaseOffset,
+ BaseBufferImpl(final Object unsafeObj, final long nativeBaseOffset,
final long regionOffset, final long capacityBytes) {
super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
capacity = end = capacityBytes;
}
- /**
- * Increments the current position by the given increment.
- * Asserts that the resource is valid and that the positional invariants are not violated,
- * otherwise, if asserts are enabled throws an {@link AssertionError}.
- * @param increment the given increment
- * @return BaseBuffer
- */
- public final BaseBuffer incrementPosition(final long increment) {
+ @Override
+ public final BaseBufferImpl incrementPosition(final long increment) {
incrementAndAssertPositionForRead(pos, increment);
return this;
}
- /**
- * Increments the current position by the given increment.
- * Checks that the resource is valid and that the positional invariants are not violated,
- * otherwise throws an {@link IllegalArgumentException}.
- * @param increment the given increment
- * @return BaseBuffer
- */
- public final BaseBuffer incrementAndCheckPosition(final long increment) {
+ @Override
+ public final BaseBufferImpl incrementAndCheckPosition(final long increment) {
incrementAndCheckPositionForRead(pos, increment);
return this;
}
- /**
- * Gets the end position
- * @return the end position
- */
+ @Override
public final long getEnd() {
return end;
}
- /**
- * Gets the current position
- * @return the current position
- */
+ @Override
public final long getPosition() {
return pos;
}
- /**
- * Gets start position
- * @return start position
- */
+ @Override
public final long getStart() {
return start;
}
- /**
- * The number of elements remaining between the current position and the end position
- * @return {@code (end - position)}
- */
+ @Override
public final long getRemaining() {
return end - pos;
}
- /**
- * Returns true if there are elements remaining between the current position and the end position
- * @return {@code (end - position) > 0}
- */
+ @Override
public final boolean hasRemaining() {
return (end - pos) > 0;
}
- /**
- * Resets the current position to the start position,
- * This does not modify any data.
- * @return BaseBuffer
- */
- public final BaseBuffer resetPosition() {
+ @Override
+ public final BaseBufferImpl resetPosition() {
pos = start;
return this;
}
- /**
- * Sets the current position.
- * Asserts that the positional invariants are not violated,
- * otherwise, if asserts are enabled throws an {@link AssertionError}.
- * @param position the given current position.
- * @return BaseBuffer
- */
- public final BaseBuffer setPosition(final long position) {
+ @Override
+ public final BaseBufferImpl setPosition(final long position) {
assertInvariants(start, position, end, capacity);
pos = position;
return this;
}
- /**
- * Sets the current position.
- * Checks that the positional invariants are not violated,
- * otherwise, throws an {@link IllegalArgumentException}.
- * @param position the given current position.
- * @return BaseBuffer
- */
- public final BaseBuffer setAndCheckPosition(final long position) {
+ @Override
+ public final BaseBufferImpl setAndCheckPosition(final long position) {
checkInvariants(start, position, end, capacity);
pos = position;
return this;
}
- /**
- * Sets start position, current position, and end position.
- * Asserts that the positional invariants are not violated,
- * otherwise, if asserts are enabled throws an {@link AssertionError}.
- * @param start the start position in the buffer
- * @param position the current position between the start and end
- * @param end the end position in the buffer
- * @return BaseBuffer
- */
- public final BaseBuffer setStartPositionEnd(final long start, final long position,
+ @Override
+ public final BaseBufferImpl setStartPositionEnd(final long start, final long position,
final long end) {
assertInvariants(start, position, end, capacity);
this.start = start;
@@ -167,16 +118,8 @@ public abstract class BaseBuffer extends BaseStateImpl {
return this;
}
- /**
- * Sets start position, current position, and end position.
- * Checks that the positional invariants are not violated,
- * otherwise, throws an {@link IllegalArgumentException}.
- * @param start the start position in the buffer
- * @param position the current position between the start and end
- * @param end the end position in the buffer
- * @return BaseBuffer
- */
- public final BaseBuffer setAndCheckStartPositionEnd(final long start, final long position,
+ @Override
+ public final BaseBufferImpl setAndCheckStartPositionEnd(final long start, final long position,
final long end) {
checkInvariants(start, position, end, capacity);
this.start = start;
@@ -195,7 +138,7 @@ public abstract class BaseBuffer extends BaseStateImpl {
final void incrementAndAssertPositionForWrite(final long position, final long increment) {
assertValid();
- assert !isReadOnly() : "Buffer is read-only.";
+ assert !isReadOnly() : "BufferImpl is read-only.";
final long newPos = position + increment;
assertInvariants(start, newPos, end, capacity);
pos = newPos;
@@ -218,7 +161,7 @@ public abstract class BaseBuffer extends BaseStateImpl {
final void checkValidForWrite() {
checkValid();
if (isReadOnly()) {
- throw new ReadOnlyException("Buffer is read-only.");
+ throw new ReadOnlyException("BufferImpl is read-only.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 8855c99..d0c3524 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -33,7 +33,7 @@ import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.BaseState;
/**
- * Keeps key configuration state for MemoryImpl and Buffer plus some common static variables
+ * Keeps key configuration state for MemoryImpl and BufferImpl plus some common static variables
* and check methods.
*
* @author Lee Rhodes
@@ -162,7 +162,7 @@ public abstract class BaseStateImpl implements BaseState {
return cumBaseOffset_ + offsetBytes;
}
- //made public in WritableMemoryImpl and WritableBuffer, only implemented in Direct Leafs
+ //made public in WritableMemoryImpl and WritableBufferImpl, only implemented in Direct Leafs
abstract MemoryRequestServer getMemoryRequestServer();
//Overridden by ByteBuffer, Direct and Map leafs
@@ -187,7 +187,7 @@ public abstract class BaseStateImpl implements BaseState {
abstract int getTypeId();
//Overridden by Heap and ByteBuffer Leafs. Made public as getArray() in WritableMemoryImpl and
- // WritableBuffer
+ // WritableBufferImpl
Object getUnsafeObject() {
return null;
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index 935b364..bfc3233 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -30,6 +30,8 @@ import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_SHORT_IND
import static org.apache.datasketches.memory.internal.UnsafeUtil.checkBounds;
import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
+import org.apache.datasketches.memory.Buffer;
+
import java.nio.ByteOrder;
/*
@@ -46,15 +48,15 @@ import java.nio.ByteOrder;
*/
/**
- * Common base of native-ordered and non-native-ordered {@link WritableBuffer} implementations.
+ * Common base of native-ordered and non-native-ordered {@link WritableBufferImpl} implementations.
* Contains methods which are agnostic to the byte order.
*/
@SuppressWarnings({"restriction"})
-abstract class BaseWritableBufferImpl extends WritableBuffer {
+abstract class BaseWritableBufferImpl extends WritableBufferImpl {
final BaseWritableMemoryImpl originMemory;
//Static variable for cases where byteBuf/array sizes are zero
- final static WritableBufferImpl ZERO_SIZE_BUFFER;
+ final static NativeWritableBufferImpl ZERO_SIZE_BUFFER;
static {
final BaseWritableMemoryImpl mem = BaseWritableMemoryImpl.ZERO_SIZE_MEMORY;
@@ -71,40 +73,40 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
//REGIONS
@Override
- public Buffer region() {
+ public BufferImpl region() {
return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getTypeByteOrder());
}
@Override
- public Buffer region(final long offsetBytes, final long capacityBytes,
+ public BufferImpl region(final long offsetBytes, final long capacityBytes,
final ByteOrder byteOrder) {
- final Buffer buf = writableRegionImpl(offsetBytes, capacityBytes, true, byteOrder);
+ final BufferImpl buf = writableRegionImpl(offsetBytes, capacityBytes, true, byteOrder);
buf.setAndCheckStartPositionEnd(0, 0, capacityBytes);
return buf;
}
@Override
- public WritableBuffer writableRegion() {
+ public WritableBufferImpl writableRegion() {
return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getTypeByteOrder());
}
@Override
- public WritableBuffer writableRegion(final long offsetBytes, final long capacityBytes,
+ public WritableBufferImpl writableRegion(final long offsetBytes, final long capacityBytes,
final ByteOrder byteOrder) {
- final WritableBuffer wbuf = writableRegionImpl(offsetBytes, capacityBytes, false, byteOrder);
+ final WritableBufferImpl wbuf = writableRegionImpl(offsetBytes, capacityBytes, false, byteOrder);
wbuf.setAndCheckStartPositionEnd(0, 0, capacityBytes);
return wbuf;
}
- WritableBuffer writableRegionImpl(final long offsetBytes, final long capacityBytes,
+ WritableBufferImpl writableRegionImpl(final long offsetBytes, final long capacityBytes,
final boolean localReadOnly, final ByteOrder byteOrder) {
if (capacityBytes == 0) { return ZERO_SIZE_BUFFER; }
if (isReadOnly() && !localReadOnly) {
- throw new ReadOnlyException("Writable region of a read-only Buffer is not allowed.");
+ throw new ReadOnlyException("Writable region of a read-only BufferImpl is not allowed.");
}
checkValidAndBounds(offsetBytes, capacityBytes);
final boolean readOnly = isReadOnly() || localReadOnly;
- final WritableBuffer wbuf = toWritableRegion(offsetBytes, capacityBytes, readOnly, byteOrder);
+ final WritableBufferImpl wbuf = toWritableRegion(offsetBytes, capacityBytes, readOnly, byteOrder);
wbuf.setStartPositionEnd(0, 0, capacityBytes);
return wbuf;
}
@@ -114,31 +116,31 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
//DUPLICATES
@Override
- public Buffer duplicate() {
+ public BufferImpl duplicate() {
return writableDuplicateImpl(true, getTypeByteOrder());
}
@Override
- public Buffer duplicate(final ByteOrder byteOrder) {
+ public BufferImpl duplicate(final ByteOrder byteOrder) {
return writableDuplicateImpl(true, byteOrder);
}
@Override
- public WritableBuffer writableDuplicate() {
+ public WritableBufferImpl writableDuplicate() {
return writableDuplicateImpl(false, getTypeByteOrder());
}
@Override
- public WritableBuffer writableDuplicate(final ByteOrder byteOrder) {
+ public WritableBufferImpl writableDuplicate(final ByteOrder byteOrder) {
return writableDuplicateImpl(false, byteOrder);
}
- WritableBuffer writableDuplicateImpl(final boolean localReadOnly, final ByteOrder byteOrder) {
+ WritableBufferImpl writableDuplicateImpl(final boolean localReadOnly, final ByteOrder byteOrder) {
if (isReadOnly() && !localReadOnly) {
- throw new ReadOnlyException("Writable duplicate of a read-only Buffer is not allowed.");
+ throw new ReadOnlyException("Writable duplicate of a read-only BufferImpl is not allowed.");
}
final boolean readOnly = isReadOnly() || localReadOnly;
- final WritableBuffer wbuf = toDuplicate(readOnly, byteOrder);
+ final WritableBufferImpl wbuf = toDuplicate(readOnly, byteOrder);
wbuf.setStartPositionEnd(getStart(), getPosition(), getEnd());
return wbuf;
}
@@ -154,7 +156,7 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
@Override
public WritableMemoryImpl asWritableMemory() {
if (isReadOnly()) {
- throw new ReadOnlyException("Converting a read-only Buffer to a writable MemoryImpl is not allowed.");
+ throw new ReadOnlyException("Converting a read-only BufferImpl to a writable MemoryImpl is not allowed.");
}
return originMemory;
}
@@ -265,8 +267,8 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
@Override
public final int compareTo(final long thisOffsetBytes, final long thisLengthBytes,
final Buffer thatBuf, final long thatOffsetBytes, final long thatLengthBytes) {
- return CompareAndCopy.compare(this, thisOffsetBytes, thisLengthBytes,
- thatBuf, thatOffsetBytes, thatLengthBytes);
+ return CompareAndCopy.compare((BaseStateImpl)this, thisOffsetBytes, thisLengthBytes,
+ (BaseStateImpl)thatBuf, thatOffsetBytes, thatLengthBytes);
}
/*
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index 872cc05..07df6b0 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -200,32 +200,32 @@ abstract class BaseWritableMemoryImpl extends WritableMemoryImpl {
//AS BUFFER
@Override
- public Buffer asBuffer() {
- return asWritableBufferImpl(true, getTypeByteOrder());
+ public BufferImpl asBuffer() {
+ return asWritableBuffer(true, getTypeByteOrder());
}
@Override
- public Buffer asBuffer(final ByteOrder byteOrder) {
- return asWritableBufferImpl(true, byteOrder);
+ public BufferImpl asBuffer(final ByteOrder byteOrder) {
+ return asWritableBuffer(true, byteOrder);
}
@Override
- public WritableBuffer asWritableBuffer() {
- return asWritableBufferImpl(false, getTypeByteOrder());
+ public WritableBufferImpl asWritableBuffer() {
+ return asWritableBuffer(false, getTypeByteOrder());
}
@Override
- public WritableBuffer asWritableBuffer(final ByteOrder byteOrder) {
- return asWritableBufferImpl(false, byteOrder);
+ public WritableBufferImpl asWritableBuffer(final ByteOrder byteOrder) {
+ return asWritableBuffer(false, byteOrder);
}
- WritableBuffer asWritableBufferImpl(final boolean localReadOnly, final ByteOrder byteOrder) {
+ WritableBufferImpl asWritableBuffer(final boolean localReadOnly, final ByteOrder byteOrder) {
if (isReadOnly() && !localReadOnly) {
throw new ReadOnlyException(
- "Converting a read-only MemoryImpl to a writable Buffer is not allowed.");
+ "Converting a read-only MemoryImpl to a writable BufferImpl is not allowed.");
}
final boolean readOnly = isReadOnly() || localReadOnly;
- final WritableBuffer wbuf = toWritableBuffer(readOnly, byteOrder);
+ final WritableBufferImpl wbuf = toWritableBuffer(readOnly, byteOrder);
wbuf.setStartPositionEnd(0, 0, getCapacity());
return wbuf;
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java
new file mode 100644
index 0000000..482db82
--- /dev/null
+++ b/src/main/java/org/apache/datasketches/memory/internal/BufferImpl.java
@@ -0,0 +1,161 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import org.apache.datasketches.memory.Buffer;
+
+/**
+ * Provides read-only, positional primitive and primitive array methods to any of the four resources
+ * mentioned in the package level documentation.
+ *
+ * @author Roman Leventov
+ * @author Lee Rhodes
+ *
+ * @see org.apache.datasketches.memory.internal
+ */
+public abstract class BufferImpl extends BaseBufferImpl implements Buffer {
+
+ //Pass-through ctor
+ BufferImpl(final Object unsafeObj, final long nativeBaseOffset,
+ final long regionOffset, final long capacityBytes) {
+ super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
+ }
+
+ //BYTE BUFFER
+ public static BufferImpl wrap(final ByteBuffer byteBuf) {
+ return wrap(byteBuf, byteBuf.order());
+ }
+
+ public static BufferImpl wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ final BaseWritableMemoryImpl wmem =
+ BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, true, byteOrder);
+ final WritableBufferImpl wbuf = wmem.asWritableBuffer(true, byteOrder);
+ wbuf.setStartPositionEnd(0, byteBuf.position(), byteBuf.limit());
+ return wbuf;
+ }
+
+ //MAP
+ //Use MemoryImpl for mapping files and the asBuffer()
+
+ //DUPLICATES
+ @Override
+ public abstract BufferImpl duplicate();
+
+ @Override
+ public abstract BufferImpl duplicate(ByteOrder byteOrder);
+
+ //REGIONS
+ @Override
+ public abstract BufferImpl region();
+
+ @Override
+ public abstract BufferImpl region(long offsetBytes, long capacityBytes,
+ ByteOrder byteOrder);
+
+ //MEMORY
+ @Override
+ public abstract MemoryImpl asMemory();
+
+ //ACCESS PRIMITIVE HEAP ARRAYS for readOnly
+ // use MemoryImpl or WritableMemoryImpl and then asBuffer().
+ //END OF CONSTRUCTOR-TYPE METHODS
+
+ //PRIMITIVE getX() and getXArray()
+ @Override
+ public abstract boolean getBoolean();
+
+ @Override
+ public abstract boolean getBoolean(long offsetBytes);
+
+ @Override
+ public abstract void getBooleanArray(boolean[] dstArray, int dstOffsetBooleans,
+ int lengthBooleans);
+
+ @Override
+ public abstract byte getByte();
+
+ @Override
+ public abstract byte getByte(long offsetBytes);
+
+ @Override
+ public abstract void getByteArray(byte[] dstArray, int dstOffsetBytes, int lengthBytes);
+
+ @Override
+ public abstract char getChar();
+
+ @Override
+ public abstract char getChar(long offsetBytes);
+
+ @Override
+ public abstract void getCharArray(char[] dstArray, int dstOffsetChars, int lengthChars);
+
+ @Override
+ public abstract double getDouble();
+
+ @Override
+ public abstract double getDouble(long offsetBytes);
+
+ @Override
+ public abstract void getDoubleArray(double[] dstArray, int dstOffsetDoubles, int lengthDoubles);
+
+ @Override
+ public abstract float getFloat();
+
+ @Override
+ public abstract float getFloat(long offsetBytes);
+
+ @Override
+ public abstract void getFloatArray(float[] dstArray, int dstOffsetFloats, int lengthFloats);
+
+ @Override
+ public abstract int getInt();
+
+ @Override
+ public abstract int getInt(long offsetBytes);
+
+ @Override
+ public abstract void getIntArray(int[] dstArray, int dstOffsetInts, int lengthInts);
+
+ @Override
+ public abstract long getLong();
+
+ @Override
+ public abstract long getLong(long offsetBytes);
+
+ @Override
+ public abstract void getLongArray(long[] dstArray, int dstOffsetLongs, int lengthLongs);
+
+ @Override
+ public abstract short getShort();
+
+ @Override
+ public abstract short getShort(long offsetBytes);
+
+ @Override
+ public abstract void getShortArray(short[] dstArray, int dstOffsetShorts, int lengthShorts);
+
+ //SPECIAL PRIMITIVE READ METHODS: compareTo
+ @Override
+ public abstract int compareTo(long thisOffsetBytes, long thisLengthBytes, Buffer that,
+ long thatOffsetBytes, long thatLengthBytes);
+
+}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
index 089e576..b49e739 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
@@ -124,7 +124,7 @@ final class CompareAndCopy {
lengthBytes);
}
- //Used by all of the get/put array methods in Buffer and MemoryImpl classes
+ //Used by all of the get/put array methods in BufferImpl and MemoryImpl classes
static final void copyMemoryCheckingDifferentObject(final Object srcUnsafeObj,
final long srcAdd, final Object dstUnsafeObj, final long dstAdd, final long lengthBytes) {
if (srcUnsafeObj != dstUnsafeObj) {
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
index 4358d6b..5957fc6 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
@@ -24,7 +24,7 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.MemoryRequestServer;
/**
- * Implementation of {@link WritableBuffer} for direct memory, non-native byte order.
+ * Implementation of {@link WritableBufferImpl} for direct memory, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
index 9b1a287..b5c3609 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
@@ -24,12 +24,12 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.MemoryRequestServer;
/**
- * Implementation of {@link WritableBuffer} for direct memory, native byte order.
+ * Implementation of {@link WritableBufferImpl} for direct memory, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class DirectWritableBufferImpl extends WritableBufferImpl {
+final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
private static final int id = BUFFER | NATIVE | DIRECT;
private final long nativeBaseOffset; //used to compute cumBaseOffset
private final StepBoolean valid; //a reference only
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
index f0f1fef..5a74126 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
@@ -22,7 +22,7 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableBuffer} for heap-based, non-native byte order.
+ * Implementation of {@link WritableBufferImpl} for heap-based, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
index e2d35b8..5a9316f 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
@@ -22,12 +22,12 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableBuffer} for heap-based, native byte order.
+ * Implementation of {@link WritableBufferImpl} for heap-based, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class HeapWritableBufferImpl extends WritableBufferImpl {
+final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
private static final int id = BUFFER | NATIVE | HEAP;
private final Object unsafeObj;
private final byte typeId;
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
index 59ca32d..0f135d5 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
@@ -22,7 +22,7 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableBuffer} for map memory, non-native byte order.
+ * Implementation of {@link WritableBufferImpl} for map memory, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
index 4a9be74..eafe417 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
@@ -22,12 +22,12 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableBuffer} for map memory, native byte order.
+ * Implementation of {@link WritableBufferImpl} for map memory, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class MapWritableBufferImpl extends WritableBufferImpl {
+final class MapWritableBufferImpl extends NativeWritableBufferImpl {
private static final int id = BUFFER | NATIVE | MAP;
private final long nativeBaseOffset; //used to compute cumBaseOffset
private final StepBoolean valid; //a reference only
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
index 4761ec6..e758318 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
@@ -81,10 +81,10 @@ public abstract class MemoryImpl extends BaseStateImpl implements Memory {
//AS BUFFER
@Override
- public abstract Buffer asBuffer();
+ public abstract BufferImpl asBuffer();
@Override
- public abstract Buffer asBuffer(ByteOrder byteOrder);
+ public abstract BufferImpl asBuffer(ByteOrder byteOrder);
//UNSAFE BYTE BUFFER VIEW
@Override
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
similarity index 98%
copy from src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
copy to src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
index fb84563..d3f5f59 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
@@ -50,16 +50,16 @@ import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
*/
/**
- * Implementation of {@link WritableBuffer} for native endian byte order. Non-native variant is
+ * Implementation of {@link WritableBufferImpl} for native endian byte order. Non-native variant is
* {@link NonNativeWritableBufferImpl}.
* @author Roman Leventov
* @author Lee Rhodes
*/
@SuppressWarnings({"restriction"})
-abstract class WritableBufferImpl extends BaseWritableBufferImpl {
+abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
//Pass-through ctor
- WritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
+ NativeWritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
final long capacityBytes, final BaseWritableMemoryImpl originMemory) {
super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes, originMemory);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
index 818a6ee..6073fce 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
@@ -43,8 +43,8 @@ import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
*/
/**
- * Implementation of {@link WritableBuffer} for non-native endian byte order. Native variant is
- * {@link WritableBufferImpl}.
+ * Implementation of {@link WritableBufferImpl} for non-native endian byte order. Native variant is
+ * {@link NativeWritableBufferImpl}.
* @author Roman Leventov
* @author Lee Rhodes
*/
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
index fb84563..4f53d40 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java
@@ -19,356 +19,157 @@
package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_CHAR_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_DOUBLE_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_DOUBLE_INDEX_SCALE;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_FLOAT_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_FLOAT_INDEX_SCALE;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_INT_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_LONG_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_SHORT_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.CHAR_SHIFT;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.DOUBLE_SHIFT;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.FLOAT_SHIFT;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.INT_SHIFT;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.LONG_SHIFT;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.SHORT_SHIFT;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.checkBounds;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
-/*
- * Developer notes: The heavier methods, such as put/get arrays, duplicate, region, clear, fill,
- * compareTo, etc., use hard checks (check*() and incrementAndCheck*() methods), which execute at
- * runtime and throw exceptions if violated. The cost of the runtime checks are minor compared to
- * the rest of the work these methods are doing.
- *
- * <p>The light weight methods, such as put/get primitives, use asserts (assert*() and
- * incrementAndAssert*() methods), which only execute when asserts are enabled and JIT will remove
- * them entirely from production runtime code. The offset versions of the light weight methods will
- * simplify to a single unsafe call, which is further simplified by JIT to an intrinsic that is
- * often a single CPU instruction.
- */
+import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.WritableBuffer;
/**
- * Implementation of {@link WritableBuffer} for native endian byte order. Non-native variant is
- * {@link NonNativeWritableBufferImpl}.
+ * Provides read and write, positional primitive and primitive array access to any of the four
+ * resources mentioned at the package level.
+ *
* @author Roman Leventov
* @author Lee Rhodes
*/
-@SuppressWarnings({"restriction"})
-abstract class WritableBufferImpl extends BaseWritableBufferImpl {
+public abstract class WritableBufferImpl extends BufferImpl implements WritableBuffer {
//Pass-through ctor
- WritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
- final long capacityBytes, final BaseWritableMemoryImpl originMemory) {
- super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes, originMemory);
+ WritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset,
+ final long regionOffset, final long capacityBytes) {
+ super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
}
- //PRIMITIVE getX() and getXArray()
- @Override
- public char getChar() {
- return getNativeOrderedChar();
+ //BYTE BUFFER
+ public static WritableBufferImpl writableWrap(final ByteBuffer byteBuf) {
+ return writableWrap(byteBuf, byteBuf.order());
}
- @Override
- public char getChar(final long offsetBytes) {
- return getNativeOrderedChar(offsetBytes);
+ public static WritableBufferImpl writableWrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ final BaseWritableMemoryImpl wmem =
+ BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteOrder);
+ final WritableBufferImpl wbuf = wmem.asWritableBuffer(false, byteOrder);
+ wbuf.setStartPositionEnd(0, byteBuf.position(), byteBuf.limit());
+ return wbuf;
}
- @Override
- public void getCharArray(final char[] dstArray, final int dstOffsetChars, final int lengthChars) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- incrementAndCheckPositionForRead(pos, copyBytes);
- checkBounds(dstOffsetChars, lengthChars, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_CHAR_BASE_OFFSET + (((long) dstOffsetChars) << CHAR_SHIFT),
- copyBytes);
- }
+ //MAP
+ //Use WritableMemoryImpl for mapping files and then asWritableBuffer()
+
+ //ALLOCATE DIRECT
+ //Use WritableMemoryImpl to allocate direct memory and then asWritableBuffer().
+ //DUPLICATES
@Override
- public double getDouble() {
- final long pos = getPosition();
- incrementAndAssertPositionForRead(pos, ARRAY_DOUBLE_INDEX_SCALE);
- return unsafe.getDouble(getUnsafeObject(), getCumulativeOffset(pos));
- }
+ public abstract WritableBufferImpl writableDuplicate();
@Override
- public double getDouble(final long offsetBytes) {
- assertValidAndBoundsForRead(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
- return unsafe.getDouble(getUnsafeObject(), getCumulativeOffset(offsetBytes));
- }
+ public abstract WritableBufferImpl writableDuplicate(ByteOrder byteOrder);
+ //REGIONS
@Override
- public void getDoubleArray(final double[] dstArray, final int dstOffsetDoubles,
- final int lengthDoubles) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- incrementAndCheckPositionForRead(pos, copyBytes);
- checkBounds(dstOffsetDoubles, lengthDoubles, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_DOUBLE_BASE_OFFSET + (((long) dstOffsetDoubles) << DOUBLE_SHIFT),
- copyBytes);
- }
+ public abstract WritableBufferImpl writableRegion();
@Override
- public float getFloat() {
- final long pos = getPosition();
- incrementAndAssertPositionForRead(pos, ARRAY_FLOAT_INDEX_SCALE);
- return unsafe.getFloat(getUnsafeObject(), getCumulativeOffset(pos));
- }
+ public abstract WritableBufferImpl writableRegion(long offsetBytes, long capacityBytes,
+ ByteOrder byteOrder);
+ //AS MEMORY
@Override
- public float getFloat(final long offsetBytes) {
- assertValidAndBoundsForRead(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
- return unsafe.getFloat(getUnsafeObject(), getCumulativeOffset(offsetBytes));
- }
+ public abstract WritableMemoryImpl asWritableMemory();
+
+ //ACCESS PRIMITIVE HEAP ARRAYS for write
+ //use WritableMemoryImpl and then asWritableBuffer().
+ //END OF CONSTRUCTOR-TYPE METHODS
+ //PRIMITIVE putX() and putXArray()
@Override
- public void getFloatArray(final float[] dstArray, final int dstOffsetFloats,
- final int lengthFloats) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- incrementAndCheckPositionForRead(pos, copyBytes);
- checkBounds(dstOffsetFloats, lengthFloats, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_FLOAT_BASE_OFFSET + (((long) dstOffsetFloats) << FLOAT_SHIFT),
- copyBytes);
- }
+ public abstract void putBoolean(boolean value);
@Override
- public int getInt() {
- return getNativeOrderedInt();
- }
+ public abstract void putBoolean(long offsetBytes, boolean value);
@Override
- public int getInt(final long offsetBytes) {
- return getNativeOrderedInt(offsetBytes);
- }
+ public abstract void putBooleanArray(boolean[] srcArray, int srcOffsetBooleans,
+ int lengthBooleans);
@Override
- public void getIntArray(final int[] dstArray, final int dstOffsetInts, final int lengthInts) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- incrementAndCheckPositionForRead(pos, copyBytes);
- checkBounds(dstOffsetInts, lengthInts, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_INT_BASE_OFFSET + (((long) dstOffsetInts) << INT_SHIFT),
- copyBytes);
- }
+ public abstract void putByte(byte value);
@Override
- public long getLong() {
- return getNativeOrderedLong();
- }
+ public abstract void putByte(long offsetBytes, byte value);
@Override
- public long getLong(final long offsetBytes) {
- return getNativeOrderedLong(offsetBytes);
- }
+ public abstract void putByteArray(byte[] srcArray, int srcOffsetBytes, int lengthBytes);
@Override
- public void getLongArray(final long[] dstArray, final int dstOffsetLongs, final int lengthLongs) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- incrementAndCheckPositionForRead(pos, copyBytes);
- checkBounds(dstOffsetLongs, lengthLongs, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_LONG_BASE_OFFSET + (((long) dstOffsetLongs) << LONG_SHIFT),
- copyBytes);
- }
+ public abstract void putChar(char value);
@Override
- public short getShort() {
- return getNativeOrderedShort();
- }
+ public abstract void putChar(long offsetBytes, char value);
@Override
- public short getShort(final long offsetBytes) {
- return getNativeOrderedShort(offsetBytes);
- }
+ public abstract void putCharArray(char[] srcArray, int srcOffsetChars, int lengthChars);
@Override
- public void getShortArray(final short[] dstArray, final int dstOffsetShorts,
- final int lengthShorts) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- incrementAndCheckPositionForRead(pos, copyBytes);
- checkBounds(dstOffsetShorts, lengthShorts, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_SHORT_BASE_OFFSET + (((long) dstOffsetShorts) << SHORT_SHIFT),
- copyBytes);
- }
+ public abstract void putDouble(double value);
- //PRIMITIVE putX() and putXArray()
@Override
- public void putChar(final char value) {
- putNativeOrderedChar(value);
- }
+ public abstract void putDouble(long offsetBytes, double value);
@Override
- public void putChar(final long offsetBytes, final char value) {
- putNativeOrderedChar(offsetBytes, value);
- }
+ public abstract void putDoubleArray(double[] srcArray, int srcOffsetDoubles, int lengthDoubles);
@Override
- public void putCharArray(final char[] srcArray, final int srcOffsetChars, final int lengthChars) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- checkBounds(srcOffsetChars, lengthChars, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_CHAR_BASE_OFFSET + (((long) srcOffsetChars) << CHAR_SHIFT),
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
- }
+ public abstract void putFloat(float value);
@Override
- public void putDouble(final double value) {
- final long pos = getPosition();
- incrementAndAssertPositionForWrite(pos, ARRAY_DOUBLE_INDEX_SCALE);
- unsafe.putDouble(getUnsafeObject(), getCumulativeOffset(pos), value);
- }
+ public abstract void putFloat(long offsetBytes, float value);
@Override
- public void putDouble(final long offsetBytes, final double value) {
- assertValidAndBoundsForWrite(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
- unsafe.putDouble(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
- }
+ public abstract void putFloatArray(float[] srcArray, int srcOffsetFloats, int lengthFloats);
@Override
- public void putDoubleArray(final double[] srcArray, final int srcOffsetDoubles,
- final int lengthDoubles) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- checkBounds(srcOffsetDoubles, lengthDoubles, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_DOUBLE_BASE_OFFSET + (((long) srcOffsetDoubles) << DOUBLE_SHIFT),
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
- }
+ public abstract void putInt(int value);
@Override
- public void putFloat(final float value) {
- final long pos = getPosition();
- incrementAndAssertPositionForWrite(pos, ARRAY_FLOAT_INDEX_SCALE);
- unsafe.putFloat(getUnsafeObject(), getCumulativeOffset(pos), value);
- }
+ public abstract void putInt(long offsetBytes, int value);
@Override
- public void putFloat(final long offsetBytes, final float value) {
- assertValidAndBoundsForWrite(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
- unsafe.putFloat(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
- }
+ public abstract void putIntArray(int[] srcArray, int srcOffsetInts, int lengthInts);
@Override
- public void putFloatArray(final float[] srcArray, final int srcOffsetFloats,
- final int lengthFloats) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- checkBounds(srcOffsetFloats, lengthFloats, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_FLOAT_BASE_OFFSET + (((long) srcOffsetFloats) << FLOAT_SHIFT),
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
- }
+ public abstract void putLong(long value);
@Override
- public void putInt(final int value) {
- putNativeOrderedInt(value);
- }
+ public abstract void putLong(long offsetBytes, long value);
@Override
- public void putInt(final long offsetBytes, final int value) {
- putNativeOrderedInt(offsetBytes, value);
- }
+ public abstract void putLongArray(long[] srcArray, int srcOffsetLongs, int lengthLongs);
@Override
- public void putIntArray(final int[] srcArray, final int srcOffsetInts, final int lengthInts) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- checkBounds(srcOffsetInts, lengthInts, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_INT_BASE_OFFSET + (((long) srcOffsetInts) << INT_SHIFT),
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
- }
+ public abstract void putShort(short value);
@Override
- public void putLong(final long value) {
- putNativeOrderedLong(value);
- }
+ public abstract void putShort(long offsetBytes, short value);
@Override
- public void putLong(final long offsetBytes, final long value) {
- putNativeOrderedLong(offsetBytes, value);
- }
+ public abstract void putShortArray(short[] srcArray, int srcOffsetShorts, int lengthShorts);
+ //OTHER WRITE METHODS
@Override
- public void putLongArray(final long[] srcArray, final int srcOffsetLongs, final int lengthLongs) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- checkBounds(srcOffsetLongs, lengthLongs, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_LONG_BASE_OFFSET + (((long) srcOffsetLongs) << LONG_SHIFT),
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
- }
+ public abstract Object getArray();
@Override
- public void putShort(final short value) {
- putNativeOrderedShort(value);
- }
+ public abstract void clear();
@Override
- public void putShort(final long offsetBytes, final short value) {
- putNativeOrderedShort(offsetBytes, value);
- }
+ public abstract void fill(byte value);
+ //OTHER WRITABLE API METHODS
@Override
- public void putShortArray(final short[] srcArray, final int srcOffsetShorts,
- final int lengthShorts) {
- final long pos = getPosition();
- final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- checkBounds(srcOffsetShorts, lengthShorts, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_SHORT_BASE_OFFSET + (((long) srcOffsetShorts) << SHORT_SHIFT),
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
+ public MemoryRequestServer getMemoryRequestServer() {
+ return null;
}
+
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
index 4bc97c4..696d765 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
@@ -91,10 +91,10 @@ public abstract class WritableMemoryImpl extends MemoryImpl implements WritableM
//AS BUFFER
@Override
- public abstract WritableBuffer asWritableBuffer();
+ public abstract WritableBufferImpl asWritableBuffer();
@Override
- public abstract WritableBuffer asWritableBuffer(ByteOrder byteOrder);
+ public abstract WritableBufferImpl asWritableBuffer(ByteOrder byteOrder);
//ALLOCATE HEAP VIA AUTOMATIC BYTE ARRAY
public static WritableMemoryImpl allocate(final int capacityBytes) {
diff --git a/src/main/java/org/apache/datasketches/memory/internal/package-info.java b/src/main/java/org/apache/datasketches/memory/internal/package-info.java
index 2f8471a..d1ed819 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/package-info.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/package-info.java
@@ -28,8 +28,8 @@
*
* <ul><li>Two different access APIs: read-only {@link org.apache.datasketches.memory.internal.MemoryImpl} and
* {@link org.apache.datasketches.memory.internal.WritableMemoryImpl} for absolute offset access,
- * and read-only {@link org.apache.datasketches.memory.internal.Buffer} and
- * {@link org.apache.datasketches.memory.internal.WritableBuffer}
+ * and read-only {@link org.apache.datasketches.memory.internal.BufferImpl} and
+ * {@link org.apache.datasketches.memory.internal.WritableBufferImpl}
* for relative positional access (similar to ByteBuffer).</li>
*
* <li>Clean separation of Read-only API from Writable API, which makes writable versus read-only
@@ -71,7 +71,7 @@
*
* <p>The two different access APIs are:</p>
* <ul><li><i>MemoryImpl, WritableMemoryImpl</i>: Absolute offset addressing into a resource.</li>
- * <li><i>Buffer, WritableBuffer</i>: Position relative addressing into a resource.</li>
+ * <li><i>BufferImpl, WritableBufferImpl</i>: Position relative addressing into a resource.</li>
* </ul>
*
* <p>In addition, all combinations of access APIs and backing resources can be accessed via
@@ -149,10 +149,10 @@
* hard-to-find bug.</li>
* </ul>
*
- *<p>Moving back and forth between <i>MemoryImpl</i> and <i>Buffer</i>:</p>
+ *<p>Moving back and forth between <i>MemoryImpl</i> and <i>BufferImpl</i>:</p>
*<blockquote><pre>
* MemoryImpl mem = ...
- * Buffer buf = mem.asBuffer();
+ * BufferImpl buf = mem.asBuffer();
* ...
* MemoryImpl mem2 = buf.asMemory();
* ...
diff --git a/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java b/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
index 0f5f44e..ac2579a 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
@@ -22,7 +22,7 @@ package org.apache.datasketches.memory.test;
import static org.testng.Assert.fail;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -35,7 +35,7 @@ public class BaseBufferTest {
@Test
public void checkLimits() {
- Buffer buf = MemoryImpl.wrap(new byte[100]).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(new byte[100]).asBuffer();
buf.setStartPositionEnd(40, 45, 50);
buf.setStartPositionEnd(0, 0, 100);
try {
@@ -48,7 +48,7 @@ public class BaseBufferTest {
@Test
public void checkLimitsAndCheck() {
- Buffer buf = MemoryImpl.wrap(new byte[100]).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(new byte[100]).asBuffer();
buf.setAndCheckStartPositionEnd(40, 45, 50);
buf.setAndCheckStartPositionEnd(0, 0, 100);
try {
@@ -77,7 +77,7 @@ public class BaseBufferTest {
@Test
public void checkCheckValid() {
WritableMemoryImpl wmem;
- Buffer buf;
+ BufferImpl buf;
try (WritableHandle hand = WritableMemoryImpl.allocateDirect(100)) {
wmem = hand.get();
buf = wmem.asBuffer();
diff --git a/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java b/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
index 919265c..598710f 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
@@ -27,12 +27,12 @@ import static org.testng.Assert.fail;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Prim;
import org.apache.datasketches.memory.internal.StepBoolean;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -52,8 +52,8 @@ public class BaseStateTest {
assertFalse(wmem.isSameResource(null));
assertTrue(wmem.isSameResource(mem));
- WritableBuffer wbuf = wmem.asWritableBuffer();
- Buffer buf = wbuf;
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
+ BufferImpl buf = wbuf;
assertFalse(wbuf.isSameResource(null));
assertTrue(wbuf.isSameResource(buf));
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java b/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
index 4a19f56..b2a7f1d 100644
--- a/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
+++ b/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
@@ -26,10 +26,10 @@ import static org.testng.Assert.assertTrue;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -47,7 +47,7 @@ public class Buffer2Test {
}
bb.position(0);
- Buffer buffer = Buffer.wrap(bb.asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
+ BufferImpl buffer = BufferImpl.wrap(bb.asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
while (buffer.hasRemaining()) {
assertEquals(bb.get(), buffer.getByte());
}
@@ -67,7 +67,7 @@ public class Buffer2Test {
}
bb.position(0);
- Buffer buffer = Buffer.wrap(bb);
+ BufferImpl buffer = BufferImpl.wrap(bb);
while (buffer.hasRemaining()) {
assertEquals(bb.get(), buffer.getByte());
}
@@ -84,7 +84,7 @@ public class Buffer2Test {
byteArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(byteArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(byteArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(byteArray[i++], buffer.getByte());
@@ -107,7 +107,7 @@ public class Buffer2Test {
charArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(charArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(charArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(charArray[i++], buffer.getChar());
@@ -127,7 +127,7 @@ public class Buffer2Test {
shortArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(shortArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(shortArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(shortArray[i++], buffer.getShort());
@@ -147,7 +147,7 @@ public class Buffer2Test {
intArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(intArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(intArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(intArray[i++], buffer.getInt());
@@ -167,7 +167,7 @@ public class Buffer2Test {
longArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(longArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(longArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(longArray[i++], buffer.getLong());
@@ -187,7 +187,7 @@ public class Buffer2Test {
floatArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(floatArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(floatArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(floatArray[i++], buffer.getFloat());
@@ -207,7 +207,7 @@ public class Buffer2Test {
doubleArray[i] = i;
}
- Buffer buffer = MemoryImpl.wrap(doubleArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(doubleArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(doubleArray[i++], buffer.getDouble());
@@ -229,7 +229,7 @@ public class Buffer2Test {
}
}
- Buffer buffer = MemoryImpl.wrap(booleanArray).asBuffer();
+ BufferImpl buffer = MemoryImpl.wrap(booleanArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(booleanArray[i++], buffer.getBoolean());
@@ -254,7 +254,7 @@ public class Buffer2Test {
}
bb.position(10);
- Buffer buffer = Buffer.wrap(bb);
+ BufferImpl buffer = BufferImpl.wrap(bb);
while (buffer.hasRemaining()) {
assertEquals(bb.get(), buffer.getByte());
}
@@ -271,7 +271,7 @@ public class Buffer2Test {
}
bb.position(10);
- Buffer buffer = Buffer.wrap(bb);
+ BufferImpl buffer = BufferImpl.wrap(bb);
assertEquals(bb.hasRemaining(), buffer.hasRemaining());
assertEquals(bb.remaining(), buffer.getRemaining());
}
@@ -287,7 +287,7 @@ public class Buffer2Test {
}
bb.position(10);
- Buffer buffer = Buffer.wrap(bb);
+ BufferImpl buffer = BufferImpl.wrap(bb);
assertEquals(bb.position(), buffer.getPosition());
assertEquals(30, buffer.setPosition(30).getPosition());
assertEquals(40, buffer.incrementPosition(10).getPosition());
@@ -305,7 +305,7 @@ public class Buffer2Test {
}
bb.position(10);
- Buffer buffer = Buffer.wrap(bb.slice().order(ByteOrder.nativeOrder()));
+ BufferImpl buffer = BufferImpl.wrap(bb.slice().order(ByteOrder.nativeOrder()));
while (buffer.hasRemaining()) {
assertEquals(bb.get(), buffer.getByte());
}
@@ -327,10 +327,10 @@ public class Buffer2Test {
}
bb.position(10);
- Buffer buffer = Buffer.wrap(bb.slice().order(ByteOrder.nativeOrder())); //slice = 54
+ BufferImpl buffer = BufferImpl.wrap(bb.slice().order(ByteOrder.nativeOrder())); //slice = 54
buffer.setPosition(30);//remaining = 24
- Buffer dupBuffer = buffer.duplicate(); //all 54
- Buffer regionBuffer = buffer.region(); //24
+ BufferImpl dupBuffer = buffer.duplicate(); //all 54
+ BufferImpl regionBuffer = buffer.region(); //24
assertEquals(dupBuffer.getStart(), buffer.getStart());
assertEquals(regionBuffer.getStart(), buffer.getStart());
@@ -349,8 +349,8 @@ public class Buffer2Test {
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
MemoryImpl mem = MemoryImpl.wrap(arr);
- Buffer buf = mem.asBuffer();
- Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getTypeByteOrder()); //top half
+ BufferImpl buf = mem.asBuffer();
+ BufferImpl reg = buf.region(n2 * 8, n2 * 8, buf.getTypeByteOrder()); //top half
for (int i = 0; i < n2; i++) {
long v = reg.getLong(i * 8);
long e = i + n2;
@@ -369,7 +369,7 @@ public class Buffer2Test {
}
bb.position(10);
- Buffer buffer = Buffer.wrap(bb);
+ BufferImpl buffer = BufferImpl.wrap(bb);
MemoryImpl memory = buffer.asMemory();
assertEquals(buffer.getCapacity(), memory.getCapacity());
@@ -383,8 +383,8 @@ public class Buffer2Test {
public void testROByteBuffer() {
byte[] arr = new byte[64];
ByteBuffer roBB = ByteBuffer.wrap(arr).asReadOnlyBuffer();
- Buffer buf = Buffer.wrap(roBB);
- WritableBuffer wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(roBB);
+ WritableBufferImpl wbuf = (WritableBufferImpl) buf;
wbuf.putByte(0, (byte) 1);
}
@@ -392,8 +392,8 @@ public class Buffer2Test {
public void testROByteBuffer2() {
byte[] arr = new byte[64];
ByteBuffer roBB = ByteBuffer.wrap(arr).asReadOnlyBuffer();
- Buffer buf = Buffer.wrap(roBB);
- WritableBuffer wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(roBB);
+ WritableBufferImpl wbuf = (WritableBufferImpl) buf;
wbuf.putByteArray(arr, 0, 64);
}
@@ -401,18 +401,18 @@ public class Buffer2Test {
public void testIllegalFill() {
byte[] arr = new byte[64];
ByteBuffer roBB = ByteBuffer.wrap(arr).asReadOnlyBuffer();
- Buffer buf = Buffer.wrap(roBB);
- WritableBuffer wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(roBB);
+ WritableBufferImpl wbuf = (WritableBufferImpl) buf;
wbuf.fill((byte)0);
}
@Test
public void testWritableDuplicate() {
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(new byte[1]);
- WritableBuffer wbuf = wmem.asWritableBuffer();
- WritableBuffer wbuf2 = wbuf.writableDuplicate();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wbuf.writableDuplicate();
assertEquals(wbuf2.getCapacity(), 1);
- Buffer buf = wmem.asBuffer();
+ BufferImpl buf = wmem.asBuffer();
assertEquals(buf.getCapacity(), 1);
}
@@ -420,8 +420,8 @@ public class Buffer2Test {
public void checkIndependence() {
int cap = 64;
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(cap);
- WritableBuffer wbuf1 = wmem.asWritableBuffer();
- WritableBuffer wbuf2 = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf1 = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem.asWritableBuffer();
assertFalse(wbuf1 == wbuf2);
assertTrue(wbuf1.isSameResource(wbuf2));
@@ -431,8 +431,8 @@ public class Buffer2Test {
assertTrue(reg1.isSameResource(reg2));
- WritableBuffer wbuf3 = wbuf1.writableRegion();
- WritableBuffer wbuf4 = wbuf1.writableRegion();
+ WritableBufferImpl wbuf3 = wbuf1.writableRegion();
+ WritableBufferImpl wbuf4 = wbuf1.writableRegion();
assertFalse(wbuf3 == wbuf4);
assertTrue(wbuf3.isSameResource(wbuf4));
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
index d71419a..46f340d 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
@@ -25,8 +25,8 @@ import static org.testng.Assert.fail;
import java.nio.ByteBuffer;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -40,10 +40,10 @@ public class BufferInvariantsTest {
public void testRegion() {
ByteBuffer byteBuffer = ByteBuffer.allocate(10);
byteBuffer.limit(7);
- Buffer buff = Buffer.wrap(byteBuffer); //assuming buff has cap of 8
+ BufferImpl buff = BufferImpl.wrap(byteBuffer); //assuming buff has cap of 8
assertEquals(buff.getCapacity(), 10); //wrong should be 8
buff.getByte(); //pos moves to 1
- Buffer copyBuff = buff.region(); //pos: 0, start: 0, end: 6: cap: 7
+ BufferImpl copyBuff = buff.region(); //pos: 0, start: 0, end: 6: cap: 7
assertEquals(copyBuff.getEnd(), 6);
assertEquals(copyBuff.getCapacity(), 6);
assertEquals(copyBuff.getStart(), 0);
@@ -51,7 +51,7 @@ public class BufferInvariantsTest {
buff.setStartPositionEnd(1, 1, 5);
buff.getByte();
- Buffer copyBuff2 = buff.region();
+ BufferImpl copyBuff2 = buff.region();
assertEquals(copyBuff2.getEnd(), 3);
assertEquals(copyBuff2.getCapacity(), 3);
assertEquals(copyBuff2.getStart(), 0);
@@ -93,7 +93,7 @@ public class BufferInvariantsTest {
@Test
public void testBuf() {
int n = 25;
- WritableBuffer buf = WritableMemoryImpl.allocate(n).asWritableBuffer();
+ WritableBufferImpl buf = WritableMemoryImpl.allocate(n).asWritableBuffer();
for (byte i = 0; i < n; i++) { buf.putByte(i); }
buf.setPosition(0);
assertEquals(buf.getPosition(), 0);
@@ -110,7 +110,7 @@ public class BufferInvariantsTest {
// print("Set : ");
// printbuf(buf);
- Buffer dup = buf.duplicate();
+ BufferImpl dup = buf.duplicate();
assertEquals(dup.getRemaining(), 15);
assertEquals(dup.getCapacity(), 25);
assertEquals(dup.getByte(), 5);
@@ -119,7 +119,7 @@ public class BufferInvariantsTest {
// printbuf(dup);
- Buffer reg = buf.region();
+ BufferImpl reg = buf.region();
assertEquals(reg.getPosition(), 0);
assertEquals(reg.getEnd(), 15);
assertEquals(reg.getRemaining(), 15);
@@ -139,7 +139,7 @@ public class BufferInvariantsTest {
bb.position(5);
bb.limit(20);
- Buffer buf = Buffer.wrap(bb);
+ BufferImpl buf = BufferImpl.wrap(bb);
assertEquals(buf.getPosition(), 5);
assertEquals(buf.getEnd(), 20);
assertEquals(buf.getRemaining(), 15);
@@ -149,7 +149,7 @@ public class BufferInvariantsTest {
// print("Buf.wrap: ");
// printbuf(buf);
- Buffer reg = buf.region();
+ BufferImpl reg = buf.region();
assertEquals(reg.getPosition(), 0);
assertEquals(reg.getEnd(), 15);
assertEquals(reg.getRemaining(), 15);
@@ -164,7 +164,7 @@ public class BufferInvariantsTest {
public void checkLimitsDirect() {
try (WritableHandle hand = WritableMemoryImpl.allocateDirect(100)) {
WritableMemoryImpl wmem = hand.get();
- Buffer buf = wmem.asBuffer();
+ BufferImpl buf = wmem.asBuffer();
buf.setStartPositionEnd(40, 45, 50);
buf.setStartPositionEnd(0, 0, 100);
try {
@@ -180,10 +180,10 @@ public class BufferInvariantsTest {
public void testRegionDirect() {
ByteBuffer byteBuffer = ByteBuffer.allocate(10);
byteBuffer.limit(7);
- Buffer buff = Buffer.wrap(byteBuffer); //assuming buff has cap of 8
+ BufferImpl buff = BufferImpl.wrap(byteBuffer); //assuming buff has cap of 8
assertEquals(buff.getCapacity(), 10); //wrong should be 8
buff.getByte(); //pos moves to 1
- Buffer copyBuff = buff.region(); //pos: 0, start: 0, end: 6: cap: 7
+ BufferImpl copyBuff = buff.region(); //pos: 0, start: 0, end: 6: cap: 7
assertEquals(copyBuff.getEnd(), 6);
assertEquals(copyBuff.getCapacity(), 6);
assertEquals(copyBuff.getStart(), 0);
@@ -191,7 +191,7 @@ public class BufferInvariantsTest {
buff.setStartPositionEnd(1, 1, 5);
buff.getByte();
- Buffer copyBuff2 = buff.region();
+ BufferImpl copyBuff2 = buff.region();
assertEquals(copyBuff2.getEnd(), 3);
assertEquals(copyBuff2.getCapacity(), 3);
assertEquals(copyBuff2.getStart(), 0);
@@ -235,7 +235,7 @@ public class BufferInvariantsTest {
int n = 25;
try (WritableHandle whand = WritableMemoryImpl.allocateDirect(n)) {
WritableMemoryImpl wmem = whand.get();
- WritableBuffer buf = wmem.asWritableBuffer();
+ WritableBufferImpl buf = wmem.asWritableBuffer();
for (byte i = 0; i < n; i++) { buf.putByte(i); }
buf.setPosition(0);
assertEquals(buf.getPosition(), 0);
@@ -252,7 +252,7 @@ public class BufferInvariantsTest {
// print("Set : ");
// printbuf(buf);
- Buffer dup = buf.duplicate();
+ BufferImpl dup = buf.duplicate();
assertEquals(dup.getRemaining(), 15);
assertEquals(dup.getCapacity(), 25);
assertEquals(dup.getByte(), 5);
@@ -261,7 +261,7 @@ public class BufferInvariantsTest {
// printbuf(dup);
- Buffer reg = buf.region();
+ BufferImpl reg = buf.region();
assertEquals(reg.getPosition(), 0);
assertEquals(reg.getEnd(), 15);
assertEquals(reg.getRemaining(), 15);
@@ -282,7 +282,7 @@ public class BufferInvariantsTest {
bb.position(5);
bb.limit(20);
- Buffer buf = Buffer.wrap(bb);
+ BufferImpl buf = BufferImpl.wrap(bb);
assertEquals(buf.getPosition(), 5);
assertEquals(buf.getEnd(), 20);
assertEquals(buf.getRemaining(), 15);
@@ -292,7 +292,7 @@ public class BufferInvariantsTest {
// print("Buf.wrap: ");
// printbuf(buf);
- Buffer reg = buf.region();
+ BufferImpl reg = buf.region();
assertEquals(reg.getPosition(), 0);
assertEquals(reg.getEnd(), 15);
assertEquals(reg.getRemaining(), 15);
@@ -315,7 +315,7 @@ public class BufferInvariantsTest {
println(bb.get(i + pos) + "\n");
}
- static void printbuf(Buffer buf) {
+ static void printbuf(BufferImpl buf) {
println("pos: " + buf.getPosition() + ", end: " + buf.getEnd() + ", cap: " + buf.getCapacity());
long rem = buf.getRemaining();
long pos = buf.getPosition();
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
index 6d67e67..b076dee 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
@@ -21,18 +21,18 @@ package org.apache.datasketches.memory.test;
import java.nio.ByteBuffer;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class BufferReadWriteSafetyTest {
- // Test various operations with read-only Buffer
+ // Test various operations with read-only BufferImpl
- private final WritableBuffer buf = (WritableBuffer) Buffer.wrap(ByteBuffer.allocate(8));
+ private final WritableBufferImpl buf = (WritableBufferImpl) BufferImpl.wrap(ByteBuffer.allocate(8));
@Test(expectedExceptions = AssertionError.class)
public void testPutByte() {
@@ -158,19 +158,19 @@ public class BufferReadWriteSafetyTest {
@Test(expectedExceptions = AssertionError.class)
public void testWritableMemoryAsBuffer() {
- WritableBuffer buf1 = (WritableBuffer) WritableMemoryImpl.allocate(8).asBuffer();
+ WritableBufferImpl buf1 = (WritableBufferImpl) WritableMemoryImpl.allocate(8).asBuffer();
buf1.putInt(1);
}
@Test(expectedExceptions = AssertionError.class)
public void testWritableBufferRegion() {
- WritableBuffer buf1 = (WritableBuffer) WritableMemoryImpl.allocate(8).asWritableBuffer().region();
+ WritableBufferImpl buf1 = (WritableBufferImpl) WritableMemoryImpl.allocate(8).asWritableBuffer().region();
buf1.putInt(1);
}
@Test(expectedExceptions = AssertionError.class)
public void testWritableBufferDuplicate() {
- WritableBuffer buf1 = (WritableBuffer) WritableMemoryImpl.allocate(8).asWritableBuffer().duplicate();
+ WritableBufferImpl buf1 = (WritableBufferImpl) WritableMemoryImpl.allocate(8).asWritableBuffer().duplicate();
buf1.putInt(1);
}
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
index 38a4f31..123bbbf 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
@@ -26,9 +26,9 @@ import java.nio.ByteOrder;
import java.util.List;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
import org.testng.collections.Lists;
@@ -41,7 +41,7 @@ public class BufferTest {
int n = 1024; //longs
try (WritableHandle wh = WritableMemoryImpl.allocateDirect(n * 8)) {
WritableMemoryImpl wmem = wh.get();
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
}
@@ -56,7 +56,7 @@ public class BufferTest {
@Test
public void checkAutoHeapRoundTrip() {
int n = 1024; //longs
- WritableBuffer wbuf = WritableMemoryImpl.allocate(n * 8).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.allocate(n * 8).asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
}
@@ -71,7 +71,7 @@ public class BufferTest {
public void checkArrayWrap() {
int n = 1024; //longs
byte[] arr = new byte[n * 8];
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(arr).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(arr).asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
}
@@ -80,7 +80,7 @@ public class BufferTest {
long v = wbuf.getLong();
assertEquals(v, i);
}
- Buffer buf = MemoryImpl.wrap(arr).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(arr).asBuffer();
buf.resetPosition();
for (int i = 0; i < n; i++) {
long v = buf.getLong();
@@ -88,13 +88,13 @@ public class BufferTest {
}
// Check Zero length array wraps
MemoryImpl mem = MemoryImpl.wrap(new byte[0]);
- Buffer buffZeroLengthArrayWrap = mem.asBuffer();
+ BufferImpl buffZeroLengthArrayWrap = mem.asBuffer();
assertEquals(buffZeroLengthArrayWrap.getCapacity(), 0);
// check 0 length array wraps
- List<Buffer> buffersToCheck = Lists.newArrayList();
+ List<BufferImpl> buffersToCheck = Lists.newArrayList();
buffersToCheck.add(WritableMemoryImpl.allocate(0).asBuffer());
- buffersToCheck.add(WritableBuffer.wrap(ByteBuffer.allocate(0)));
- buffersToCheck.add(Buffer.wrap(ByteBuffer.allocate(0)));
+ buffersToCheck.add(WritableBufferImpl.writableWrap(ByteBuffer.allocate(0)));
+ buffersToCheck.add(BufferImpl.wrap(ByteBuffer.allocate(0)));
buffersToCheck.add(MemoryImpl.wrap(new boolean[0]).asBuffer());
buffersToCheck.add(MemoryImpl.wrap(new byte[0]).asBuffer());
buffersToCheck.add(MemoryImpl.wrap(new char[0]).asBuffer());
@@ -104,7 +104,7 @@ public class BufferTest {
buffersToCheck.add(MemoryImpl.wrap(new float[0]).asBuffer());
buffersToCheck.add(MemoryImpl.wrap(new double[0]).asBuffer());
//Check the buffer lengths
- for (Buffer buffer : buffersToCheck) {
+ for (BufferImpl buffer : buffersToCheck) {
assertEquals(buffer.getCapacity(), 0);
}
}
@@ -116,7 +116,7 @@ public class BufferTest {
ByteBuffer bb = ByteBuffer.wrap(arr);
bb.order(ByteOrder.nativeOrder());
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
for (int i = 0; i < n; i++) { //write to wbuf
wbuf.putLong(i);
}
@@ -138,7 +138,7 @@ public class BufferTest {
ByteBuffer bb = ByteBuffer.wrap(arr);
bb.order(ByteOrder.nativeOrder());
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
for (int i = 0; i < n; i++) { //write to wbuf
wbuf.putLong(i);
}
@@ -151,13 +151,13 @@ public class BufferTest {
long v = bb.getLong(i * 8);
assertEquals(v, i);
}
- Buffer buf1 = MemoryImpl.wrap(arr).asBuffer();
+ BufferImpl buf1 = MemoryImpl.wrap(arr).asBuffer();
for (int i = 0; i < n; i++) { //read from wrapped arr
long v = buf1.getLong();
assertEquals(v, i);
}
//convert to wbuf to RO
- Buffer buf = wbuf;
+ BufferImpl buf = wbuf;
buf.resetPosition();
for (int i = 0; i < n; i++) {
long v = buf.getLong();
@@ -171,7 +171,7 @@ public class BufferTest {
ByteBuffer bb = ByteBuffer.allocateDirect(n * 8);
bb.order(ByteOrder.nativeOrder());
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
for (int i = 0; i < n; i++) { //write to wmem
wbuf.putLong(i);
}
@@ -184,13 +184,13 @@ public class BufferTest {
long v = bb.getLong(i * 8);
assertEquals(v, i);
}
- Buffer buf1 = Buffer.wrap(bb);
+ BufferImpl buf1 = BufferImpl.wrap(bb);
for (int i = 0; i < n; i++) { //read from wrapped bb RO
long v = buf1.getLong();
assertEquals(v, i);
}
//convert to RO
- Buffer buf = wbuf;
+ BufferImpl buf = wbuf;
buf.resetPosition();
for (int i = 0; i < n; i++) {
long v = buf.getLong();
@@ -203,7 +203,7 @@ public class BufferTest {
int n = 1024; //longs
ByteBuffer bb = ByteBuffer.allocate(n * 8);
bb.order(ByteOrder.BIG_ENDIAN);
- Buffer buf = Buffer.wrap(bb);
+ BufferImpl buf = BufferImpl.wrap(bb);
assertEquals(buf.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@@ -217,7 +217,7 @@ public class BufferTest {
ByteBuffer slice = bb.slice().asReadOnlyBuffer();
slice.order(ByteOrder.nativeOrder());
- Buffer buf = Buffer.wrap(slice);
+ BufferImpl buf = BufferImpl.wrap(slice);
for (int i = 0; i < 64; i++) {
assertEquals(buf.getByte(), 64 + i);
}
@@ -231,7 +231,7 @@ public class BufferTest {
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableBuffer wbuf = WritableMemoryImpl.allocate(n * 8).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.allocate(n * 8).asWritableBuffer();
wbuf.putLongArray(arr, 0, n);
long[] arr2 = new long[n];
wbuf.resetPosition();
@@ -248,9 +248,9 @@ public class BufferTest {
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- Buffer buf = MemoryImpl.wrap(arr).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(arr).asBuffer();
buf.setPosition(n2 * 8);
- Buffer reg = buf.region();
+ BufferImpl reg = buf.region();
for (int i = 0; i < n2; i++) {
long v = reg.getLong();
assertEquals(v, i + n2);
@@ -264,14 +264,14 @@ public class BufferTest {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(arr).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(arr).asWritableBuffer();
for (int i = 0; i < n; i++) {
assertEquals(wbuf.getLong(), i); //write all
//println("" + wmem.getLong(i * 8));
}
//println("");
wbuf.setPosition(n2 * 8);
- WritableBuffer reg = wbuf.writableRegion();
+ WritableBufferImpl reg = wbuf.writableRegion();
for (int i = 0; i < n2; i++) { reg.putLong(i); } //rewrite top half
wbuf.resetPosition();
for (int i = 0; i < n; i++) {
@@ -286,7 +286,7 @@ public class BufferTest {
@SuppressWarnings("resource") //intentionally not using try-with-resources here
WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes);
WritableMemoryImpl wmem = wh.get();
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
wh.close();
//with -ea assert: MemoryImpl not valid.
//with -da sometimes segfaults, sometimes passes!
@@ -300,7 +300,7 @@ public class BufferTest {
WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes);
MemoryImpl wmem = wh.get();
- Buffer reg = wmem.asBuffer().region();
+ BufferImpl reg = wmem.asBuffer().region();
wh.close();
//with -ea assert: MemoryImpl not valid.
//with -da sometimes segfaults, sometimes passes!
@@ -309,7 +309,7 @@ public class BufferTest {
@Test(expectedExceptions = AssertionError.class)
public void checkBaseBufferInvariants() {
- WritableBuffer wbuf = WritableMemoryImpl.allocate(64).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.allocate(64).asWritableBuffer();
wbuf.setStartPositionEnd(1, 0, 2); //out of order
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java b/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
index 2f7f4fb..1e12d32 100644
--- a/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
@@ -22,7 +22,7 @@ package org.apache.datasketches.memory.test;
import static org.testng.Assert.assertEquals;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -34,14 +34,14 @@ public class CommonBufferTest {
int memCapacity = 60; //must be at least 60
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl mem = wrh.get();
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetTests(buf);
setGetTests2(buf);
}
}
- public static void setGetTests(WritableBuffer buf) {
+ public static void setGetTests(WritableBufferImpl buf) {
buf.putBoolean(true);
buf.putBoolean(false);
buf.putByte((byte) -1);
@@ -95,7 +95,7 @@ public class CommonBufferTest {
assertEquals(buf.getDouble(), Double.MIN_VALUE);
}
- public static void setGetTests2(WritableBuffer buf) {
+ public static void setGetTests2(WritableBufferImpl buf) {
buf.putBoolean(0, true);
buf.putBoolean(1, false);
buf.putByte(2, (byte) -1);
@@ -136,13 +136,13 @@ public class CommonBufferTest {
int memCapacity = 32;
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl mem = wrh.get();
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetArraysTests(buf);
}
}
- public static void setGetArraysTests(WritableBuffer buf) {
+ public static void setGetArraysTests(WritableBufferImpl buf) {
int words = 4;
boolean[] srcArray1 = {true, false, true, false};
@@ -233,13 +233,13 @@ public class CommonBufferTest {
int memCapacity = 32;
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl mem = wrh.get();
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetPartialArraysWithOffsetTests(buf);
}
}
- public static void setGetPartialArraysWithOffsetTests(WritableBuffer buf) {
+ public static void setGetPartialArraysWithOffsetTests(WritableBufferImpl buf) {
int items= 4;
boolean[] srcArray1 = {true, false, true, false};
boolean[] dstArray1 = new boolean[items];
@@ -327,7 +327,7 @@ public class CommonBufferTest {
int memCapacity = 64; //must be 64
try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl mem = wrh1.get();
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setClearMemoryRegionsTests(buf); //requires println enabled to visually check
@@ -339,7 +339,7 @@ public class CommonBufferTest {
}
//enable println statements to visually check
- public static void setClearMemoryRegionsTests(WritableBuffer buf) {
+ public static void setClearMemoryRegionsTests(WritableBufferImpl buf) {
int accessCapacity = (int)buf.getCapacity();
//define regions
@@ -416,14 +416,14 @@ public class CommonBufferTest {
int memCapacity = 48; //must be 48
try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl mem = wrh1.get();
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
toHexStringAllMemTests(buf); //requires println enabled to visually check
}
}
//enable println to visually check
- public static void toHexStringAllMemTests(WritableBuffer buf) {
+ public static void toHexStringAllMemTests(WritableBufferImpl buf) {
int memCapacity = (int)buf.getCapacity();
for (int i=0; i<memCapacity; i++) {
diff --git a/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java b/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
index c25ea06..19f8b8c 100644
--- a/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
@@ -32,7 +32,7 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.WritableDirectHandle;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.apache.datasketches.memory.WritableMapHandle;
@@ -71,7 +71,7 @@ public class LeafImplTest {
//assertTrue(mem.getUnsafeObject() == null);
assertTrue(mem.isValid() == true);
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(buf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -101,7 +101,7 @@ public class LeafImplTest {
//assertTrue(nnMem.getUnsafeObject() == null);
assertTrue(nnMem.isValid() == true);
- WritableBuffer nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
+ WritableBufferImpl nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
assertEquals(nnBuf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnBuf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -156,7 +156,7 @@ public class LeafImplTest {
//assertTrue(mem.getUnsafeObject() == null);
assertTrue(mem.isValid() == true);
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(buf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -186,7 +186,7 @@ public class LeafImplTest {
//assertTrue(nnMem.getUnsafeObject() == null);
assertTrue(nnMem.isValid() == true);
- WritableBuffer nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
+ WritableBufferImpl nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
assertEquals(nnBuf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnBuf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -239,7 +239,7 @@ public class LeafImplTest {
}
assertTrue(mem.isValid() == true);
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(buf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -281,7 +281,7 @@ public class LeafImplTest {
}
assertTrue(nnMem.isValid() == true);
- WritableBuffer nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
+ WritableBufferImpl nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
assertEquals(nnBuf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnBuf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -326,7 +326,7 @@ public class LeafImplTest {
//assertTrue(mem.getUnsafeObject() != null);
assertTrue(mem.isValid() == true);
- WritableBuffer buf = mem.asWritableBuffer();
+ WritableBufferImpl buf = mem.asWritableBuffer();
assertEquals(buf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(buf.writableRegion(off, cap, BE).getShort(0), 256);
@@ -356,7 +356,7 @@ public class LeafImplTest {
//assertTrue(nnMem.getUnsafeObject() != null);
assertTrue(nnMem.isValid() == true);
- WritableBuffer nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
+ WritableBufferImpl nnBuf = mem.asWritableBuffer(Util.nonNativeByteOrder);
assertEquals(nnBuf.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnBuf.writableRegion(off, cap, BE).getShort(0), 256);
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java b/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
index 4137c71..7654af8 100644
--- a/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
@@ -19,14 +19,14 @@
package org.apache.datasketches.memory.test;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class MemoryBoundaryCheckTest {
- private final WritableBuffer writableBuffer = WritableMemoryImpl.allocate(8).asWritableBuffer();
+ private final WritableBufferImpl writableBuffer = WritableMemoryImpl.allocate(8).asWritableBuffer();
@Test
public void testGetBoolean() {
diff --git a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java b/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
index aa22700..84c2f1c 100644
--- a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
@@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -42,7 +42,7 @@ public class NonNativeWritableBufferImplTest {
byte[] arr1 = new byte[n * m]; //non-native
//put & get
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
char ch = 'a';
for (int i = 0; i < n; i++) { wbuf.putChar(i * m, ch++); }
ch = 'a';
@@ -63,7 +63,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.getCharArray(cArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf2 = wmem2.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem2.asWritableBuffer();
wbuf2.putCharArray(cArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -75,7 +75,7 @@ public class NonNativeWritableBufferImplTest {
byte[] arr1 = new byte[n * m]; //non-native
//put & get
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
double dbl = 1.0;
for (int i = 0; i < n; i++) { wbuf.putDouble(i * m, dbl++); }
dbl = 1.0;
@@ -96,7 +96,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.getDoubleArray(dblArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf2 = wmem2.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem2.asWritableBuffer();
wbuf2.putDoubleArray(dblArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -108,7 +108,7 @@ public class NonNativeWritableBufferImplTest {
byte[] arr1 = new byte[n * m]; //non-native
//put & get
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
float flt = 1.0F;
for (int i = 0; i < n; i++) { wbuf.putFloat(i * m, flt++); }
flt = 1.0F;
@@ -129,7 +129,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.getFloatArray(fltArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf2 = wmem2.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem2.asWritableBuffer();
wbuf2.putFloatArray(fltArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -141,7 +141,7 @@ public class NonNativeWritableBufferImplTest {
byte[] arr1 = new byte[n * m]; //non-native
//put & get
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
int intg = 1;
for (int i = 0; i < n; i++) { wbuf.putInt(i * m, intg++); }
intg = 1;
@@ -162,7 +162,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.getIntArray(intArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf2 = wmem2.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem2.asWritableBuffer();
wbuf2.putIntArray(intArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -174,7 +174,7 @@ public class NonNativeWritableBufferImplTest {
byte[] arr1 = new byte[n * m]; //non-native
//put & get
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
long lng = 1;
for (int i = 0; i < n; i++) { wbuf.putLong(i * m, lng++); }
lng = 1;
@@ -195,7 +195,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.getLongArray(longArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf2 = wmem2.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem2.asWritableBuffer();
wbuf2.putLongArray(longArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -207,7 +207,7 @@ public class NonNativeWritableBufferImplTest {
byte[] arr1 = new byte[n * m]; //non-native
//put & get
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
short sht = 1;
for (int i = 0; i < n; i++) { wbuf.putShort(i * m, sht++); }
sht = 1;
@@ -228,7 +228,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.getShortArray(shortArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf2 = wmem2.asWritableBuffer();
+ WritableBufferImpl wbuf2 = wmem2.asWritableBuffer();
wbuf2.putShortArray(shortArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -238,11 +238,11 @@ public class NonNativeWritableBufferImplTest {
public void checkDuplicate() {
byte[] bArr = new byte[8];
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
- WritableBuffer wbuf = wmem.asWritableBuffer();
- WritableBuffer wdup = wbuf.writableDuplicate();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wdup = wbuf.writableDuplicate();
assertEquals(wdup.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
- WritableBuffer wreg = wbuf.writableRegion();
+ WritableBufferImpl wreg = wbuf.writableRegion();
assertEquals(wreg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@@ -250,11 +250,11 @@ public class NonNativeWritableBufferImplTest {
public void checkDuplicateZeros() {
byte[] bArr = new byte[0];
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
- Buffer buf = wmem.asBuffer();
- Buffer dup = buf.duplicate();
+ BufferImpl buf = wmem.asBuffer();
+ BufferImpl dup = buf.duplicate();
assertEquals(dup.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
- Buffer reg = buf.region();
+ BufferImpl reg = buf.region();
assertEquals(reg.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java b/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
index 6436164..a1e5ce7 100644
--- a/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
@@ -26,7 +26,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
@@ -50,12 +50,12 @@ public class SpecificLeafTest {
assertTrue(ReflectUtil.isBBType(mem));
assertTrue(mem.isReadOnly());
checkCrossLeafTypeIds(mem);
- Buffer buf = mem.asBuffer().region(0, bytes, Util.nativeByteOrder);
+ BufferImpl buf = mem.asBuffer().region(0, bytes, Util.nativeByteOrder);
bb.order(Util.nonNativeByteOrder);
MemoryImpl mem2 = MemoryImpl.wrap(bb).region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf2 = mem2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf3 = buf2.duplicate();
+ BufferImpl buf2 = mem2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
+ BufferImpl buf3 = buf2.duplicate();
assertTrue(ReflectUtil.isRegionType(mem));
assertTrue(ReflectUtil.isRegionType(mem2));
@@ -75,12 +75,12 @@ public class SpecificLeafTest {
WritableMemoryImpl nnwmem = wmem.writableRegion(0, bytes, Util.nonNativeByteOrder);
MemoryImpl mem = wmem.region(0, bytes, Util.nativeByteOrder);
- Buffer buf = mem.asBuffer().region(0, bytes, Util.nativeByteOrder);
+ BufferImpl buf = mem.asBuffer().region(0, bytes, Util.nativeByteOrder);
MemoryImpl mem2 = nnwmem.region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf2 = mem2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf3 = buf2.duplicate();
+ BufferImpl buf2 = mem2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
+ BufferImpl buf3 = buf2.duplicate();
assertTrue(ReflectUtil.isRegionType(mem));
assertTrue(ReflectUtil.isRegionType(mem2));
@@ -115,12 +115,12 @@ public class SpecificLeafTest {
MemoryImpl nnreg = mem.region(0, bytes, Util.nonNativeByteOrder);
MemoryImpl reg = mem.region(0, bytes, Util.nativeByteOrder);
- Buffer buf = reg.asBuffer().region(0, bytes, Util.nativeByteOrder);
- Buffer buf4 = buf.duplicate();
+ BufferImpl buf = reg.asBuffer().region(0, bytes, Util.nativeByteOrder);
+ BufferImpl buf4 = buf.duplicate();
MemoryImpl reg2 = nnreg.region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf3 = buf2.duplicate();
+ BufferImpl buf2 = reg2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
+ BufferImpl buf3 = buf2.duplicate();
assertTrue(ReflectUtil.isRegionType(reg));
assertTrue(ReflectUtil.isRegionType(reg2));
@@ -141,12 +141,12 @@ public class SpecificLeafTest {
MemoryImpl nnreg = mem.region(0, bytes, Util.nonNativeByteOrder);
MemoryImpl reg = mem.region(0, bytes, Util.nativeByteOrder);
- Buffer buf = reg.asBuffer().region(0, bytes, Util.nativeByteOrder);
- Buffer buf4 = buf.duplicate();
+ BufferImpl buf = reg.asBuffer().region(0, bytes, Util.nativeByteOrder);
+ BufferImpl buf4 = buf.duplicate();
MemoryImpl reg2 = nnreg.region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
- Buffer buf3 = buf2.duplicate();
+ BufferImpl buf2 = reg2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
+ BufferImpl buf3 = buf2.duplicate();
assertFalse(ReflectUtil.isRegionType(mem));
assertTrue(ReflectUtil.isRegionType(reg2));
@@ -160,11 +160,11 @@ public class SpecificLeafTest {
MemoryImpl reg1 = mem.region(0, mem.getCapacity());
assertTrue(ReflectUtil.isRegionType(reg1));
- Buffer buf1 = reg1.asBuffer();
+ BufferImpl buf1 = reg1.asBuffer();
assertTrue(ReflectUtil.isRegionType(buf1));
assertTrue(ReflectUtil.isBufferType(buf1));
- Buffer buf2 = buf1.duplicate();
+ BufferImpl buf2 = buf1.duplicate();
assertTrue(ReflectUtil.isRegionType(buf2));
assertTrue(ReflectUtil.isBufferType(buf2));
assertTrue(ReflectUtil.isDuplicateType(buf2));
@@ -174,7 +174,7 @@ public class SpecificLeafTest {
assertFalse(ReflectUtil.isBufferType(mem2));
assertFalse(ReflectUtil.isDuplicateType(mem2));
- Buffer buf3 = buf1.duplicate(Util.nonNativeByteOrder);
+ BufferImpl buf3 = buf1.duplicate(Util.nonNativeByteOrder);
assertTrue(ReflectUtil.isRegionType(buf3));
assertTrue(ReflectUtil.isBufferType(buf3));
assertTrue(ReflectUtil.isDuplicateType(buf3));
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java
index 7593be8..18a43da 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java
@@ -27,12 +27,12 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.UnsafeUtil;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -48,7 +48,7 @@ public class WritableBufferImplTest {
int memCapacity = 64;
WritableHandle wmh = WritableMemoryImpl.allocateDirect(memCapacity);
WritableMemoryImpl wmem = wmh.get();
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
assertEquals(wbuf.getCapacity(), memCapacity);
wmh.close(); //intentional
@@ -64,13 +64,13 @@ public class WritableBufferImplTest {
boolean[] srcArray = { true, false, true, false, false, true, true, false };
boolean[] dstArray = new boolean[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getBooleanArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getBooleanArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -83,13 +83,13 @@ public class WritableBufferImplTest {
byte[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
byte[] dstArray = new byte[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getByteArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getByteArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -101,13 +101,13 @@ public class WritableBufferImplTest {
char[] srcArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
char[] dstArray = new char[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getCharArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getCharArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -119,13 +119,13 @@ public class WritableBufferImplTest {
short[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
short[] dstArray = new short[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getShortArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getShortArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -137,13 +137,13 @@ public class WritableBufferImplTest {
int[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
int[] dstArray = new int[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getIntArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getIntArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -155,13 +155,13 @@ public class WritableBufferImplTest {
long[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
long[] dstArray = new long[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getLongArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getLongArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -173,13 +173,13 @@ public class WritableBufferImplTest {
float[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
float[] dstArray = new float[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getFloatArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getFloatArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -191,13 +191,13 @@ public class WritableBufferImplTest {
double[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
double[] dstArray = new double[8];
- Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
+ BufferImpl buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getDoubleArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getDoubleArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -209,7 +209,7 @@ public class WritableBufferImplTest {
int memCapacity = 64;
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl wmem = wrh.get();
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
wbuf.toHexString("Force Assertion Error", memCapacity, 8);
} catch (IllegalArgumentException e) {
//ok
@@ -221,7 +221,7 @@ public class WritableBufferImplTest {
long memCapacity = 64;
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl wmem = wrh.get();
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
byte[] srcArray = { 1, -2, 3, -4 };
wbuf.putByteArray(srcArray, 0, 5); //wrong!
} catch (IllegalArgumentException e) {
@@ -235,7 +235,7 @@ public class WritableBufferImplTest {
int memCapacity = 64;
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl wmem = wrh.get();
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
wbuf.writableRegion(1, 64, wbuf.getTypeByteOrder()); //wrong!
}
}
@@ -250,7 +250,7 @@ public class WritableBufferImplTest {
byteBuf.put(i, (byte) i);
}
- WritableBuffer wbuf = WritableBuffer.wrap(byteBuf);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(byteBuf);
for (int i=0; i<memCapacity; i++) {
assertEquals(wbuf.getByte(), byteBuf.get(i));
@@ -272,7 +272,7 @@ public class WritableBufferImplTest {
byteBuf.put(i, (byte) i);
}
- Buffer buf = WritableBuffer.wrap(byteBuf);
+ BufferImpl buf = WritableBufferImpl.writableWrap(byteBuf);
for (int i = 0; i < memCapacity; i++) {
assertEquals(buf.getByte(), byteBuf.get(i));
@@ -288,7 +288,7 @@ public class WritableBufferImplTest {
byteBuf.order(ByteOrder.nativeOrder());
ByteBuffer byteBufRO = byteBuf.asReadOnlyBuffer();
- WritableBuffer.wrap(byteBufRO);
+ WritableBufferImpl.writableWrap(byteBufRO);
}
@Test
@@ -303,7 +303,7 @@ public class WritableBufferImplTest {
ByteBuffer byteBufRO = byteBuf.asReadOnlyBuffer();
byteBufRO.order(ByteOrder.nativeOrder());
- Buffer buf = Buffer.wrap(byteBufRO);
+ BufferImpl buf = BufferImpl.wrap(byteBufRO);
for (int i = 0; i < memCapacity; i++) {
assertEquals(buf.getByte(), byteBuf.get(i));
@@ -319,7 +319,7 @@ public class WritableBufferImplTest {
ByteBuffer byteBufRO = byteBuf.asReadOnlyBuffer();
byteBufRO.order(ByteOrder.nativeOrder());
- WritableBuffer.wrap(byteBufRO);
+ WritableBufferImpl.writableWrap(byteBufRO);
}
@Test
@@ -332,7 +332,7 @@ public class WritableBufferImplTest {
byteBuf.put(i, (byte) i);
}
- Buffer buf = Buffer.wrap(byteBuf);
+ BufferImpl buf = BufferImpl.wrap(byteBuf);
for (int i=0; i<memCapacity; i++) {
assertEquals(buf.getByte(), byteBuf.get(i));
@@ -344,11 +344,11 @@ public class WritableBufferImplTest {
@Test
public void checkIsDirect() {
int memCapacity = 64;
- WritableBuffer mem = WritableMemoryImpl.allocate(memCapacity).asWritableBuffer();
+ WritableBufferImpl mem = WritableMemoryImpl.allocate(memCapacity).asWritableBuffer();
assertFalse(mem.isDirect());
try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
WritableMemoryImpl mem2 = wrh.get();
- WritableBuffer wbuf = mem2.asWritableBuffer();
+ WritableBufferImpl wbuf = mem2.asWritableBuffer();
assertTrue(wbuf.isDirect());
wrh.close();
}
@@ -358,10 +358,10 @@ public class WritableBufferImplTest {
public void checkIsReadOnly() {
long[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
- WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
+ WritableBufferImpl wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
assertFalse(wbuf.isReadOnly());
- Buffer buf = wbuf;
+ BufferImpl buf = wbuf;
assertFalse(buf.isReadOnly());
for (int i = 0; i < srcArray.length; i++) {
@@ -380,9 +380,9 @@ public class WritableBufferImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- Buffer buf1 = MemoryImpl.wrap(arr1).asBuffer();
- Buffer buf2 = MemoryImpl.wrap(arr2).asBuffer();
- Buffer buf3 = MemoryImpl.wrap(arr3).asBuffer();
+ BufferImpl buf1 = MemoryImpl.wrap(arr1).asBuffer();
+ BufferImpl buf2 = MemoryImpl.wrap(arr2).asBuffer();
+ BufferImpl buf3 = MemoryImpl.wrap(arr3).asBuffer();
int comp = buf1.compareTo(0, 3, buf2, 0, 3);
assertEquals(comp, 0);
@@ -416,9 +416,9 @@ public class WritableBufferImplTest {
WritableMemoryImpl mem3 = h3.get();
mem3.putByteArray(0, arr3, 0, 5);
- Buffer buf1 = mem1.asBuffer();
- Buffer buf2 = mem2.asBuffer();
- Buffer buf3 = mem3.asBuffer();
+ BufferImpl buf1 = mem1.asBuffer();
+ BufferImpl buf2 = mem2.asBuffer();
+ BufferImpl buf3 = mem3.asBuffer();
int comp = buf1.compareTo(0, 3, buf2, 0, 3);
assertEquals(comp, 0);
@@ -437,12 +437,12 @@ public class WritableBufferImplTest {
@Test
public void checkAsBuffer() {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
wbuf.setPosition(32);
for (int i = 32; i < 64; i++) { wbuf.putByte((byte)i); }
//println(wbuf.toHexString("Buf", 0, (int)wbuf.getCapacity()));
- Buffer buf = wmem.asBuffer();
+ BufferImpl buf = wmem.asBuffer();
buf.setPosition(32);
for (int i = 32; i < 64; i++) {
assertEquals(buf.getByte(), i);
@@ -454,12 +454,12 @@ public class WritableBufferImplTest {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
for (int i = 0; i < 64; i++) { wmem.putByte(i, (byte)i); }
- WritableBuffer wbuf = wmem.asWritableBuffer().writableDuplicate();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer().writableDuplicate();
wbuf.checkValidAndBounds(0, 64);
for (int i = 0; i < 64; i++) {
assertEquals(wbuf.getByte(), i);
}
- Buffer buf = wmem.asBuffer().duplicate();
+ BufferImpl buf = wmem.asBuffer().duplicate();
for (int i = 0; i < 64; i++) {
assertEquals(buf.getByte(), i);
}
@@ -476,7 +476,7 @@ public class WritableBufferImplTest {
public void checkCumAndRegionOffset() {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
WritableMemoryImpl reg = wmem.writableRegion(32, 32);
- WritableBuffer buf = reg.asWritableBuffer();
+ WritableBufferImpl buf = reg.asWritableBuffer();
assertEquals(buf.getRegionOffset(), 32);
assertEquals(buf.getRegionOffset(0), 32);
assertEquals(buf.getCumulativeOffset(), 32 + 16);
@@ -486,29 +486,29 @@ public class WritableBufferImplTest {
@Test
public void checkIsSameResource() {
byte[] byteArr = new byte[64];
- WritableBuffer wbuf1 = WritableMemoryImpl.writableWrap(byteArr).asWritableBuffer();
- WritableBuffer wbuf2 = WritableMemoryImpl.writableWrap(byteArr).asWritableBuffer();
+ WritableBufferImpl wbuf1 = WritableMemoryImpl.writableWrap(byteArr).asWritableBuffer();
+ WritableBufferImpl wbuf2 = WritableMemoryImpl.writableWrap(byteArr).asWritableBuffer();
assertTrue(wbuf1.isSameResource(wbuf2));
}
@Test
public void checkDegenerateRegionReturn() {
MemoryImpl mem = MemoryImpl.wrap(new byte[0]);
- Buffer buf = mem.asBuffer();
- Buffer reg = buf.region();
+ BufferImpl buf = mem.asBuffer();
+ BufferImpl reg = buf.region();
assertEquals(reg.getCapacity(), 0);
}
@Test
public void checkAsWritableMemoryRO() {
ByteBuffer bb = ByteBuffer.allocate(64);
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
@SuppressWarnings("unused")
WritableMemoryImpl wmem = wbuf.asWritableMemory();
try {
- Buffer buf = Buffer.wrap(bb);
- wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(bb);
+ wbuf = (WritableBufferImpl) buf;
@SuppressWarnings("unused")
WritableMemoryImpl wmem2 = wbuf.asWritableMemory();
Assert.fail();
@@ -520,15 +520,15 @@ public class WritableBufferImplTest {
@Test
public void checkWritableDuplicateRO() {
ByteBuffer bb = ByteBuffer.allocate(64);
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
@SuppressWarnings("unused")
- WritableBuffer wdup = wbuf.writableDuplicate();
+ WritableBufferImpl wdup = wbuf.writableDuplicate();
try {
- Buffer buf = Buffer.wrap(bb);
- wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(bb);
+ wbuf = (WritableBufferImpl) buf;
@SuppressWarnings("unused")
- WritableBuffer wdup2 = wbuf.writableDuplicate();
+ WritableBufferImpl wdup2 = wbuf.writableDuplicate();
Assert.fail();
} catch (ReadOnlyException expected) {
// ignore
@@ -538,15 +538,15 @@ public class WritableBufferImplTest {
@Test
public void checkWritableRegionRO() {
ByteBuffer bb = ByteBuffer.allocate(64);
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
@SuppressWarnings("unused")
- WritableBuffer wreg = wbuf.writableRegion();
+ WritableBufferImpl wreg = wbuf.writableRegion();
try {
- Buffer buf = Buffer.wrap(bb);
- wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(bb);
+ wbuf = (WritableBufferImpl) buf;
@SuppressWarnings("unused")
- WritableBuffer wreg2 = wbuf.writableRegion();
+ WritableBufferImpl wreg2 = wbuf.writableRegion();
Assert.fail();
} catch (ReadOnlyException expected) {
// ignore
@@ -556,15 +556,15 @@ public class WritableBufferImplTest {
@Test
public void checkWritableRegionWithParamsRO() {
ByteBuffer bb = ByteBuffer.allocate(64);
- WritableBuffer wbuf = WritableBuffer.wrap(bb);
+ WritableBufferImpl wbuf = WritableBufferImpl.writableWrap(bb);
@SuppressWarnings("unused")
- WritableBuffer wreg = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
+ WritableBufferImpl wreg = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
try {
- Buffer buf = Buffer.wrap(bb);
- wbuf = (WritableBuffer) buf;
+ BufferImpl buf = BufferImpl.wrap(bb);
+ wbuf = (WritableBufferImpl) buf;
@SuppressWarnings("unused")
- WritableBuffer wreg2 = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
+ WritableBufferImpl wreg2 = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
Assert.fail();
} catch (ReadOnlyException expected) {
// ignore
@@ -574,8 +574,8 @@ public class WritableBufferImplTest {
@Test
public void checkZeroBuffer() {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(8);
- WritableBuffer wbuf = wmem.asWritableBuffer();
- WritableBuffer reg = wbuf.writableRegion(0, 0, wbuf.getTypeByteOrder());
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl reg = wbuf.writableRegion(0, 0, wbuf.getTypeByteOrder());
assertEquals(reg.getCapacity(), 0);
}
@@ -583,7 +583,7 @@ public class WritableBufferImplTest {
public void checkDuplicateNonNative() {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
wmem.putShort(0, (short) 1);
- Buffer buf = wmem.asWritableBuffer().duplicate(Util.nonNativeByteOrder);
+ BufferImpl buf = wmem.asWritableBuffer().duplicate(Util.nonNativeByteOrder);
assertEquals(buf.getShort(0), 256);
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java
index ccf994e..2cb8460 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java
@@ -28,12 +28,12 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.BufferImpl;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.UnsafeUtil;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -642,12 +642,12 @@ public class WritableMemoryImplTest {
@Test
public void checkAsBuffer() {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
wbuf.setPosition(32);
for (int i = 32; i < 64; i++) { wbuf.putByte((byte)i); }
//println(wbuf.toHexString("Buf", 0, (int)wbuf.getCapacity()));
- Buffer buf = wmem.asBuffer();
+ BufferImpl buf = wmem.asBuffer();
buf.setPosition(32);
for (int i = 32; i < 64; i++) {
assertEquals(buf.getByte(), i);
@@ -678,7 +678,7 @@ public class WritableMemoryImplTest {
byteBuf.position(16);
byteBuf.limit(48);
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(byteBuf);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
assertEquals(wbuf.getCapacity(), 64);
assertEquals(wbuf.getPosition(), 0);
assertEquals(wbuf.getEnd(), 64);
@@ -708,7 +708,7 @@ public class WritableMemoryImplTest {
public void checkAsBufferNonNative() {
WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
wmem.putShort(0, (short) 1);
- Buffer buf = wmem.asBuffer(Util.nonNativeByteOrder);
+ BufferImpl buf = wmem.asBuffer(Util.nonNativeByteOrder);
assertEquals(buf.getShort(0), 256);
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
index 988d2ee..e0765a9 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
@@ -29,7 +29,7 @@ import java.util.concurrent.ThreadLocalRandom;
import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableBufferImpl;
import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@@ -64,7 +64,7 @@ public class WritableMemoryTest {
byte[] byteArr = new byte[64];
WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(byteArr);
assertTrue(wmem.getArray() == byteArr);
- WritableBuffer wbuf = wmem.asWritableBuffer();
+ WritableBufferImpl wbuf = wmem.asWritableBuffer();
assertTrue(wbuf.getArray() == byteArr);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org