com.ibm.util
Class Utility

java.lang.Object
  |
  +--com.ibm.util.Utility

public final class Utility
extends java.lang.Object


Field Summary
static java.lang.String LINE_SEPARATOR
           
 
Constructor Summary
Utility()
           
 
Method Summary
static boolean arrayEquals(double[] source, java.lang.Object target)
          Convenience utility to compare two double[]s Ought to be in System
static boolean arrayEquals(int[] source, java.lang.Object target)
          Convenience utility to compare two int[]s Ought to be in System
static boolean arrayEquals(java.lang.Object[] source, java.lang.Object target)
          Convenience utility to compare two Object[]s.
static boolean arrayEquals(java.lang.Object source, java.lang.Object target)
          Convenience utility to compare two Object[]s Ought to be in System
static boolean arrayRegionMatches(double[] source, int sourceStart, double[] target, int targetStart, int len)
          Convenience utility to compare two arrays of doubles.
static boolean arrayRegionMatches(int[] source, int sourceStart, int[] target, int targetStart, int len)
          Convenience utility to compare two int[]s.
static boolean arrayRegionMatches(java.lang.Object[] source, int sourceStart, java.lang.Object[] target, int targetStart, int len)
          Convenience utility to compare two Object[]s Ought to be in System.
static java.lang.String arrayToRLEString(byte[] a)
          Construct a string representing a byte array.
static java.lang.String arrayToRLEString(char[] a)
          Construct a string representing a char array.
static java.lang.String arrayToRLEString(int[] a)
          Construct a string representing an int array.
static java.lang.String arrayToRLEString(short[] a)
          Construct a string representing a short array.
static java.lang.String escape(java.lang.String s)
          Convert characters outside the range U+0020 to U+007F to Unicode escapes, and convert backslash to a double backslash.
static java.lang.String formatForSource(java.lang.String s)
          Format a String for representation in a source file.
static java.lang.String hex(char ch)
          Convert a char to 4 hex uppercase digits.
static java.lang.StringBuffer hex(char ch, java.lang.StringBuffer output)
          Convert a char to 4 hex uppercase digits.
static java.lang.String hex(java.lang.String s)
          Convert a string to comma-separated groups of 4 hex uppercase digits.
static java.lang.String hex(java.lang.StringBuffer s)
          Convert a string to comma-separated groups of 4 hex uppercase digits.
static java.lang.StringBuffer hex(java.lang.String s, java.lang.StringBuffer result)
          Convert a string to comma-separated groups of 4 hex uppercase digits.
static int lookup(java.lang.String source, java.lang.String[] target)
          Look up a given string in a string array.
static boolean objectEquals(java.lang.Object source, java.lang.Object target)
          Convenience utility.
static byte[] RLEStringToByteArray(java.lang.String s)
          Construct an array of bytes from a run-length encoded string.
static char[] RLEStringToCharArray(java.lang.String s)
          Construct an array of shorts from a run-length encoded string.
static int[] RLEStringToIntArray(java.lang.String s)
          Construct an array of ints from a run-length encoded string.
static short[] RLEStringToShortArray(java.lang.String s)
          Construct an array of shorts from a run-length encoded string.
static void split(java.lang.String s, char divider, java.lang.String[] output)
          Split a string into pieces based on the given divider character
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static java.lang.String LINE_SEPARATOR
Constructor Detail

Utility

public Utility()
Method Detail

arrayEquals

public static final boolean arrayEquals(java.lang.Object[] source,
                                        java.lang.Object target)
Convenience utility to compare two Object[]s. Ought to be in System

arrayEquals

public static final boolean arrayEquals(int[] source,
                                        java.lang.Object target)
Convenience utility to compare two int[]s Ought to be in System

arrayEquals

public static final boolean arrayEquals(double[] source,
                                        java.lang.Object target)
Convenience utility to compare two double[]s Ought to be in System

arrayEquals

public static final boolean arrayEquals(java.lang.Object source,
                                        java.lang.Object target)
Convenience utility to compare two Object[]s Ought to be in System

arrayRegionMatches

public static final boolean arrayRegionMatches(java.lang.Object[] source,
                                               int sourceStart,
                                               java.lang.Object[] target,
                                               int targetStart,
                                               int len)
Convenience utility to compare two Object[]s Ought to be in System.
Parameters:
len - the length to compare. The start indices and start+len must be valid.

arrayRegionMatches

public static final boolean arrayRegionMatches(int[] source,
                                               int sourceStart,
                                               int[] target,
                                               int targetStart,
                                               int len)
Convenience utility to compare two int[]s.
Parameters:
len - the length to compare. The start indices and start+len must be valid. Ought to be in System

arrayRegionMatches

public static final boolean arrayRegionMatches(double[] source,
                                               int sourceStart,
                                               double[] target,
                                               int targetStart,
                                               int len)
Convenience utility to compare two arrays of doubles.
Parameters:
len - the length to compare. The start indices and start+len must be valid. Ought to be in System

objectEquals

public static final boolean objectEquals(java.lang.Object source,
                                         java.lang.Object target)
Convenience utility. Does null checks on objects, then calls equals.

arrayToRLEString

