public enum BufferSearch extends Enum<BufferSearch>
java.util.Arrays, modified with minimal changes to support nio
buffers.
Also provides methods for finding the first or last index of a sequence of duplicate values.
| Modifier and Type | Method and Description |
|---|---|
static int |
binaryFindFirst(ByteBuffer b,
int minIndex,
int keyIndex)
Searches a range of the specified
ByteBuffer for the first occurrence
of the value at the given keyIndex. |
static int |
binaryFindFirst(DoubleBuffer b,
int minIndex,
int keyIndex)
Searches a range of the specified
DoubleBuffer for the first
occurrence of the value at the given keyIndex. |
static int |
binaryFindFirst(FloatBuffer b,
int minIndex,
int keyIndex)
Searches a range of the specified
FloatBuffer for the first
occurrence of the value at the given keyIndex. |
static int |
binaryFindFirst(IntBuffer b,
int minIndex,
int keyIndex)
Searches a range of the specified
IntBuffer for the first occurrence
of the value at the given keyIndex. |
static int |
binaryFindFirst(LongBuffer b,
int minIndex,
int keyIndex)
Searches a range of the specified
LongBuffer for the first occurrence
of the value at the given keyIndex. |
static int |
binaryFindFirst(ShortBuffer b,
int minIndex,
int keyIndex)
Searches a range of the specified
ShortBuffer for the first
occurrence of the value at the given keyIndex. |
static int |
binaryFindLast(ByteBuffer b,
int maxIndex,
int keyIndex)
Searches a range of the specified
ByteBuffer for the last occurrence
of the value at the given keyIndex. |
static int |
binaryFindLast(DoubleBuffer b,
int maxIndex,
int keyIndex)
Searches a range of the specified
DoubleBuffer for the last
occurrence of the value at the given keyIndex. |
static int |
binaryFindLast(FloatBuffer b,
int maxIndex,
int keyIndex)
Searches a range of the specified
FloatBuffer for the last occurrence
of the value at the given keyIndex. |
static int |
binaryFindLast(IntBuffer b,
int maxIndex,
int keyIndex)
Searches a range of the specified
IntBuffer for the last occurrence
of the value at the given keyIndex. |
static int |
binaryFindLast(LongBuffer b,
int maxIndex,
int keyIndex)
Searches a range of the specified
LongBuffer for the last occurrence
of the value at the given keyIndex. |
static int |
binaryFindLast(ShortBuffer b,
int maxIndex,
int keyIndex)
Searches a range of the specified
ShortBuffer for the last occurrence
of the value at the given keyIndex. |
static int |
binarySearch(ByteBuffer b,
int fromIndex,
int toIndex,
byte key)
Searches a range of the specified
ByteBuffer for the specified value
using the binary search algorithm. |
static int |
binarySearch(DoubleBuffer b,
int fromIndex,
int toIndex,
double key)
Searches a range of the specified
DoubleBuffer for the specified
value using the binary search algorithm. |
static int |
binarySearch(FloatBuffer b,
int fromIndex,
int toIndex,
float key)
Searches a range of the specified
FloatBuffer for the specified value
using the binary search algorithm. |
static int |
binarySearch(IntBuffer b,
int fromIndex,
int toIndex,
int key)
Searches a range of the specified
IntBuffer for the specified value
using the binary search algorithm. |
static int |
binarySearch(LongBuffer b,
int fromIndex,
int toIndex,
long key)
Searches a range of the specified
LongBuffer for the specified value
using the binary search algorithm. |
static int |
binarySearch(ShortBuffer b,
int fromIndex,
int toIndex,
short key)
Searches a range of the specified
ShortBuffer for the specified value
using the binary search algorithm. |
static BufferSearch |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static BufferSearch[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static BufferSearch[] values()
for (BufferSearch c : BufferSearch.values()) System.out.println(c);
public static BufferSearch valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static int binarySearch(IntBuffer b, int fromIndex, int toIndex, int key)
IntBuffer for the specified value
using the binary search algorithm. The range must be sorted in ascending
order prior to making this call. If it is not sorted, the results are
undefined. If the range contains multiple elements with the specified value,
there is no guarantee which one will be found.b - the buffer to be searchedfromIndex - the index of the first element (inclusive) to be searchedtoIndex - the index of the last element (exclusive) to be searchedkey - the value to be searched forIllegalArgumentException - if fromIndex > toIndexIndexOutOfBoundsException - if
fromIndex < 0 or toIndex > b.capacity()public static int binarySearch(LongBuffer b, int fromIndex, int toIndex, long key)
LongBuffer for the specified value
using the binary search algorithm. The range must be sorted in ascending
order prior to making this call. If it is not sorted, the results are
undefined. If the range contains multiple elements with the specified value,
there is no guarantee which one will be found.b - the buffer to be searchedfromIndex - the index of the first element (inclusive) to be searchedtoIndex - the index of the last element (exclusive) to be searchedkey - the value to be searched forIllegalArgumentException - if fromIndex > toIndexIndexOutOfBoundsException - if
fromIndex < 0 or toIndex > b.capacity()public static int binarySearch(ShortBuffer b, int fromIndex, int toIndex, short key)
ShortBuffer for the specified value
using the binary search algorithm. The range must be sorted in ascending
order prior to making this call. If it is not sorted, the results are
undefined. If the range contains multiple elements with the specified value,
there is no guarantee which one will be found.b - the buffer to be searchedfromIndex - the index of the first element (inclusive) to be searchedtoIndex - the index of the last element (exclusive) to be searchedkey - the value to be searched forIllegalArgumentException - if fromIndex > toIndexIndexOutOfBoundsException - if
fromIndex < 0 or toIndex > b.capacity()public static int binarySearch(ByteBuffer b, int fromIndex, int toIndex, byte key)
ByteBuffer for the specified value
using the binary search algorithm. The range must be sorted in ascending
order prior to making this call. If it is not sorted, the results are
undefined. If the range contains multiple elements with the specified value,
there is no guarantee which one will be found.b - the buffer to be searchedfromIndex - the index of the first element (inclusive) to be searchedtoIndex - the index of the last element (exclusive) to be searchedkey - the value to be searched forIllegalArgumentException - if fromIndex > toIndexIndexOutOfBoundsException - if
fromIndex < 0 or toIndex > b.capacity()public static int binarySearch(FloatBuffer b, int fromIndex, int toIndex, float key)
FloatBuffer for the specified value
using the binary search algorithm. The range must be sorted in ascending
order prior to making this call. If it is not sorted, the results are
undefined. If the range contains multiple elements with the specified value,
there is no guarantee which one will be found. This method considers all NaN
values to be equivalent and equal.b - the buffer to be searchedfromIndex - the index of the first element (inclusive) to be searchedtoIndex - the index of the last element (exclusive) to be searchedkey - the value to be searched forIllegalArgumentException - if fromIndex > toIndexIndexOutOfBoundsException - if
fromIndex < 0 or toIndex > b.capacity()public static int binarySearch(DoubleBuffer b, int fromIndex, int toIndex, double key)
DoubleBuffer for the specified
value using the binary search algorithm. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined. If the range contains multiple elements with the specified
value, there is no guarantee which one will be found. This method considers
all NaN values to be equivalent and equal.b - the buffer to be searchedfromIndex - the index of the first element (inclusive) to be searchedtoIndex - the index of the last element (exclusive) to be searchedkey - the value to be searched forIllegalArgumentException - if fromIndex > toIndexIndexOutOfBoundsException - if
fromIndex < 0 or toIndex > b.capacity()public static int binaryFindFirst(IntBuffer b, int minIndex, int keyIndex)
IntBuffer for the first occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedminIndex - the lowest index to be searchedkeyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if minIndex > keyIndexIndexOutOfBoundsException - if
minIndex < 0 or keyIndex >= b.capacity()public static int binaryFindLast(IntBuffer b, int maxIndex, int keyIndex)
IntBuffer for the last occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedmaxIndex - the highest index to be searched (exclusive)keyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if maxIndex < keyIndexIndexOutOfBoundsException - if
keyIndex < 0 or maxIndex > b.capacity()public static int binaryFindFirst(LongBuffer b, int minIndex, int keyIndex)
LongBuffer for the first occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedminIndex - the lowest index to be searchedkeyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if minIndex > keyIndexIndexOutOfBoundsException - if
minIndex < 0 or keyIndex >= b.capacity()public static int binaryFindLast(LongBuffer b, int maxIndex, int keyIndex)
LongBuffer for the last occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedmaxIndex - the highest index to be searched (exclusive)keyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if maxIndex < keyIndexIndexOutOfBoundsException - if
keyIndex < 0 or maxIndex > b.capacity()public static int binaryFindFirst(ShortBuffer b, int minIndex, int keyIndex)
ShortBuffer for the first
occurrence of the value at the given keyIndex. The range must be
sorted in ascending order prior to making this call. If it is not sorted, the
results are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedminIndex - the lowest index to be searchedkeyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if minIndex > keyIndexIndexOutOfBoundsException - if
minIndex < 0 or keyIndex >= b.capacity()public static int binaryFindLast(ShortBuffer b, int maxIndex, int keyIndex)
ShortBuffer for the last occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedmaxIndex - the highest index to be searched (exclusive)keyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if maxIndex < keyIndexIndexOutOfBoundsException - if
keyIndex < 0 or maxIndex > b.capacity()public static int binaryFindFirst(ByteBuffer b, int minIndex, int keyIndex)
ByteBuffer for the first occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedminIndex - the lowest index to be searchedkeyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if minIndex > keyIndexIndexOutOfBoundsException - if
minIndex < 0 or keyIndex >= b.capacity()public static int binaryFindLast(ByteBuffer b, int maxIndex, int keyIndex)
ByteBuffer for the last occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedmaxIndex - the highest index to be searched (exclusive)keyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if maxIndex < keyIndexIndexOutOfBoundsException - if
keyIndex < 0 or maxIndex > b.capacity()public static int binaryFindFirst(FloatBuffer b, int minIndex, int keyIndex)
FloatBuffer for the first
occurrence of the value at the given keyIndex. The range must be
sorted in ascending order prior to making this call. If it is not sorted, the
results are undefined. This method considers all NaN values to be equivalent
and equal.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedminIndex - the lowest index to be searchedkeyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if minIndex > keyIndexIndexOutOfBoundsException - if
minIndex < 0 or keyIndex >= b.capacity()public static int binaryFindLast(FloatBuffer b, int maxIndex, int keyIndex)
FloatBuffer for the last occurrence
of the value at the given keyIndex. The range must be sorted in
ascending order prior to making this call. If it is not sorted, the results
are undefined. This method considers all NaN values to be equivalent and
equal.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedmaxIndex - the highest index to be searched (exclusive)keyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if maxIndex < keyIndexIndexOutOfBoundsException - if
keyIndex < 0 or maxIndex > b.capacity()public static int binaryFindFirst(DoubleBuffer b, int minIndex, int keyIndex)
DoubleBuffer for the first
occurrence of the value at the given keyIndex. The range must be
sorted in ascending order prior to making this call. If it is not sorted, the
results are undefined. This method considers all NaN values to be equivalent
and equal.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedminIndex - the lowest index to be searchedkeyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if minIndex > keyIndexIndexOutOfBoundsException - if
minIndex < 0 or keyIndex >= b.capacity()public static int binaryFindLast(DoubleBuffer b, int maxIndex, int keyIndex)
DoubleBuffer for the last
occurrence of the value at the given keyIndex. The range must be
sorted in ascending order prior to making this call. If it is not sorted, the
results are undefined. This method considers all NaN values to be equivalent
and equal.
This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.
b - the buffer to be searchedmaxIndex - the highest index to be searched (exclusive)keyIndex - an index of the value for which to find the first occurrence
(inclusive)keyIndexIllegalArgumentException - if maxIndex < keyIndexIndexOutOfBoundsException - if
keyIndex < 0 or maxIndex > b.capacity()Copyright © 2020. All rights reserved.