|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.ivmaidns.util.ByteVector
public final class ByteVector
Class for 'byte' array wrappers.
This class wraps a primitive byte
-type array, and
has the possibility to resize (when required) the wrapped array.
This class supports cloning, serialization and comparison of its
instances. In addition, the class contains static
methods for byte
arrays resizing, filling in,
reversing, vector arithmetics (addition, subtraction,
multiplication by a value, scalar multiplication, polynome
evaluation), elements summing and non-zero elements counting,
linear/binary searching in for a value or sequence, mismatches
counting, signed/unsigned 'less-equal-greater' comparison,
sorting, and also decimal/hexadecimal/radix-64 'to-string' and
'from-string' (parse) conversions.
CharVector
,
DoubleVector
,
FloatVector
,
IntVector
,
LongVector
,
ShortVector
,
BooleanVector
,
ObjectVector
,
UnsignedInt
,
JavaConsts
,
Serialized FormField Summary | |
---|---|
protected byte[] |
array
The wrapped (encapsulated) custom byte array. |
protected static byte[] |
EMPTY
A constant initialized with an instance of empty byte array. |
Constructor Summary | |
---|---|
ByteVector()
Constructs an empty byte vector. |
|
ByteVector(byte[] array)
Constructs a new byte array wrapper. |
|
ByteVector(int size)
Constructs a new byte vector of the specified
length. |
Method Summary | |
---|---|
static void |
addTo(byte[] arrayA,
byte[] arrayB)
Adds a given vector (array) to another one. |
byte[] |
array()
Returns array wrapped by this vector. |
static int |
binarySearch(byte[] array,
int offset,
int len,
byte value,
boolean isUnsigned)
Searches (fast) for value in a given sorted array. |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
static int |
compare(byte[] arrayA,
int offsetA,
int lenA,
byte[] arrayB,
int offsetB,
int lenB,
boolean isUnsigned)
Compares two given array regions. |
void |
copyAt(int srcOffset,
int destOffset,
int len)
Copies a region of values at one offset to another offset in this vector. |
static void |
counterSort(byte[] array,
int offset,
int len,
boolean isUnsigned)
Sorts the elements in the region of a given array (by counting the amount of each possible value in it). |
static int |
countNonZero(byte[] array)
Count non-zero elements in a given array. |
static byte[] |
ensureSize(byte[] array,
int size)
Ensures the length (capacity) of a given array. |
void |
ensureSize(int size)
Ensures the size (capacity) of this vector. |
static boolean |
equals(byte[] arrayA,
byte[] arrayB)
Tests whether or not the specified two arrays are equal. |
boolean |
equals(java.lang.Object obj)
Indicates whether this object is equal to the
specified one. |
static void |
fill(byte[] array,
int offset,
int len,
byte value)
Fills in the region of a given array with the specified value. |
java.lang.Object |
getAt(int index)
Returns the wrapped value of the element at the specified index. |
byte |
getByteAt(int index)
Returns value of the element at the specified index. |
boolean |
greaterThan(java.lang.Object obj)
Tests for being semantically greater than the argument. |
int |
hashCode()
Computes and returns a hash code value for the object. |
static int |
hashCode(byte[] array)
Produces a hash code value for a given array. |
static int |
indexOf(byte[] subArray,
int offset,
int len,
int index,
byte[] array)
Searches forward for the specified sequence in a given array. |
static int |
indexOf(byte value,
int index,
byte[] array)
Searches forward for value in a given array. |
void |
integrityCheck()
Verifies this object for its integrity. |
static int |
lastIndexOf(byte[] subArray,
int offset,
int len,
int index,
byte[] array)
Searches backward for the specified sequence in a given array. |
static int |
lastIndexOf(byte value,
int index,
byte[] array)
Searches backward for value in a given array. |
int |
length()
Returns the number of elements in this vector. |
static int |
mismatches(byte[] arrayA,
int offsetA,
byte[] arrayB,
int offsetB,
int len)
Count the mismatches of two given array regions. |
static void |
multiplyBy(byte[] array,
byte value)
Multiplies a given vector (array) by a value. |
static byte[] |
parseBase64String(java.lang.String str,
int beginIndex,
int endIndex)
Decodes 'radix-64' representation into a byte array. |
static byte[] |
parseHexString(java.lang.String str,
int beginIndex,
int endIndex,
char separator,
boolean emptyAsZero,
int groupLen,
boolean padArray)
Decodes hexadecimal sequence into a byte array. |
static int |
polynome(int intValue,
byte[] array,
boolean isUnsigned)
Computes the result of substitution of a given int
value into the polynome specified by its coefficients. |
static byte[] |
resize(byte[] array,
int size)
Resizes a given array. |
void |
resize(int size)
Resizes this vector. |
static void |
reverse(byte[] array)
Reverses the elements order in a given array. |
static int |
scalarMul(byte[] arrayA,
byte[] arrayB,
boolean isUnsigned)
Multiplies two given vectors (arrays) in a scalar way. |
void |
setArray(byte[] array)
Sets another array to be wrapped by this vector. |
void |
setAt(int index,
byte value)
Assigns a new value to the element at the specified index. |
static void |
subtractFrom(byte[] arrayA,
byte[] arrayB)
Subtracts a given vector (array) from another one. |
static int |
sumOf(byte[] array,
int offset,
int len,
boolean isUnsigned)
Sums the elements in the region of a given array. |
static java.lang.String |
toBase64String(byte[] array,
int offset,
int len)
Converts the byte-array region into its 'radix-64' representation. |
static java.lang.String |
toHexString(byte[] array,
int offset,
int len,
boolean upperCase,
char separator,
int groupLen,
boolean zeroPadding)
Converts the byte-array region into its hexadecimal representation. |
java.lang.String |
toString()
Converts this vector to its 'in-line' string
representation. |
static java.lang.String |
toString(byte[] array,
int offset,
int len,
char separator,
boolean isUnsigned)
Converts the region of a given array to its 'in-line' string representation. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final byte[] EMPTY
byte
array.
array
protected byte[] array
byte
array.
array must be non-null
.
EMPTY
,
ByteVector()
,
ByteVector(int)
,
ByteVector(byte[])
,
setArray(byte[])
,
array()
,
length()
,
resize(int)
,
ensureSize(int)
,
setAt(int, byte)
,
getByteAt(int)
,
copyAt(int, int, int)
,
clone()
,
integrityCheck()
Constructor Detail |
---|
public ByteVector()
byte
vector.
This constructor is used for the creation of a resizable vector.
The length of such a vector is changed only by
resize(int)
and ensureSize(int)
methods.
ByteVector(int)
,
ByteVector(byte[])
,
array()
,
length()
,
resize(int)
,
ensureSize(int)
,
setAt(int, byte)
,
getByteAt(int)
,
copyAt(int, int, int)
,
clone()
,
toString()
public ByteVector(int size)
byte
vector of the specified
length.
This constructor is typically used for the creation of a vector
with a fixed size. All elements of the created vector are set to
zero.
size
- the initial length (unsigned) of the vector to be created.
java.lang.OutOfMemoryError
- if there is not enough memory.ByteVector()
,
ByteVector(byte[])
,
array()
,
length()
,
setAt(int, byte)
,
getByteAt(int)
,
copyAt(int, int, int)
,
fill(byte[], int, int, byte)
,
clone()
,
toString()
public ByteVector(byte[] array) throws java.lang.NullPointerException
byte
array wrapper.
This constructor is used for the creation of a vector which wraps
the specified array (without copying it). The wrapped array may
be further replaced with another one only by
setArray(byte[])
and by resize(int)
,
ensureSize(int)
methods.
array
- the byte
array (must be non-null
) to be
wrapped.
java.lang.NullPointerException
- if array is null
.ByteVector()
,
ByteVector(int)
,
setArray(byte[])
,
array()
,
resize(int)
,
ensureSize(int)
,
setAt(int, byte)
,
getByteAt(int)
,
copyAt(int, int, int)
,
clone()
,
toString()
Method Detail |
---|
public void setArray(byte[] array) throws java.lang.NullPointerException
this
vector.
Important notes: resize(int)
and
ensureSize(int)
methods may change the array to be
wrapped too (but only with its copy of a different length); this
method does not copy array. If an exception is thrown
then this
vector remains unchanged.
array
- the byte
array (must be non-null
) to be
wrapped.
java.lang.NullPointerException
- if array is null
.ByteVector()
,
ByteVector(byte[])
,
array()
,
resize(int)
,
ensureSize(int)
,
setAt(int, byte)
,
getByteAt(int)
,
copyAt(int, int, int)
,
clone()
public final byte[] array()
this
vector.
Important notes: this method does not copy array.
byte
array (not null
), which is
wrapped.ByteVector(byte[])
,
setArray(byte[])
,
length()
,
resize(int)
,
ensureSize(int)
,
copyAt(int, int, int)
,
clone()
public int length()
this
vector.
The result is the same as length
of
array()
.
length
in interface Indexable
this
vector.setArray(byte[])
,
array()
,
setAt(int, byte)
,
resize(int)
,
ensureSize(int)
,
getByteAt(int)
,
getAt(int)
public java.lang.Object getAt(int index) throws java.lang.ArrayIndexOutOfBoundsException
new Byte(array()[index])
.
getAt
in interface Indexable
index
- the index (must be in the range) at which to return an element.
Byte
) at index.
java.lang.ArrayIndexOutOfBoundsException
- if index is negative or is not less than
length()
.
java.lang.OutOfMemoryError
- if there is not enough memory.getByteAt(int)
,
array()
,
length()
public final byte getByteAt(int index) throws java.lang.ArrayIndexOutOfBoundsException
array()[index]
.
index
- the index (must be in the range) at which to return an element.
byte
element at index.
java.lang.ArrayIndexOutOfBoundsException
- if index is negative or is not less than
length()
.array()
,
length()
,
setAt(int, byte)
,
resize(int)
,
ensureSize(int)
public void setAt(int index, byte value) throws java.lang.ArrayIndexOutOfBoundsException
this
vector remains
unchanged.
index
- the index (must be in the range) at which to assign a new value.value
- the value to be assigned.
java.lang.ArrayIndexOutOfBoundsException
- if index is negative or is not less than
length()
.setArray(byte[])
,
array()
,
length()
,
getByteAt(int)
,
resize(int)
,
ensureSize(int)
,
copyAt(int, int, int)
,
fill(byte[], int, int, byte)
public void copyAt(int srcOffset, int destOffset, int len) throws java.lang.ArrayIndexOutOfBoundsException
this
vector.
Copying is performed here through
arraycopy(Object, int, Object, int, int)
method of
System
class. Negative len is treated as
zero. If an exception is thrown then this
vector
remains unchanged.
srcOffset
- the source first index (must be in the range) of the region to be
copied.destOffset
- the first index (must be in the range) of the region copy
destination.len
- the length of the region to be copied.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (srcOffset is
negative or is greater than length()
minus
len, or destOffset is negative or is
greater than length()
minus len).array()
,
length()
,
setAt(int, byte)
,
getByteAt(int)
,
resize(int)
,
ensureSize(int)
public void resize(int size)
this
vector.
The result is the same as of
setArray(resize(array(), size))
. This method changes
the length of this
vector to the specified one.
Important notes: if size (length) of the vector grows then its
new elements are set to zero. If an exception is thrown then
this
vector remains unchanged.
size
- the (unsigned) length of this
vector to set.
java.lang.OutOfMemoryError
- if there is not enough memory.ByteVector(int)
,
setArray(byte[])
,
array()
,
length()
,
ensureSize(int)
,
resize(byte[], int)
public void ensureSize(int size)
this
vector.
The result is the same as of
setArray(ensureSize(array(), size))
. This method
changes (only if size is greater than
length()
) the length of this
vector to
a value not less than size. Important notes: if size
(length) of the vector grows then its new elements are set to
zero. If an exception is thrown then this
vector
remains unchanged.
size
- the (unsigned) length of this
vector to be ensured.
java.lang.OutOfMemoryError
- if there is not enough memory.array()
,
length()
,
setAt(int, byte)
,
resize(int)
,
ensureSize(byte[], int)
public static final byte[] resize(byte[] array, int size) throws java.lang.NullPointerException
length
of array is the same as
size then array is returned else
array content is copied into the result (all new
elements are set to zero).
array
- the array (must be non-null
) to be resized.size
- the (unsigned) length of the array to set.
null
, with
length
equal to size).
java.lang.NullPointerException
- if array is null
.
java.lang.OutOfMemoryError
- if there is not enough memory.resize(int)
,
ensureSize(byte[], int)
,
fill(byte[], int, int, byte)
public static final byte[] ensureSize(byte[] array, int size) throws java.lang.NullPointerException
length
of array) the length of
array. Important notes: array elements are
not changed; if length
of array is
greater or the same as size then array is
returned else array content is copied into the result
(all new elements are set to zero).
array
- the array (must be non-null
) to be length-ensured.size
- the (unsigned) length of the array to ensure.
null
, with
length
not less than size).
java.lang.NullPointerException
- if array is null
.
java.lang.OutOfMemoryError
- if there is not enough memory.ensureSize(int)
,
resize(byte[], int)
,
fill(byte[], int, int, byte)
public static final void fill(byte[] array, int offset, int len, byte value) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
arraycopy(Object, int, Object, int, int)
method of
System
class.
array
- the array (must be non-null
) to be filled in.offset
- the first index (must be in the range) of the region to fill in.len
- the length of the region to be filled.value
- the value to fill with.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).array()
,
copyAt(int, int, int)
,
indexOf(byte[], int, int, int, byte[])
,
lastIndexOf(byte[], int, int, int, byte[])
,
toString(byte[], int, int, char, boolean)
,
counterSort(byte[], int, int, boolean)
,
binarySearch(byte[], int, int, byte, boolean)
public static final void reverse(byte[] array) throws java.lang.NullPointerException
array
- the array (must be non-null
) to be reversed.
java.lang.NullPointerException
- if array is null
.array()
,
addTo(byte[], byte[])
,
subtractFrom(byte[], byte[])
,
countNonZero(byte[])
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte, int, byte[])
,
hashCode(byte[])
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
,
mismatches(byte[], int, byte[], int, int)
public static final void addTo(byte[] arrayA, byte[] arrayB) throws java.lang.NullPointerException
arrayA
- the first array (must be non-null
) to be added to.arrayB
- the second array (must be non-null
) to add.
java.lang.NullPointerException
- if arrayA is null
or arrayB is
null
.array()
,
reverse(byte[])
,
subtractFrom(byte[], byte[])
,
multiplyBy(byte[], byte)
,
sumOf(byte[], int, int, boolean)
,
scalarMul(byte[], byte[], boolean)
,
polynome(int, byte[], boolean)
public static final void subtractFrom(byte[] arrayA, byte[] arrayB) throws java.lang.NullPointerException
arrayA
- the first array (must be non-null
) to be subtracted
from.arrayB
- the second array (must be non-null
) to subtract.
java.lang.NullPointerException
- if arrayA is null
or arrayB is
null
.array()
,
reverse(byte[])
,
addTo(byte[], byte[])
,
multiplyBy(byte[], byte)
,
sumOf(byte[], int, int, boolean)
,
scalarMul(byte[], byte[], boolean)
,
polynome(int, byte[], boolean)
public static final void multiplyBy(byte[] array, byte value) throws java.lang.NullPointerException
array
- the array (must be non-null
) to be multiplied.value
- the value to multiply by.
java.lang.NullPointerException
- if array is null
.array()
,
fill(byte[], int, int, byte)
,
reverse(byte[])
,
addTo(byte[], byte[])
,
subtractFrom(byte[], byte[])
,
sumOf(byte[], int, int, boolean)
,
scalarMul(byte[], byte[], boolean)
,
polynome(int, byte[], boolean)
,
countNonZero(byte[])
public static final int scalarMul(byte[] arrayA, byte[] arrayB, boolean isUnsigned) throws java.lang.NullPointerException
arrayA
- the first array (must be non-null
) to multiply.arrayB
- the second array (must be non-null
) to multiply.isUnsigned
- true
if and only if array elements are (treated as)
unsigned.
int
value).
java.lang.NullPointerException
- if arrayA is null
or arrayB is
null
.array()
,
addTo(byte[], byte[])
,
subtractFrom(byte[], byte[])
,
multiplyBy(byte[], byte)
,
sumOf(byte[], int, int, boolean)
,
polynome(int, byte[], boolean)
,
mismatches(byte[], int, byte[], int, int)
,
equals(byte[], byte[])
public static final int polynome(int intValue, byte[] array, boolean isUnsigned) throws java.lang.NullPointerException
int
value into the polynome specified by its coefficients.
The result is the same as of
sum(array[index] * power(intValue, index))
. Overflow
is not checked. If length
of array is
zero then 0
is returned.
intValue
- the value to be substituted.array
- the array (must be non-null
) of the polynome
coefficients, arranged by their weight.isUnsigned
- true
if and only if array elements are (treated as)
unsigned.
java.lang.NullPointerException
- if array is null
.array()
,
addTo(byte[], byte[])
,
subtractFrom(byte[], byte[])
,
multiplyBy(byte[], byte)
,
scalarMul(byte[], byte[], boolean)
,
sumOf(byte[], int, int, boolean)
,
countNonZero(byte[])
public static final int sumOf(byte[] array, int offset, int len, boolean isUnsigned) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
array
- the array (must be non-null
) which elements to be
summed.offset
- the first index (must be in the range) of the region.len
- the length of the region.isUnsigned
- true
if and only if array elements are (treated as)
unsigned.
int
value) for a given
region.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).array()
,
fill(byte[], int, int, byte)
,
addTo(byte[], byte[])
,
subtractFrom(byte[], byte[])
,
multiplyBy(byte[], byte)
,
countNonZero(byte[])
,
hashCode(byte[])
,
mismatches(byte[], int, byte[], int, int)
,
scalarMul(byte[], byte[], boolean)
,
polynome(int, byte[], boolean)
public static final int countNonZero(byte[] array) throws java.lang.NullPointerException
array
- the array (must be non-null
) to count non-zero
elements in.
length
of array) of non-zero elements.
java.lang.NullPointerException
- if array is null
.array()
,
fill(byte[], int, int, byte)
,
sumOf(byte[], int, int, boolean)
,
scalarMul(byte[], byte[], boolean)
,
polynome(int, byte[], boolean)
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
,
mismatches(byte[], int, byte[], int, int)
public static final int indexOf(byte value, int index, byte[] array) throws java.lang.NullPointerException
length
of
array. If value is not found then the
result is -1
.
value
- the value to sequentially search for.index
- the first index, from which to begin forward searching.array
- the array (must be non-null
) to be searched in.
-1
(if not found).
java.lang.NullPointerException
- if array is null
.array()
,
lastIndexOf(byte, int, byte[])
,
indexOf(byte[], int, int, int, byte[])
,
binarySearch(byte[], int, int, byte, boolean)
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
public static final int lastIndexOf(byte value, int index, byte[] array) throws java.lang.NullPointerException
-1
, too big
index is treated as length
of
array minus one. If value is not found then
the result is -1
.
value
- the value to sequentially search for.index
- the first index, from which to begin backward searching.array
- the array (must be non-null
) to be searched in.
-1
(if not found).
java.lang.NullPointerException
- if array is null
.array()
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte[], int, int, int, byte[])
,
binarySearch(byte[], int, int, byte, boolean)
,
reverse(byte[])
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
public static final int indexOf(byte[] subArray, int offset, int len, int index, byte[] array) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
length
of array. If the
sequence is not found then the result is -1
.
subArray
- the array (must be non-null
) specifying the sequence
of values to search for.offset
- the offset (must be in the range) of the sequence in
subArray.len
- the length of the sequence.index
- the first index, from which to begin forward searching.array
- the array (must be non-null
) to be searched in.
-1
(if not found).
java.lang.NullPointerException
- if subArray is null
or array
is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of subArray
minus len).array()
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte[], int, int, int, byte[])
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
public static final int lastIndexOf(byte[] subArray, int offset, int len, int index, byte[] array) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
-1
, too big
index is treated as length
of
array minus one. If the sequence is not found then the
result is -1
.
subArray
- the array (must be non-null
) specifying the sequence
of values to search for.offset
- the offset (must be in the range) of the sequence in
subArray.len
- the length of the sequence.index
- the first index, from which to begin backward searching.array
- the array (must be non-null
) to be searched in.
-1
(if not found).
java.lang.NullPointerException
- if subArray is null
or array
is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of subArray
minus len).array()
,
lastIndexOf(byte, int, byte[])
,
indexOf(byte[], int, int, int, byte[])
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
public static final java.lang.String toString(byte[] array, int offset, int len, char separator, boolean isUnsigned) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
byte
values (of the specified region of
array) are placed into the resulting string in the
direct index order, delimited by a single separator
character. Negative len is treated as zero.
array
- the array (must be non-null
) to be converted.offset
- the first index (must be in the range) of the region to be
converted.len
- the length of the region to be converted.separator
- the delimiter character.isUnsigned
- true
if and only if array elements are (treated as)
unsigned.
null
) of the
specified region.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).
java.lang.OutOfMemoryError
- if there is not enough memory.array()
,
toString()
,
toHexString(byte[], int, int, boolean, char, int, boolean)
,
toBase64String(byte[], int, int)
,
fill(byte[], int, int, byte)
,
counterSort(byte[], int, int, boolean)
,
binarySearch(byte[], int, int, byte, boolean)
public static final java.lang.String toHexString(byte[] array, int offset, int len, boolean upperCase, char separator, int groupLen, boolean zeroPadding) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
byte
values (of the specified region of array) are placed
into the resulting string in the direct index order, delimiting
each group of bytes by a single separator character
(unless groupLen is zero). The length of every group
is specified by the absolute value of groupLen. The
sign of groupLen specifies the side of group alignment
(if non-negative then the last group may contain fewer bytes than
the previous ones, else the first group may contain fewer bytes
than the next ones). If zeroPadding is
false
then the insignificant zero digits (which may
exist on the right of each group if groupLen is
non-negative else on the left) are not placed into the result
(but, at least, on digit for each group is put in the resulting
string). If groupLen is zero then grouping is not used
(this is the same as if groupLen == len
). Negative
len is treated as zero. The resulting string is
'in-line' (and with non-zero length()
if and only if
len is positive).
array
- the array (must be non-null
) to be converted.offset
- the first index (must be in the range) of the region to be
converted.len
- the length of the region to be converted.upperCase
- true
if and only if digit characters in the result
are in the upper case.separator
- the group delimiter character.groupLen
- the byte
length of each group (in the absolute
value) and the alignment side specifier (if negative then the
right-side alignment is used else left-side one).zeroPadding
- true
if each group is zero-padded (on the left if
right-side alignment is chosen else on the right), that is, zero
bytes are not ignored, else padding is not used (but, netherless,
if the alignment is on the left then the tail byte (in each
group) is yet zero-padded (on the right side), else if the
alignment is on the right and the first digit of a group is not
decimal then one '0' is appended on its left).
null
) of the
specified region.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).
java.lang.OutOfMemoryError
- if there is not enough memory.toString()
,
toString(byte[], int, int, char, boolean)
,
toBase64String(byte[], int, int)
,
parseBase64String(java.lang.String, int, int)
,
parseHexString(java.lang.String, int, int,
char, boolean, int, boolean)
public static final byte[] parseHexString(java.lang.String str, int beginIndex, int endIndex, char separator, boolean emptyAsZero, int groupLen, boolean padArray) throws java.lang.NullPointerException, java.lang.StringIndexOutOfBoundsException, ParserException
toHexString()
method. The
length of every group is specified by the absolute value of
groupLen. The sign of groupLen specifies
the side of group alignment. Any found insignificant zero digits
(which may exist on the right of each group if
groupLen is positive else on the left if
groupLen is negative) are ignored. If
emptyAsZero is false
then all found empty
groups are ignored else treated as filled with zeros. If
padArray is true
then the resulting array
is always aligned on the group boundary. If groupLen
is zero then grouping is not used and all the found
separator characters are simply ignored. If an illegal
character (neither a hexadecimal digit nor separator)
is found then ParserException
is thrown. If
length()
of str is zero then the
resulting array length
is zero too.
str
- the string (must be non-null
), which region to
parse.beginIndex
- the string region beginning index (must be in the range),
inclusive.endIndex
- the string region ending index (must be in the range), exclusive.separator
- the group delimiter character.emptyAsZero
- true
if a particular group contains no digits then
it is treated as if it contains zero digits otherwise this group
is ignored.groupLen
- the byte
length of each group (in the absolute
value) and the alignment side specifier (if negative then the
right-side alignment is used else left-side one).padArray
- true
if the resulting byte
array is
zero-padded to the group boundary.
null
array, but may be with zero
length
) represented by str region.
java.lang.NullPointerException
- if str is null
.
java.lang.StringIndexOutOfBoundsException
- if beginIndex is negative, or if endIndex
is less than beginIndex or is greater than
length()
of str.
java.lang.OutOfMemoryError
- if there is not enough memory.
ParserException
- if str region cannot be decoded (parsed) properly
(error is set to 1
or 2
in
the exception, meaning an illegal character is found or a group
overflow occurs at index, respectively).toHexString(byte[], int, int, boolean, char, int, boolean)
,
toBase64String(byte[], int, int)
,
parseBase64String(java.lang.String, int, int)
public static final java.lang.String toBase64String(byte[] array, int offset, int len) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
byte
array region is converted to a single
character from the alphabet of 'A-Za-z0-9+/'; at the end if the
region length is not aligned to a six-bit boundary then some '='
characters are added (one for every missing six-bit group).
Negative len is treated as zero. The resulting string
is 'in-line' and without spaces (and with non-zero
length()
if and only if len is positive).
array
- the array (must be non-null
) to be converted.offset
- the first index (must be in the range) of the region to be
converted.len
- the length of the region to be converted.
null
) of the
specified region.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).
java.lang.OutOfMemoryError
- if there is not enough memory.toString()
,
toString(byte[], int, int, char, boolean)
,
toHexString(byte[], int, int, boolean, char, int, boolean)
,
parseBase64String(java.lang.String, int, int)
,
parseHexString(java.lang.String, int, int,
char, boolean, int, boolean)
public static final byte[] parseBase64String(java.lang.String str, int beginIndex, int endIndex) throws java.lang.NullPointerException, java.lang.StringIndexOutOfBoundsException, ParserException
toBase64String()
method. Any
found space, tab, new-line, carriage-return and form-feed
characters are ignored. Padding character ('=') may be used at
any place (not only at the end). If an illegal character (not
from 'A-Za-z0-9+/' alphabet) is found then
ParserException
is thrown. If length()
of str is zero then the resulting array
length
is zero too.
str
- the string (must be non-null
), which region to
parse.beginIndex
- the string region beginning index (must be in the range),
inclusive.endIndex
- the string region ending index (must be in the range), exclusive.
null
array, but may be with zero
length
) represented by str region.
java.lang.NullPointerException
- if str is null
.
java.lang.StringIndexOutOfBoundsException
- if beginIndex is negative, or if endIndex
is less than beginIndex or is greater than
length()
of str.
java.lang.OutOfMemoryError
- if there is not enough memory.
ParserException
- if str region cannot be decoded (parsed) properly
(error is set to 1
in the exception,
meaning an illegal character is found at index).toBase64String(byte[], int, int)
,
toHexString(byte[], int, int, boolean, char, int, boolean)
,
parseHexString(java.lang.String, int, int,
char, boolean, int, boolean)
public static final int hashCode(byte[] array) throws java.lang.NullPointerException
array
- the array (must be non-null
) to evaluate hash of.
java.lang.NullPointerException
- if array is null
.array()
,
hashCode()
,
fill(byte[], int, int, byte)
,
reverse(byte[])
,
sumOf(byte[], int, int, boolean)
,
countNonZero(byte[])
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte, int, byte[])
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
,
mismatches(byte[], int, byte[], int, int)
public static final boolean equals(byte[] arrayA, byte[] arrayB) throws java.lang.NullPointerException
true
if and only if both of the
arrays are of the same length and all the elements of the first
array are equal to the corresponding elements of the second
array.
arrayA
- the first array (must be non-null
) to be compared.arrayB
- the second array (must be non-null
) to compare with.
true
if and only if arrayA content is the
same as arrayB content.
java.lang.NullPointerException
- if arrayA is null
or arrayB is
null
.array()
,
equals(java.lang.Object)
,
fill(byte[], int, int, byte)
,
reverse(byte[])
,
subtractFrom(byte[], byte[])
,
scalarMul(byte[], byte[], boolean)
,
sumOf(byte[], int, int, boolean)
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte, int, byte[])
,
indexOf(byte[], int, int, int, byte[])
,
lastIndexOf(byte[], int, int, int, byte[])
,
hashCode(byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
,
mismatches(byte[], int, byte[], int, int)
public static final int mismatches(byte[] arrayA, int offsetA, byte[] arrayB, int offsetB, int len) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
arrayA
- the first array (must be non-null
) to be compared.offsetA
- the first index (must be in the range) of the first region.arrayB
- the second array (must be non-null
) to compare with.offsetB
- the first index (must be in the range) of the second region.len
- the length of the regions.
java.lang.NullPointerException
- if arrayA is null
or arrayB is
null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offsetA is negative
or is greater than length
of arrayA minus
len, or offsetB is negative or is greater
than length
of arrayB minus
len).array()
,
fill(byte[], int, int, byte)
,
reverse(byte[])
,
subtractFrom(byte[], byte[])
,
scalarMul(byte[], byte[], boolean)
,
sumOf(byte[], int, int, boolean)
,
countNonZero(byte[])
,
hashCode(byte[])
,
equals(byte[], byte[])
,
compare(byte[], int, int, byte[], int, int, boolean)
public static final int compare(byte[] arrayA, int offsetA, int lenA, byte[] arrayB, int offsetB, int lenB, boolean isUnsigned) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
byte
values (the absolute
value of the result, in fact, is the distance between the first
found mismatch and the end of the bigger-length region). Negative
lenA is treated as zero. Negative lenB is
treated as zero. Important notes: the content of array regions is
compared before comparing their length.
arrayA
- the first array (must be non-null
) to be compared.offsetA
- the first index (must be in the range) of the first region.lenA
- the length of the first region.arrayB
- the second array (must be non-null
) to compare with.offsetB
- the first index (must be in the range) of the second region.lenB
- the length of the second region.isUnsigned
- true
if and only if array elements are (treated as)
unsigned.
java.lang.NullPointerException
- if arrayA is null
or arrayB is
null
.
java.lang.ArrayIndexOutOfBoundsException
- if lenA is positive and (offsetA is
negative or is greater than length
of
arrayA minus lenA), or if lenB
is positive and (offsetB is negative or is greater
than length
of arrayB minus
lenB).array()
,
greaterThan(java.lang.Object)
,
fill(byte[], int, int, byte)
,
reverse(byte[])
,
scalarMul(byte[], byte[], boolean)
,
polynome(int, byte[], boolean)
,
sumOf(byte[], int, int, boolean)
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte, int, byte[])
,
hashCode(byte[])
,
equals(byte[], byte[])
,
mismatches(byte[], int, byte[], int, int)
public static final void counterSort(byte[] array, int offset, int len, boolean isUnsigned) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
(BYTE_MASK + 1)
integer values is allocated. The
algorithm cost is linear. Negative len is treated as
zero. If an exception is thrown then array remains
unchanged. Else the region content is altered.
array
- the array (must be non-null
) to be sorted.offset
- the first index (must be in the range) of the region to sort.len
- the length of the region to sort.isUnsigned
- true
if and only if array elements are (treated as)
unsigned.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).
java.lang.OutOfMemoryError
- if there is not enough memory.array()
,
binarySearch(byte[], int, int, byte, boolean)
,
fill(byte[], int, int, byte)
public static final int binarySearch(byte[] array, int offset, int len, byte value, boolean isUnsigned) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
O(log(len))
. Negative len is treated as
zero. If value is not found then
(-result - 1)
is the offset of the insertion point
for value.
array
- the sorted array (must be non-null
) to be searched
in.offset
- the first index (must be in the range) of the region to search
in.len
- the length of the region to search in.value
- the value to search for.isUnsigned
- true
if and only if value and array
elements are (treated as) unsigned.
(-insertionOffset - 1)
(a negative integer) if not
found.
java.lang.NullPointerException
- if array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of array minus
len).array()
,
indexOf(byte, int, byte[])
,
lastIndexOf(byte, int, byte[])
,
counterSort(byte[], int, int, boolean)
,
fill(byte[], int, int, byte)
,
toString(byte[], int, int, char, boolean)
public java.lang.Object clone()
this
object.
This method creates a new instance of the class of this object
and initializes its array with a copy of
array of this
vector.
clone
in interface ReallyCloneable
clone
in class java.lang.Object
null
and != this
) of
this
instance.
java.lang.OutOfMemoryError
- if there is not enough memory.ByteVector()
,
array()
,
getByteAt(int)
,
equals(java.lang.Object)
public int hashCode()
this
vector to
produce a single hash code value.
hashCode
in class java.lang.Object
this
object.hashCode(byte[])
,
array()
,
length()
,
getByteAt(int)
,
equals(java.lang.Object)
public boolean equals(java.lang.Object obj)
this
object is equal to the
specified one.
This method returns true
if and only if
obj is instance of this vector class and all elements
of this
vector are equal to the corresponding
elements of obj vector.
equals
in class java.lang.Object
obj
- the object (may be null
) with which to compare.
true
if and only if this
value is the
same as obj value.ByteVector()
,
equals(byte[], byte[])
,
array()
,
length()
,
getByteAt(int)
,
hashCode()
,
greaterThan(java.lang.Object)
public boolean greaterThan(java.lang.Object obj)
true
if and only if obj is
instance of this
class and this
object
is greater than the specified object. Vectors are compared in the
unsigned element-by-element manner, starting at index
0
.
greaterThan
in interface Sortable
obj
- the second compared object (may be null
).
true
if obj is comparable with
this
and this
object is greater than
obj, else false
.compare(byte[], int, int, byte[], int, int, boolean)
,
array()
,
length()
,
getByteAt(int)
,
equals(java.lang.Object)
public java.lang.String toString()
this
vector to its 'in-line' string
representation.
The decimal string representations of unsigned byte
values of the wrapped array are placed into the
resulting string in the direct index order, delimited by a single
space.
toString
in class java.lang.Object
null
) of
this
object.
java.lang.OutOfMemoryError
- if there is not enough memory.toString(byte[], int, int, char, boolean)
,
toHexString(byte[], int, int, boolean, char, int, boolean)
,
toBase64String(byte[], int, int)
,
array()
,
length()
public void integrityCheck()
this
object for its integrity.
For debug purpose only.
integrityCheck
in interface Verifiable
java.lang.InternalError
- if integrity violation is detected.ByteVector(byte[])
,
setArray(byte[])
,
array()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |