Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Java9 overrides to specialize return types #19

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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