public static final java.lang.String arrayToRLEString(int[] a)
Construct a string representing an int array. Use run-length encoding. A character represents itself, unless it is the ESCAPE character. Then the following notations are possible: ESCAPE ESCAPE ESCAPE literal ESCAPE n c n instances of character c Since an encoded run occupies 3 characters, we only encode runs of 4 or more characters. Thus we have n > 0 and n != ESCAPE and n <= 0xFFFF. If we encounter a run where n == ESCAPE, we represent this as: c ESCAPE n-1 c The ESCAPE value is chosen so as not to collide with commonly seen values.

arrayToRLEString

public static final java.lang.String arrayToRLEString(short[] a)
Construct a string representing a short array. Use run-length encoding. A character represents itself, unless it is the ESCAPE character. Then the following notations are possible: ESCAPE ESCAPE ESCAPE literal ESCAPE n c n instances of character c Since an encoded run occupies 3 characters, we only encode runs of 4 or more characters. Thus we have n > 0 and n != ESCAPE and n <= 0xFFFF. If we encounter a run where n == ESCAPE, we represent this as: c ESCAPE n-1 c The ESCAPE value is chosen so as not to collide with commonly seen values.

arrayToRLEString

public static final java.lang.String arrayToRLEString(char[] a)
Construct a string representing a char array. Use run-length encoding. A character represents itself, unless it is the ESCAPE character. Then the following notations are possible: ESCAPE ESCAPE ESCAPE literal ESCAPE n c n instances of character c Since an encoded run occupies 3 characters, we only encode runs of 4 or more characters. Thus we have n > 0 and n != ESCAPE and n <= 0xFFFF. If we encounter a run where n == ESCAPE, we represent this as: c ESCAPE n-1 c The ESCAPE value is chosen so as not to collide with commonly seen values.

arrayToRLEString

public static final java.lang.String arrayToRLEString(byte[] a)
Construct a string representing a byte array. Use run-length encoding. Two bytes are packed into a single char, with a single extra zero byte at the end if needed. A byte represents itself, unless it is the ESCAPE_BYTE. Then the following notations are possible: ESCAPE_BYTE ESCAPE_BYTE ESCAPE_BYTE literal ESCAPE_BYTE n b n instances of byte b Since an encoded run occupies 3 bytes, we only encode runs of 4 or more bytes. Thus we have n > 0 and n != ESCAPE_BYTE and n <= 0xFF. If we encounter a run where n == ESCAPE_BYTE, we represent this as: b ESCAPE_BYTE n-1 b The ESCAPE_BYTE value is chosen so as not to collide with commonly seen values.

RLEStringToIntArray

public static final int[] RLEStringToIntArray(java.lang.String s)
Construct an array of ints from a run-length encoded string.

RLEStringToShortArray

public static final short[] RLEStringToShortArray(java.lang.String s)
Construct an array of shorts from a run-length encoded string.

RLEStringToCharArray

public static final char[] RLEStringToCharArray(java.lang.String s)
Construct an array of shorts from a run-length encoded string.

RLEStringToByteArray

public static final byte[] RLEStringToByteArray(java.lang.String s)
Construct an array of bytes from a run-length encoded string.

formatForSource

public static final java.lang.String formatForSource(java.lang.String s)
Format a String for representation in a source file. This includes breaking it into lines and escaping characters using octal notation when necessary (control characters and double quotes).

escape

public static final java.lang.String escape(java.lang.String s)
Convert characters outside the range U+0020 to U+007F to Unicode escapes, and convert backslash to a double backslash.

hex

public static java.lang.String hex(char ch)
Convert a char to 4 hex uppercase digits. E.g., hex('a') => "0041".

hex

public static java.lang.String hex(java.lang.String s)
Convert a string to comma-separated groups of 4 hex uppercase digits. E.g., hex('ab') => "0041,0042".

hex

public static java.lang.String hex(java.lang.StringBuffer s)
Convert a string to comma-separated groups of 4 hex uppercase digits. E.g., hex('ab') => "0041,0042".

hex

public static java.lang.StringBuffer hex(char ch,
                                         java.lang.StringBuffer output)
Convert a char to 4 hex uppercase digits. E.g., hex('a') => "0041". Append the output to the given StringBuffer.

hex

public static java.lang.StringBuffer hex(java.lang.String s,
                                         java.lang.StringBuffer result)
Convert a string to comma-separated groups of 4 hex uppercase digits. E.g., hex('ab') => "0041,0042". Append the output to the given StringBuffer.

split

public static void split(java.lang.String s,
                         char divider,
                         java.lang.String[] output)
Split a string into pieces based on the given divider character
Parameters:
s - the string to split
divider - the character on which to split. Occurrences of this character are not included in the output
output - an array to receive the substrings between instances of divider. It must be large enough on entry to accomodate all output. Adjacent instances of the divider character will place empty strings into output. Before returning, output is padded out with empty strings.

lookup

public static int lookup(java.lang.String source,
                         java.lang.String[] target)
Look up a given string in a string array. Returns the index at which the first occurrence of the string was found in the array, or -1 if it was not found.
Parameters:
source - the string to search for
target - the array of zero or more strings in which to look for source
Returns:
the index of target at which source first occurs, or -1 if not found


Copyright (c) 1998-2000 IBM Corporation and others.