Skip to content

Commit

Permalink
Add Java9 overrides to specialize return types (#19)
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
niloc132 authored Jun 7, 2024
1 parent 7c35f2c commit e93a75c
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/java/nio/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final int capacity () {
*
* @return this buffer.
*/
public final Buffer clear () {
public Buffer clear() {
position = 0;
mark = UNSET_MARK;
limit = capacity;
Expand All @@ -100,7 +100,7 @@ public final Buffer clear () {
*
* @return this buffer.
*/
public final Buffer flip () {
public Buffer flip() {
limit = position;
position = 0;
mark = UNSET_MARK;
Expand Down Expand Up @@ -139,7 +139,7 @@ public final int limit () {
* @return this buffer.
* @exception IllegalArgumentException if <code>newLimit</code> is invalid.
*/
public final Buffer limit (int newLimit) {
public Buffer limit(int newLimit) {
if (newLimit < 0 || newLimit > capacity) {
throw new IllegalArgumentException();
}
Expand All @@ -159,7 +159,7 @@ public final Buffer limit (int newLimit) {
*
* @return this buffer.
*/
public final Buffer mark () {
public Buffer mark() {
mark = position;
return this;
}
Expand All @@ -179,7 +179,7 @@ public final int position () {
* @return this buffer.
* @exception IllegalArgumentException if <code>newPosition</code> is invalid.
*/
public final Buffer position (int newPosition) {
public Buffer position(int newPosition) {
if (newPosition < 0 || newPosition > limit) {
throw new IllegalArgumentException();
}
Expand All @@ -204,7 +204,7 @@ public final int remaining () {
* @return this buffer.
* @exception InvalidMarkException if the mark is not set.
*/
public final Buffer reset () {
public Buffer reset() {
if (mark == UNSET_MARK) {
throw new InvalidMarkException();
}
Expand All @@ -218,7 +218,7 @@ public final Buffer reset () {
*
* @return this buffer.
*/
public final Buffer rewind () {
public Buffer rewind() {
position = 0;
mark = UNSET_MARK;
return this;
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/java/nio/ByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import elemental2.core.ArrayBuffer;
import elemental2.core.ArrayBufferView;
import elemental2.core.Int8Array;
import jsinterop.base.Js;
import org.gwtproject.nio.HasArrayBufferView;
import org.gwtproject.nio.Numbers;
import org.gwtproject.nio.TypedArrayHelper;
Expand Down Expand Up @@ -558,6 +559,41 @@ public int hashCode () {
return hash;
}

@Override
public ByteBuffer limit(int newLimit) {
return Js.uncheckedCast(super.limit(newLimit));
}

@Override
public ByteBuffer position(int newPosition) {
return Js.uncheckedCast(super.position(newPosition));
}

@Override
public ByteBuffer mark() {
return Js.uncheckedCast(super.mark());
}

@Override
public ByteBuffer reset() {
return Js.uncheckedCast(super.reset());
}

@Override
public ByteBuffer clear() {
return Js.uncheckedCast(super.clear());
}

@Override
public ByteBuffer flip() {
return Js.uncheckedCast(super.flip());
}

@Override
public ByteBuffer rewind() {
return Js.uncheckedCast(super.rewind());
}

/** Returns the byte order used by this buffer when converting bytes from/to other primitive
* types.
* <p> The default byte order of byte buffer is always {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/java/nio/FloatBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import elemental2.core.ArrayBufferView;
import elemental2.core.Float32Array;
import jsinterop.base.Js;

/** A buffer of floats.
* <p>
Expand Down Expand Up @@ -112,6 +113,41 @@ public int compareTo (FloatBuffer otherBuffer) {
return remaining() - otherBuffer.remaining();
}

@Override
public FloatBuffer limit(int newLimit) {
return Js.uncheckedCast(super.limit(newLimit));
}

@Override
public FloatBuffer position(int newPosition) {
return Js.uncheckedCast(super.position(newPosition));
}

@Override
public FloatBuffer mark() {
return Js.uncheckedCast(super.mark());
}

@Override
public FloatBuffer reset() {
return Js.uncheckedCast(super.reset());
}

@Override
public FloatBuffer clear() {
return Js.uncheckedCast(super.clear());
}

@Override
public FloatBuffer flip() {
return Js.uncheckedCast(super.flip());
}

@Override
public FloatBuffer rewind() {
return Js.uncheckedCast(super.rewind());
}

/** Returns a duplicated buffer that shares its content with this buffer.
* <p> The duplicated buffer's position, limit, capacity and mark are the same as this buffer.
* The duplicated buffer's read-only property and byte order are same as this buffer too. </p>
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/java/nio/ShortBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import elemental2.core.ArrayBufferView;
import elemental2.core.Int16Array;
import jsinterop.base.Js;

/** A buffer of shorts.
* <p> A short buffer can be created in either of the following ways: </p>
Expand Down Expand Up @@ -108,6 +109,41 @@ public int compareTo (ShortBuffer otherBuffer) {
return remaining() - otherBuffer.remaining();
}

@Override
public ShortBuffer limit(int newLimit) {
return Js.uncheckedCast(super.limit(newLimit));
}

@Override
public ShortBuffer position(int newPosition) {
return Js.uncheckedCast(super.position(newPosition));
}

@Override
public ShortBuffer mark() {
return Js.uncheckedCast(super.mark());
}

@Override
public ShortBuffer reset() {
return Js.uncheckedCast(super.reset());
}

@Override
public ShortBuffer clear() {
return Js.uncheckedCast(super.clear());
}

@Override
public ShortBuffer flip() {
return Js.uncheckedCast(super.flip());
}

@Override
public ShortBuffer rewind() {
return Js.uncheckedCast(super.rewind());
}

/** Returns a duplicated buffer that shares its content with this buffer.
* <p> The duplicated buffer's position, limit, capacity and mark are the same as this buffer.
* The duplicated buffer's read-only property and byte order are the same as this buffer's.
Expand Down

0 comments on commit e93a75c

Please sign in to comment.