public final class Buffers extends Object
#set(...)
,
#clear(...)
, and #get(...)
bit values from an argument
byte[]
.Modifier and Type | Method and Description |
---|---|
static byte[] |
clear(byte[] buf,
int bit)
Sets the bit in
buf specified by the bit index to
false . |
static char[] |
clear(char[] buf,
int bit)
Sets the bit in
buf specified by the bit index to
false . |
static int[] |
clear(int[] buf,
int bit)
Sets the bit in
buf specified by the bit index to
false . |
static long[] |
clear(long[] buf,
int bit)
Sets the bit in
buf specified by the bit index to
false . |
static short[] |
clear(short[] buf,
int bit)
Sets the bit in
buf specified by the bit index to
false . |
static boolean |
get(byte[] buf,
int bit)
Returns the value of the bit at the specified index.
|
static boolean |
get(char[] buf,
int bit)
Returns the value of the bit at the specified index.
|
static boolean |
get(int[] buf,
int bit)
Returns the value of the bit at the specified index.
|
static boolean |
get(long[] buf,
int bit)
Returns the value of the bit at the specified index.
|
static boolean |
get(short[] buf,
int bit)
Returns the value of the bit at the specified index.
|
static int |
length(byte[] buf)
Returns the "logical size" of
buf : the index of the byte with the
highest set bit in buf , plus one. |
static int |
length(char[] buf)
Returns the "logical size" of
buf : the index of the char with the
highest set bit in buf , plus one. |
static int |
length(int[] buf)
Returns the "logical size" of
buf : the index of the int with the
highest set bit in buf , plus one. |
static int |
length(long[] buf)
Returns the "logical size" of
buf : the index of the long with the
highest set bit in buf , plus one. |
static int |
length(short[] buf)
Returns the "logical size" of
buf : the index of the short with the
highest set bit in buf , plus one. |
static byte[] |
set(byte[] buf,
int bit,
double resize)
Sets the bit at the specified index in
buf to 1 . |
static char[] |
set(char[] buf,
int bit,
double resize)
Sets the bit at the specified index in
buf to 1 . |
static int[] |
set(int[] buf,
int bit,
double resize)
Sets the bit at the specified index in
buf to 1 . |
static long[] |
set(long[] buf,
int bit,
double resize)
Sets the bit at the specified index in
buf to 1 . |
static short[] |
set(short[] buf,
int bit,
double resize)
Sets the bit at the specified index in
buf to 1 . |
static String |
toString(byte... buf)
Returns a string representing the big-endian binary representation of the
specified byte values.
|
static String |
toString(char... buf)
Returns a string representing the big-endian binary representation of the
specified char values.
|
static String |
toString(int... buf)
Returns a string representing the big-endian binary representation of the
specified int values.
|
static String |
toString(long... buf)
Returns a string representing the big-endian binary representation of the
specified long values.
|
static String |
toString(short... buf)
Returns a string representing the big-endian binary representation of the
specified short values.
|
static byte[] |
trimToLength(byte[] buf)
Returns a trimmed byte array of
buf : the length of a trimmed byte
array is its "logical size". |
static char[] |
trimToLength(char[] buf)
Returns a trimmed char array of
buf : the length of a trimmed char
array is its "logical size". |
static int[] |
trimToLength(int[] buf)
Returns a trimmed int array of
buf : the length of a trimmed int
array is its "logical size". |
static long[] |
trimToLength(long[] buf)
Returns a trimmed long array of
buf : the length of a trimmed long
array is its "logical size". |
static short[] |
trimToLength(short[] buf)
Returns a trimmed short array of
buf : the length of a trimmed short
array is its "logical size". |
public static byte[] set(byte[] buf, int bit, double resize)
buf
to 1
. If the bit
index is greater than the number of bits in the buf
array, the
array will be resized based on the resize
argument.
The resize
argument behaves by the following rules:
resize == 0
, do not resize the array. An
ArrayIndexOutOfBoundsException
will be thrown.resize > 0
, set the size of the array to the value of the
index of the byte that bit
belongs to, plus 1, multiplied by
resize
:
(int)(((bit / 8) + 1) * resize)
resize < 0
, set the size of the array to the value of the
index of the byte that bit
belongs to, minus (int)resize
:
(bit / 8) - (int)resize
buf
- The byte[]
buffer.bit
- The index of the bit to be set.resize
- The resize factor.byte[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative,
or if resize == 0
. and the bit index is greater than the
number of bits in the buf
array.NullPointerException
- If the specified array is null.public static char[] set(char[] buf, int bit, double resize)
buf
to 1
. If the bit
index is greater than the number of bits in the buf
array, the
array will be resized based on the resize
argument.
The resize
argument behaves by the following rules:
resize == 0
, do not resize the array. An
ArrayIndexOutOfBoundsException
will be thrown.resize > 0
, set the size of the array to the value of the
index of the char that bit
belongs to, plus 1, multiplied by
resize
:
(int)(((bit / 8) + 1) * resize)
resize < 0
, set the size of the array to the value of the
index of the char that bit
belongs to, minus (int)resize
:
(bit / 8) - (int)resize
buf
- The char[]
buffer.bit
- The index of the bit to be set.resize
- The resize factor.char[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative,
or if resize == 0
. and the bit index is greater than the
number of bits in the buf
array.NullPointerException
- If the specified array is null.public static short[] set(short[] buf, int bit, double resize)
buf
to 1
. If the bit
index is greater than the number of bits in the buf
array, the
array will be resized based on the resize
argument.
The resize
argument behaves by the following rules:
resize == 0
, do not resize the array. An
ArrayIndexOutOfBoundsException
will be thrown.resize > 0
, set the size of the array to the value of the
index of the short that bit
belongs to, plus 1, multiplied by
resize
:
(int)(((bit / 8) + 1) * resize)
resize < 0
, set the size of the array to the value of the
index of the short that bit
belongs to, minus (int)resize
:
(bit / 8) - (int)resize
buf
- The short[]
buffer.bit
- The index of the bit to be set.resize
- The resize factor.short[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative,
or if resize == 0
. and the bit index is greater than the
number of bits in the buf
array.NullPointerException
- If the specified array is null.public static int[] set(int[] buf, int bit, double resize)
buf
to 1
. If the bit
index is greater than the number of bits in the buf
array, the
array will be resized based on the resize
argument.
The resize
argument behaves by the following rules:
resize == 0
, do not resize the array. An
ArrayIndexOutOfBoundsException
will be thrown.resize > 0
, set the size of the array to the value of the
index of the int that bit
belongs to, plus 1, multiplied by
resize
:
(int)(((bit / 8) + 1) * resize)
resize < 0
, set the size of the array to the value of the
index of the int that bit
belongs to, minus (int)resize
:
(bit / 8) - (int)resize
buf
- The int[]
buffer.bit
- The index of the bit to be set.resize
- The resize factor.int[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative,
or if resize == 0
. and the bit index is greater than the
number of bits in the buf
array.NullPointerException
- If the specified array is null.public static long[] set(long[] buf, int bit, double resize)
buf
to 1
. If the bit
index is greater than the number of bits in the buf
array, the
array will be resized based on the resize
argument.
The resize
argument behaves by the following rules:
resize == 0
, do not resize the array. An
ArrayIndexOutOfBoundsException
will be thrown.resize > 0
, set the size of the array to the value of the
index of the long that bit
belongs to, plus 1, multiplied by
resize
:
(int)(((bit / 64) + 1) * resize)
resize < 0
, set the size of the array to the value of the
index of the long that bit
belongs to, minus (int)resize
:
(bit / 64) - (int)resize
buf
- The long[]
buffer.bit
- The index of the bit to be set.resize
- The resize factor.long[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative,
or if resize == 0
. and the bit index is greater than the
number of bits in the buf
array.NullPointerException
- If the specified array is null.public static byte[] clear(byte[] buf, int bit)
buf
specified by the bit
index to
false
.buf
- The byte[]
buffer in which to clear the bit.bit
- The index of the bit to be cleared.byte[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static char[] clear(char[] buf, int bit)
buf
specified by the bit
index to
false
.buf
- The char[]
buffer in which to clear the bit.bit
- The index of the bit to be cleared.char[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static short[] clear(short[] buf, int bit)
buf
specified by the bit
index to
false
.buf
- The short[]
buffer in which to clear the bit.bit
- The index of the bit to be cleared.short[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static int[] clear(int[] buf, int bit)
buf
specified by the bit
index to
false
.buf
- The int[]
buffer in which to clear the bit.bit
- The index of the bit to be cleared.int[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static long[] clear(long[] buf, int bit)
buf
specified by the bit
index to
false
.buf
- The long[]
buffer in which to clear the bit.bit
- The index of the bit to be cleared.long[]
buffer.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static boolean get(byte[] buf, int bit)
true
if the bit with the index bit
is currently set in
buf
, otherwise the result is false
.buf
- The byte[]
buffer.bit
- The bit index.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static boolean get(char[] buf, int bit)
true
if the bit with the index bit
is currently set in
buf
, otherwise the result is false
.buf
- The char[]
buffer.bit
- The bit index.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static boolean get(short[] buf, int bit)
true
if the bit with the index bit
is currently set in
buf
, otherwise the result is false
.buf
- The short[]
buffer.bit
- The bit index.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static boolean get(int[] buf, int bit)
true
if the bit with the index bit
is currently set in
buf
, otherwise the result is false
.buf
- The int[]
buffer.bit
- The bit index.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static boolean get(long[] buf, int bit)
true
if the bit with the index bit
is currently set in
buf
, otherwise the result is false
.buf
- The long[]
buffer.bit
- The bit index.ArrayIndexOutOfBoundsException
- If the specified index is negative.NullPointerException
- If the specified array is null.public static int length(byte[] buf)
buf
: the index of the byte with the
highest set bit in buf
, plus one. Returns zero if buf
contains no set bits.buf
- The byte[]
buffer.buf
.NullPointerException
- If the specified array is null.public static int length(char[] buf)
buf
: the index of the char with the
highest set bit in buf
, plus one. Returns zero if buf
contains no set bits.buf
- The char[]
buffer.buf
.NullPointerException
- If the specified array is null.public static int length(short[] buf)
buf
: the index of the short with the
highest set bit in buf
, plus one. Returns zero if buf
contains no set bits.buf
- The short[]
buffer.buf
.NullPointerException
- If the specified array is null.public static int length(int[] buf)
buf
: the index of the int with the
highest set bit in buf
, plus one. Returns zero if buf
contains no set bits.buf
- The int[]
buffer.buf
.NullPointerException
- If the specified array is null.public static int length(long[] buf)
buf
: the index of the long with the
highest set bit in buf
, plus one. Returns zero if buf
contains no set bits.buf
- The long[]
buffer.buf
.NullPointerException
- If the specified array is null.public static byte[] trimToLength(byte[] buf)
buf
: the length of a trimmed byte
array is its "logical size".
buf
is its "logical size", the reference to
buf
is returned.buf
is greater than its "logical size", a
reference to a new byte array is returned.buf
- The byte[]
buffer.buf
.NullPointerException
- If the specified array is null.length(byte[])
public static char[] trimToLength(char[] buf)
buf
: the length of a trimmed char
array is its "logical size".
buf
is its "logical size", the reference to
buf
is returned.buf
is greater than its "logical size", a
reference to a new char array is returned.buf
- The char[]
buffer.buf
.NullPointerException
- If the specified array is null.length(char[])
public static short[] trimToLength(short[] buf)
buf
: the length of a trimmed short
array is its "logical size".
buf
is its "logical size", the reference to
buf
is returned.buf
is greater than its "logical size", a
reference to a new short array is returned.buf
- The short[]
buffer.buf
.NullPointerException
- If the specified array is null.length(short[])
public static int[] trimToLength(int[] buf)
buf
: the length of a trimmed int
array is its "logical size".
buf
is its "logical size", the reference to
buf
is returned.buf
is greater than its "logical size", a
reference to a new int array is returned.buf
- The int[]
buffer.buf
.NullPointerException
- If the specified array is null.length(int[])
public static long[] trimToLength(long[] buf)
buf
: the length of a trimmed long
array is its "logical size".
buf
is its "logical size", the reference to
buf
is returned.buf
is greater than its "logical size", a
reference to a new long array is returned.buf
- The long[]
buffer.buf
.NullPointerException
- If the specified array is null.length(long[])
public static String toString(byte... buf)
buf
- The byte values.public static String toString(char... buf)
buf
- The char values.public static String toString(short... buf)
buf
- The short values.public static String toString(int... buf)
buf
- The int values.public static String toString(long... buf)
buf
- The long values.Copyright © 2020 LibJ. All rights reserved.