public class Utils extends Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static Object |
appendArray(Object original,
Object toAppend)
Join two arrays together to form a new array which contains the elements of the first followed by the elements of the second.
|
static boolean |
canIterate(Object dataSource)
Returns if the object can be used to provide an Iterator or Enumeration.
|
static int |
compare(Object one,
Object two)
This attempts to compare two objects which may or may not implement
the Comparable interface.
|
static String |
decodeJavaUtf8String(byte[] bytes,
int start,
int length)
Decode a String encoded as Java Utf8 bytes.
|
static char[] |
decodeJavaUtf8String(byte[] data,
int start,
int numberOfBytes,
char[] chars,
int offset)
Convert a Java Utf8 byte encoded string into a string of characters.
|
static int |
encodeJavaUtf8String(char[] toEncode,
int offset,
int length,
byte[] destination,
int destOffset)
Encode a String of characters a Java Utf8 encoded bytes.
|
static byte[] |
encodeJavaUtf8String(String str)
Encodes a String as Java Utf8 bytes.
|
static Object |
getCopy(Object toCopy)
This attempts to get a copy of an object.
|
static void |
getIntSequence(int[] sequence,
int first)
This fills the int array with an increasing sequence of integers starting with first.
|
static void |
getIntSequence(int[] sequence,
int destOffset,
int first,
int step,
int length)
This puts a sequence of integers into a int array.
|
static int |
indexOf(Object array,
long lookingFor,
int minIndex,
int maxIndex,
boolean backwards)
Find the index of a value within an array.
|
static int |
makeHashCode(byte[] data,
int start,
int length)
Creates a hashCode from a sequence of bytes.
|
static int |
makeHashCode(char[] data,
int start,
int length)
Creates a hashCode from a sequence of chars.
|
static void |
primitiveArrayFromString(Object obj,
String data)
Decode an array of primitive values, encoded as a String.
|
static String |
primitiveArrayToString(Object obj)
Encode the array of primitive Java values as a String.
|
static void |
putAll(Map src,
Map dest)
Put all items from src into dest using the same keys.
|
static int |
readInt(byte[] source,
int offset,
int numBytes)
This reads an integer value from a byte array with the specified number
of bytes.
|
static long |
readLong(byte[] source,
int offset)
This reads a long value from a byte array as an 8 byte sequence - high byte first.
|
static void |
reorder(Object[] values,
int[] newIndexes)
Reorder the items in values to match the indexes in newIndexes.
|
static void |
reverse(int[] src,
int offset,
int length) |
static int |
sizeofJavaUtf8String(byte[] data,
int start,
int numberOfBytes)
Returns the number of characters needed to store a string which has been
encoded in the Java UTF8 format.
|
static int |
sizeofJavaUtf8String(char[] toEncode,
int start,
int length)
Returns the number of bytes needed to encode a String in the Java UTF8 format.
|
static boolean |
sort(Handle h,
int[] what,
int length,
CompareInts comparer,
boolean descending)
This sorts the array in place.
|
static boolean |
sort(Handle h,
Object[] values,
Comparer comparer,
boolean descending)
This sorts the objects in place.
|
static void |
sort(Handle h,
Vector v,
Comparer comparer,
boolean descending) |
static void |
sort(int[] what,
int length,
CompareInts comparer,
boolean descending)
This sorts the array in place.
|
static void |
sort(Object[] values,
Comparer comparer,
boolean descending)
This sorts the objects in place.
|
static void |
sort(Vector v,
boolean descending) |
static int[] |
sortIndexes(Handle h,
Object[] values,
Comparer comparer,
boolean descending)
This method sorts the indexes of the values array and returns the indexes
as a new array of ints.
|
static void |
textDecode(Encodable obj,
String data)
Encode the fields of the Encodable object.
|
static String |
textEncode(Encodable obj)
Encode the fields of the Encodable object.
|
static ByteArray |
toBytes(int[] src,
int offset,
int length,
ByteArray dest)
Convert a sequence of ints to a sequence of bytes where each integer is represented
as a sequence of 4 bytes - high order byte first.
|
static Enumeration |
toEnumeration(Object dataSource)
This provides an Enumeration of items provided in dataSource, which may itself be
a Vector, Iterator, or an Enumeration itself.
|
static IntArray |
toInts(byte[] src,
int offset,
int length,
IntArray dest)
Convert a sequence of bytes to a sequence of ints where each integer is represented
as a sequence of 4 bytes - high order byte first.
|
static Iterator |
toIterator(Object dataSource)
This provides an Iterator of items provided in dataSource, which may itself be
a java.util.Vector, java.util.Iterator, java.util.Enumeration or an eve.util.Iterator itself.
|
static void |
writeInt(int val,
byte[] dest,
int offset,
int numBytes)
This writes an integer value to a byte array with the specified number
of bytes.
|
static void |
writeLong(long value,
byte[] dest,
int offset)
This writes a long value to a byte array as an 8 byte sequence - high byte first.
|
static void |
zeroArrayRegion(Object array,
int offset,
int length) |
public static int compare(Object one, Object two)
one
- The first object.two
- The second objectpublic static Object getCopy(Object toCopy)
toCopy
- The object to copy.public static void zeroArrayRegion(Object array, int offset, int length)
public static int makeHashCode(byte[] data, int start, int length)
public static int makeHashCode(char[] data, int start, int length)
public static final char[] decodeJavaUtf8String(byte[] data, int start, int numberOfBytes, char[] chars, int offset)
data
- The encoded data bytes.start
- The start index of the data bytes.numberOfBytes
- The number of bytes of encoded data.chars
- The destination array.offset
- The start index of the destination to place the characters.public static int encodeJavaUtf8String(char[] toEncode, int offset, int length, byte[] destination, int destOffset)
toEncode
- The characters to encode.offset
- The start index of the character.length
- The number of characters to encode.destination
- The destination for the bytes.destOffset
- The offset for the destination bytespublic static byte[] encodeJavaUtf8String(String str)
str
- the String to encode.public static final int sizeofJavaUtf8String(byte[] data, int start, int numberOfBytes)
data
- the encoded data.start
- the start location in the data.numberOfBytes
- the number of bytes of encoded data.public static final int sizeofJavaUtf8String(char[] toEncode, int start, int length)
toEncode
- The characters to encode.start
- The start index of the character.length
- The number of characters to encode.public static String decodeJavaUtf8String(byte[] bytes, int start, int length)
bytes
- The encoded bytes.start
- The start index of the encoded bytes.length
- The number of encoded bytes.public static final void writeInt(int val, byte[] dest, int offset, int numBytes)
val
- The byte, short or integer value to write.dest
- The destination array.offset
- The location in the destination to write to.numBytes
- The number of bytes 1, 2 or 4 to write out.public static final int readInt(byte[] source, int offset, int numBytes)
source
- The source of the bytes.offset
- The location in the source.numBytes
- The number of bytes 1, 2 or 4 to read in.public static final long readLong(byte[] source, int offset)
source
- The source of the bytes.offset
- The location in the source.public static final void writeLong(long value, byte[] dest, int offset)
value
- The long value to write.dest
- The destination for the bytes.offset
- The location in the destination to write to.public static void getIntSequence(int[] sequence, int destOffset, int first, int step, int length)
sequence
- The destination for the integers.destOffset
- The index in the destination to start placing the values.first
- The first value.step
- The value to add to each value to get the next value.length
- The number of values to place.public static void getIntSequence(int[] sequence, int first)
public static boolean canIterate(Object dataSource)
dataSource
- the data source to check.public static Enumeration toEnumeration(Object dataSource)
dataSource
- the data source to convert.public static Iterator toIterator(Object dataSource)
public static Object appendArray(Object original, Object toAppend)
original
- The first array. Can be null, in which case only the elements of toAdd will go into the new array.toAppend
- The second array. Can be null, in which case only the elements of original will go into the new array.public static String primitiveArrayToString(Object obj)
See the TextEncoder/TextDecoder objects for how to do this.
obj
- An array of any Java type except Object or array.public static void primitiveArrayFromString(Object obj, String data)
obj
- The array of the correct type and length.data
- The encoded data.public static String textEncode(Encodable obj)
obj
- The object to encode.public static void textDecode(Encodable obj, String data)
obj
- The object to encode.public static boolean sort(Handle h, int[] what, int length, CompareInts comparer, boolean descending)
public static int[] sortIndexes(Handle h, Object[] values, Comparer comparer, boolean descending)
h
- a handle that can be used to monitor and stop the sorting.values
- the values to compare.comparer
- a Comparer to compare the Objects in values. If this is
null a StandardComparer is used.descending
- set true to sort in descending order.public static void reorder(Object[] values, int[] newIndexes)
values
- newIndexes
- public static boolean sort(Handle h, Object[] values, Comparer comparer, boolean descending)
public static void sort(int[] what, int length, CompareInts comparer, boolean descending)
public static void sort(Object[] values, Comparer comparer, boolean descending)
public static void sort(Vector v, boolean descending)
public static int indexOf(Object array, long lookingFor, int minIndex, int maxIndex, boolean backwards)
Searching is done within the range of index from minIndex up to maxIndex-1. If backwards is true searching goes from maxIndex-1 to minIndex (inclusive). Otherwise searching goes from minIndex to maxIndex-1. A return value of -1 indicates that the value was not found.
public static ByteArray toBytes(int[] src, int offset, int length, ByteArray dest)
src
- the source of the int values.offset
- the start of the int values.length
- the number of int values.dest
- an optional destination ByteArray. If it is null a new one is allocated
and returned.public static IntArray toInts(byte[] src, int offset, int length, IntArray dest)
src
- the source of the bytes values.offset
- the start of the byte values.length
- the number of byte values.dest
- an optional destination IntArray. If it is null a new one is allocated
and returned.public static void reverse(int[] src, int offset, int length)