diff --git a/jdk/make/java/nio/genBuffer.sh b/jdk/make/java/nio/genBuffer.sh index 27e3f82f0fd138a876c05ccd15ca63e955684c0a..69e86238baa9a07b22e0bc1b7f82a5a3cf1f1bb9 100644 --- a/jdk/make/java/nio/genBuffer.sh +++ b/jdk/make/java/nio/genBuffer.sh @@ -44,6 +44,7 @@ rwkey=XX case $type in char) fulltype=character;; + int) fulltype=integer;; *) fulltype=$type;; esac @@ -54,6 +55,11 @@ case $type in long | double) LBPV=3;; esac +case $type in + float|double) floatingPointOrIntegralType=floatingPointType;; + *) floatingPointOrIntegralType=integralType;; +esac + typesAndBits() { type="$1"; BO="$2" @@ -101,6 +107,7 @@ set -e $SPP <$SRC >$DST \ -K$type \ + -K$floatingPointOrIntegralType \ -Dtype=$type \ -DType=$Type \ -Dfulltype=$fulltype \ diff --git a/jdk/src/share/classes/java/nio/X-Buffer.java.template b/jdk/src/share/classes/java/nio/X-Buffer.java.template index 9fc8185b646ef0387d26889e548ba1bf99cab1f7..e3431a02dfec700e36a8f8b4ff585898a839cc7d 100644 --- a/jdk/src/share/classes/java/nio/X-Buffer.java.template +++ b/jdk/src/share/classes/java/nio/X-Buffer.java.template @@ -32,24 +32,24 @@ import java.io.IOException; #end[char] /** - * $A$ $fulltype$ buffer. + * $A$ $type$ buffer. * *
This class defines {#if[byte]?six:four} categories of operations upon - * $fulltype$ buffers: + * $type$ buffers: * *
Absolute and relative {@link #get() get} and
* {@link #put($type$)
put} methods that read and write
- * single $fulltype$s;
Relative {@link #get($type$[]) bulk get}
- * methods that transfer contiguous sequences of $fulltype$s from this buffer
+ * methods that transfer contiguous sequences of $type$s from this buffer
* into an array; {#if[!byte]?and}
Relative {@link #put($type$[]) bulk put}
- * methods that transfer contiguous sequences of $fulltype$s from $a$
- * $fulltype$ array{#if[char]?, a string,} or some other $fulltype$
+ * methods that transfer contiguous sequences of $type$s from $a$
+ * $type$ array{#if[char]?, a string,} or some other $type$
* buffer into this buffer;{#if[!byte]? and}
Methods for {@link #compact compacting}, {@link
* #duplicate
duplicating}, and {@link #slice
- *
slicing} $a$ $fulltype$ buffer.
} $a$ $type$ buffer.
*
*
$Fulltype$ buffers can be created either by {@link #allocate + *
$Type$ buffers can be created either by {@link #allocate
* allocation Like a byte buffer, $a$ $fulltype$ buffer is either Like a byte buffer, $a$ $type$ buffer is either direct or non-direct. A
- * $fulltype$ buffer created via the wrap methods of this class will
- * be non-direct. $A$ $fulltype$ buffer created as a view of a byte buffer will
+ * $type$ buffer created via the wrap methods of this class will
+ * be non-direct. $A$ $type$ buffer created as a view of a byte buffer will
* be direct if, and only if, the byte buffer itself is direct. Whether or not
- * $a$ $fulltype$ buffer is direct may be determined by invoking the {@link
+ * $a$ $type$ buffer is direct may be determined by invoking the {@link
* #isDirect isDirect} method. The new buffer's position will be zero, its limit will be its
* capacity, its mark will be undefined, and each of its elements will be
@@ -295,9 +295,9 @@ public abstract class $Type$Buffer
* {@link #hasArray The new buffer's position will be zero, its limit will be its
* capacity, its mark will be undefined, and each of its elements will be
@@ -318,9 +318,9 @@ public abstract class $Type$Buffer
* offset The new buffer will be backed by the given $fulltype$ array;
+ * The new buffer will be backed by the given $type$ array;
* that is, modifications to the buffer will cause the array to be modified
* and vice versa. The new buffer's capacity will be
* array.length, its position will be offset, its limit
@@ -356,7 +356,7 @@ public abstract class $Type$Buffer
* array.length - offset.
* The new buffer's limit will be set to offset + length.
*
- * @return The new $fulltype$ buffer
+ * @return The new $type$ buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on the offset and length
@@ -373,9 +373,9 @@ public abstract class $Type$Buffer
}
/**
- * Wraps $a$ $fulltype$ array into a buffer.
+ * Wraps $a$ $type$ array into a buffer.
*
- * The new buffer will be backed by the given $fulltype$ array;
+ * The new buffer will be backed by the given $type$ array;
* that is, modifications to the buffer will cause the array to be modified
* and vice versa. The new buffer's capacity and limit will be
* array.length, its position will be zero, and its mark will be
@@ -386,7 +386,7 @@ public abstract class $Type$Buffer
* @param array
* The array that will back this buffer
*
- * @return The new $fulltype$ buffer
+ * @return The new $type$ buffer
*/
public static $Type$Buffer wrap($type$[] array) {
return wrap(array, 0, array.length);
@@ -486,7 +486,7 @@ public abstract class $Type$Buffer
#end[char]
/**
- * Creates a new $fulltype$ buffer whose content is a shared subsequence of
+ * Creates a new $type$ buffer whose content is a shared subsequence of
* this buffer's content.
*
* The content of the new buffer will start at this buffer's current
@@ -495,17 +495,17 @@ public abstract class $Type$Buffer
* values will be independent.
*
* The new buffer's position will be zero, its capacity and its limit
- * will be the number of $fulltype$s remaining in this buffer, and its mark
+ * will be the number of $type$s remaining in this buffer, and its mark
* will be undefined. The new buffer will be direct if, and only if, this
* buffer is direct, and it will be read-only if, and only if, this buffer
* is read-only. The content of the new buffer will be that of this buffer. Changes
* to this buffer's content will be visible in the new buffer, and vice
@@ -517,12 +517,12 @@ public abstract class $Type$Buffer
* and only if, this buffer is direct, and it will be read-only if, and
* only if, this buffer is read-only. The content of the new buffer will be that of this buffer. Changes
@@ -537,7 +537,7 @@ public abstract class $Type$Buffer
* If this buffer is itself read-only then this method behaves in
* exactly the same way as the {@link #duplicate duplicate} method. Writes the given $fulltype$ into this buffer at the current
+ * Writes the given $type$ into this buffer at the current
* position, and then increments the position. }, which allocates space for the buffer's
*
#if[byte]
*
* content, or by {@link #wrap($type$[])
wrapping} an
- * existing $fulltype$ array {#if[char]?or string} into a buffer.
+ * existing $type$ array {#if[char]?or string} into a buffer.
*
#else[byte]
*
* content, by {@link #wrap($type$[])
wrapping} an existing
- * $fulltype$ array {#if[char]?or string} into a buffer, or by creating a
+ * $type$ array {#if[char]?or string} into a buffer, or by creating a
* view of an existing byte buffer.
*
#end[byte]
@@ -189,12 +189,12 @@ import java.io.IOException;
*
#if[!byte]
*
- *
backing array} is unspecified.
*
* @param capacity
- * The new buffer's capacity, in $fulltype$s
+ * The new buffer's capacity, in $type$s
*
- * @return The new $fulltype$ buffer
+ * @return The new $type$ buffer
*
* @throws IllegalArgumentException
* If the capacity is a negative integer
@@ -309,7 +309,7 @@ public abstract class $Type$Buffer
#end[byte]
/**
- * Allocates a new $fulltype$ buffer.
+ * Allocates a new $type$ buffer.
*
*
} will be zero.
*
* @param capacity
- * The new buffer's capacity, in $fulltype$s
+ * The new buffer's capacity, in $type$s
*
- * @return The new $fulltype$ buffer
+ * @return The new $type$ buffer
*
* @throws IllegalArgumentException
* If the capacity is a negative integer
@@ -332,9 +332,9 @@ public abstract class $Type$Buffer
}
/**
- * Wraps $a$ $fulltype$ array into a buffer.
+ * Wraps $a$ $type$ array into a buffer.
*
- *
Writes the given $fulltype$ into this buffer at the given + *
Writes the given $type$ into this buffer at the given * index.
* * @param index - * The index at which the $fulltype$ will be written + * The index at which the $type$ will be written * * @param $x$ - * The $fulltype$ value to be written + * The $type$ value to be written * * @return This buffer * @@ -618,14 +618,14 @@ public abstract class $Type$Buffer /** * Relative bulk get method. * - *This method transfers $fulltype$s from this buffer into the given - * destination array. If there are fewer $fulltype$s remaining in the + *
This method transfers $type$s from this buffer into the given + * destination array. If there are fewer $type$s remaining in the * buffer than are required to satisfy the request, that is, if * length > remaining(), then no - * $fulltype$s are transferred and a {@link BufferUnderflowException} is + * $type$s are transferred and a {@link BufferUnderflowException} is * thrown. * - *
Otherwise, this method copies length $fulltype$s from this + *
Otherwise, this method copies length $type$s from this * buffer into the given array, starting at the current position of this * buffer and at the given offset in the array. The position of this * buffer is then incremented by length. @@ -638,26 +638,26 @@ public abstract class $Type$Buffer * for (int i = off; i < off + len; i++) * dst[i] = src.get(); * - * except that it first checks that there are sufficient $fulltype$s in + * except that it first checks that there are sufficient $type$s in * this buffer and it is potentially much more efficient.
* * @param dst - * The array into which $fulltype$s are to be written + * The array into which $type$s are to be written * * @param offset - * The offset within the array of the first $fulltype$ to be + * The offset within the array of the first $type$ to be * written; must be non-negative and no larger than * dst.length * * @param length - * The maximum number of $fulltype$s to be written to the given + * The maximum number of $type$s to be written to the given * array; must be non-negative and no larger than * dst.length - offset * * @return This buffer * * @throws BufferUnderflowException - * If there are fewer than length $fulltype$s + * If there are fewer than length $type$s * remaining in this buffer * * @throws IndexOutOfBoundsException @@ -677,7 +677,7 @@ public abstract class $Type$Buffer /** * Relative bulk get method. * - *This method transfers $fulltype$s from this buffer into the given + *
This method transfers $type$s from this buffer into the given * destination array. An invocation of this method of the form * src.get(a) behaves in exactly the same way as the invocation * @@ -687,7 +687,7 @@ public abstract class $Type$Buffer * @return This buffer * * @throws BufferUnderflowException - * If there are fewer than length $fulltype$s + * If there are fewer than length $type$s * remaining in this buffer */ public $Type$Buffer get($type$[] dst) { @@ -700,15 +700,15 @@ public abstract class $Type$Buffer /** * Relative bulk put method (optional operation). * - *
This method transfers the $fulltype$s remaining in the given source - * buffer into this buffer. If there are more $fulltype$s remaining in the + *
This method transfers the $type$s remaining in the given source + * buffer into this buffer. If there are more $type$s remaining in the * source buffer than in this buffer, that is, if * src.remaining() > remaining(), - * then no $fulltype$s are transferred and a {@link + * then no $type$s are transferred and a {@link * BufferOverflowException} is thrown. * *
Otherwise, this method copies - * n = src.remaining() $fulltype$s from the given + * n = src.remaining() $type$s from the given * buffer into this buffer, starting at each buffer's current position. * The positions of both buffers are then incremented by n. * @@ -723,14 +723,14 @@ public abstract class $Type$Buffer * buffer and it is potentially much more efficient.
* * @param src - * The source buffer from which $fulltype$s are to be read; + * The source buffer from which $type$s are to be read; * must not be this buffer * * @return This buffer * * @throws BufferOverflowException * If there is insufficient space in this buffer - * for the remaining $fulltype$s in the source buffer + * for the remaining $type$s in the source buffer * * @throws IllegalArgumentException * If the source buffer is this buffer @@ -752,14 +752,14 @@ public abstract class $Type$Buffer /** * Relative bulk put method (optional operation). * - *This method transfers $fulltype$s into this buffer from the given - * source array. If there are more $fulltype$s to be copied from the array + *
This method transfers $type$s into this buffer from the given + * source array. If there are more $type$s to be copied from the array * than remain in this buffer, that is, if * length > remaining(), then no - * $fulltype$s are transferred and a {@link BufferOverflowException} is + * $type$s are transferred and a {@link BufferOverflowException} is * thrown. * - *
Otherwise, this method copies length $fulltype$s from the + *
Otherwise, this method copies length $type$s from the * given array into this buffer, starting at the given offset in the array * and at the current position of this buffer. The position of this buffer * is then incremented by length. @@ -776,14 +776,14 @@ public abstract class $Type$Buffer * buffer and it is potentially much more efficient.
* * @param src - * The array from which $fulltype$s are to be read + * The array from which $type$s are to be read * * @param offset - * The offset within the array of the first $fulltype$ to be read; + * The offset within the array of the first $type$ to be read; * must be non-negative and no larger than array.length * * @param length - * The number of $fulltype$s to be read from the given array; + * The number of $type$s to be read from the given array; * must be non-negative and no larger than * array.length - offset * @@ -813,7 +813,7 @@ public abstract class $Type$Buffer * Relative bulk put method (optional operation). * *This method transfers the entire content of the given source - * $fulltype$ array into this buffer. An invocation of this method of the + * $type$ array into this buffer. An invocation of this method of the * form dst.put(a) behaves in exactly the same way as the * invocation * @@ -837,15 +837,15 @@ public abstract class $Type$Buffer /** * Relative bulk put method (optional operation). * - *
This method transfers $fulltype$s from the given string into this - * buffer. If there are more $fulltype$s to be copied from the string than + *
This method transfers $type$s from the given string into this + * buffer. If there are more $type$s to be copied from the string than * remain in this buffer, that is, if * end - start > remaining(), - * then no $fulltype$s are transferred and a {@link + * then no $type$s are transferred and a {@link * BufferOverflowException} is thrown. * *
Otherwise, this method copies - * n = end - start $fulltype$s + * n = end - start $type$s * from the given string into this buffer, starting at the given * start index and at the current position of this buffer. The * position of this buffer is then incremented by n. @@ -862,15 +862,15 @@ public abstract class $Type$Buffer * buffer and it is potentially much more efficient.
* * @param src - * The string from which $fulltype$s are to be read + * The string from which $type$s are to be read * * @param start - * The offset within the string of the first $fulltype$ to be read; + * The offset within the string of the first $type$ to be read; * must be non-negative and no larger than * string.length() * * @param end - * The offset within the string of the last $fulltype$ to be read, + * The offset within the string of the last $type$ to be read, * plus one; must be non-negative and no larger than * string.length() * @@ -921,7 +921,7 @@ public abstract class $Type$Buffer // -- Other stuff -- /** - * Tells whether or not this buffer is backed by an accessible $fulltype$ + * Tells whether or not this buffer is backed by an accessible $type$ * array. * *If this method returns true then the {@link #array() array} @@ -936,7 +936,7 @@ public abstract class $Type$Buffer } /** - * Returns the $fulltype$ array that backs this + * Returns the $type$ array that backs this * buffer (optional operation). * *
Modifications to this buffer's content will cause the returned @@ -993,17 +993,17 @@ public abstract class $Type$Buffer /** * Compacts this buffer (optional operation). * - *
The $fulltype$s between the buffer's current position and its limit, + *
The $type$s between the buffer's current position and its limit, * if any, are copied to the beginning of the buffer. That is, the - * $fulltype$ at index p = position() is copied - * to index zero, the $fulltype$ at index p + 1 is copied - * to index one, and so forth until the $fulltype$ at index + * $type$ at index p = position() is copied + * to index zero, the $type$ at index p + 1 is copied + * to index one, and so forth until the $type$ at index * limit() - 1 is copied to index * n = limit() - 1 - p. * The buffer's position is then set to n+1 and its limit is set to * its capacity. The mark, if defined, is discarded. * - *
The buffer's position is set to the number of $fulltype$s copied, + *
The buffer's position is set to the number of $type$s copied, * rather than to zero, so that an invocation of this method can be * followed immediately by an invocation of another relative put * method.
@@ -1032,7 +1032,7 @@ public abstract class $Type$Buffer public abstract $Type$Buffer compact(); /** - * Tells whether or not this $fulltype$ buffer is direct. + * Tells whether or not this $type$ buffer is direct. * * @return true if, and only if, this buffer is direct */ @@ -1098,6 +1098,13 @@ public abstract class $Type$Buffer * *The two sequences of remaining elements, considered * independently of their starting positions, are pointwise equal. +#if[floatingPointType] + * This method considers two $type$ elements {@code a} and {@code b} + * to be equal if + * {@code (a == b) || ($Fulltype$.isNaN(a) && $Fulltype$.isNaN(b))}. + * The values {@code -0.0} and {@code +0.0} are considered to be + * equal, unlike {@link $Fulltype$#equals(Object)}. +#end[floatingPointType] *
Two $type$ buffers are compared by comparing their sequences of * remaining elements lexicographically, without regard to the starting * position of each sequence within its corresponding buffer. +#if[floatingPointType] + * Pairs of {@code $type$} elements are compared as if by invoking + * {@link $Fulltype$#compare($type$,$type$)}, except that + * {@code -0.0} and {@code 0.0} are considered to be equal. + * {@code $Fulltype$.NaN} is considered by this method to be equal + * to itself and greater than all other {@code $type$} values + * (including {@code $Fulltype$.POSITIVE_INFINITY}). +#else[floatingPointType] + * Pairs of {@code $type$} elements are compared as if by invoking + * {@link $Fulltype$#compare($type$,$type$)}. +#end[floatingPointType] * *
A $type$ buffer is not comparable to any other type of object. * @@ -1145,20 +1165,23 @@ public abstract class $Type$Buffer public int compareTo($Type$Buffer that) { int n = this.position() + Math.min(this.remaining(), that.remaining()); for (int i = this.position(), j = that.position(); i < n; i++, j++) { - $type$ v1 = this.get(i); - $type$ v2 = that.get(j); - if (v1 == v2) - continue; - if ((v1 != v1) && (v2 != v2)) // For float and double - continue; - if (v1 < v2) - return -1; - return +1; + int cmp = compare(this.get(i), that.get(j)); + if (cmp != 0) + return cmp; } return this.remaining() - that.remaining(); } - + private static int compare($type$ x, $type$ y) { +#if[floatingPointType] + return ((x < y) ? -1 : + (x > y) ? +1 : + (x == y) ? 0 : + $Fulltype$.isNaN(x) ? ($Fulltype$.isNaN(y) ? 0 : +1) : -1); +#else[floatingPointType] + return $Fulltype$.compare(x, y); +#end[floatingPointType] + } // -- Other char stuff -- @@ -1326,7 +1349,7 @@ public abstract class $Type$Buffer } /** - * Appends the specified $fulltype$ to this + * Appends the specified $type$ to this * buffer (optional operation). * *
An invocation of this method of the form dst.append($x$) @@ -1336,7 +1359,7 @@ public abstract class $Type$Buffer * dst.put($x$) * * @param $x$ - * The 16-bit $fulltype$ to append + * The 16-bit $type$ to append * * @return This buffer * @@ -1362,10 +1385,10 @@ public abstract class $Type$Buffer /** * Retrieves this buffer's byte order. * - *
The byte order of $a$ $fulltype$ buffer created by allocation or by + *
The byte order of $a$ $type$ buffer created by allocation or by
* wrapping an existing $type$ array is the {@link
* ByteOrder#nativeOrder native order} of the underlying
- * hardware. The byte order of $a$ $fulltype$ buffer created as a view of a byte buffer is that of the
* byte buffer at the moment that the view is created.