|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.util.Utils
This class provides a variety of programmer utility functions.
| Constructor Summary | |
Utils()
|
|
| Method Summary | |
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 int |
compare(Object one,
Object two)
This attempts to compare two objects which may or may not implement the Comparable interface. |
static void |
copy(Object source,
Object dest)
This copies data from the source to the destination. |
static void |
copyField(String field,
Object source,
Object dest,
Reflect theClass)
This copies one field from the source object to the destination object using the provided Reflect Object as the class specifier. |
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 String |
fileLengthDisplay(int len)
|
static int |
findCRLF(byte[] data,
int start,
int length)
Find the index of a CRLF sequence or LF character in byte data. |
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. |
protected static boolean |
merge(Handle h,
int[] source,
int sourceLength,
int one,
int two,
int length,
int[] dest,
boolean descending,
CompareInts comparer)
|
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 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 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(int[] values,
int length,
CompareInts comparer,
boolean descending)
This sorts a set of integers in place using the provided CompareInts object. |
static void |
sort(Object[] values,
Comparer comparer,
boolean descending)
This sorts the objects in place. |
static Object |
subArray(Object original,
int start,
int length)
Get a sub-array containing a set of elements from an existing array. |
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 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)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Constructor Detail |
public Utils()
| Method Detail |
public static int compare(Object one,
Object two)
one - The first object.two - The second object
public static Object getCopy(Object toCopy)
toCopy - The object to copy.
public static void copyField(String field,
Object source,
Object dest,
Reflect theClass)
In order for this to work the Class AND the Field must be public.
field - The field name.source - The source object.dest - The destination object.theClass - A Reflect object representing the exact class which is having its field copied.
public static void copy(Object source,
Object dest)
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 void sort(int[] values,
int length,
CompareInts comparer,
boolean descending)
values - the sequence of integers to sort.length - The length of the sequence.comparer - This compares two integer values together. Note that this does not imply a
numerical comparison. The integers may represent indexes into an object array or they may
represent locations for data in a file. Therefore comparing the two integers may involve
comparing the data they refer to rather than their numeric values.descending - Set this true if you want to sort in descending order.
Note that this is a blocking call - while this sort is going on all other threads are stopped.
protected static boolean merge(Handle h,
int[] source,
int sourceLength,
int one,
int two,
int length,
int[] dest,
boolean descending,
CompareInts comparer)
public static boolean sort(Handle h,
int[] what,
int length,
CompareInts comparer,
boolean descending)
public static boolean sort(Handle h,
Object[] values,
Comparer comparer,
boolean descending)
public static void sort(Object[] values,
Comparer comparer,
boolean descending)
values - The Object values to sort.comparer - An object that will compare the Objects.descending - Set this true if you want to sort in descending order.
Note that this is a blocking call - while this sort is going on all other threads are stopped.
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 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 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 bytes
public static byte[] encodeJavaUtf8String(String str)
str - the String 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 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 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 int findCRLF(byte[] data,
int start,
int length)
data - The byte data.start - The start index of the data.length - The number of data bytes.
public static int makeHashCode(byte[] data,
int start,
int length)
public static int makeHashCode(char[] data,
int start,
int length)
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 Object subArray(Object original,
int start,
int length)
original - The original array.start - The first element to copy.length - The number of elements to copy.
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 void zeroArrayRegion(Object array,
int offset,
int length)
public static String fileLengthDisplay(int len)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||