anon.util
Class Util

java.lang.Object
  extended by anon.util.Util

public final class Util
extends java.lang.Object


Nested Class Summary
static interface Util.Comparable
           
static class Util.IntegerSortAsc
           
static class Util.IntegerSortDesc
           
static class Util.LongSortAsc
           
static class Util.LongSortDesc
           
static class Util.StringSortAsc
           
 
Field Summary
static int MAX_FORMAT_ALL
           
static int MAX_FORMAT_BYTES
           
static int MAX_FORMAT_GBIT_PER_SEC
           
static int MAX_FORMAT_GBYTES
           
static int MAX_FORMAT_KBIT_PER_SEC
           
static int MAX_FORMAT_KBYTES
           
static int MAX_FORMAT_MBIT_PER_SEC
           
static int MAX_FORMAT_MBYTES
           
static java.lang.String VERSION_FORMAT
          Defines the format of version numbers in the AN.ON project.
private static java.lang.String WHITESPACE
           
private static java.lang.String WHITESPACE_ENCODED
           
 
Constructor Summary
private Util()
          This class works without being initialised and is completely static.
 
Method Summary
static boolean arraysEqual(byte[] arrayOne, byte[] arrayTwo)
          Tests if two byte arrays are equal.
static boolean arraysEqual(byte[] a_arrayA, int a_Aoff, byte[] a_arrayB, int a_Boff, int a_length)
          Tests if a_length positions of two arrays are equal.
static boolean arraysEqual(char[] arrayOne, char[] arrayTwo)
          Tests if two charactet arrays are equal.
private static void bubbleSortStrings(java.util.Vector a_vector, java.lang.String[] buffer, int[] bufferIndices)
          Uses the Bubble Sort method to sort a vector of objects by comparing the output of the toString() method.
static void closeStream(java.io.InputStream a_input)
           
static void closeStream(java.io.OutputStream a_input)
           
static java.lang.String colonizeSKI(java.lang.String a_ski)
           
static long convertVersionStringToNumber(java.lang.String a_version)
          Converts a version string of the form xx.xx.xxx to a number
static void copyStream(java.io.InputStream a_input, java.io.OutputStream a_output)
           
static InfoServiceDBEntry[] createDefaultInfoServices(java.lang.String[] a_defaultNames, java.lang.String[] a_defaultHostNames, int[][] a_defaultPortNumbers)
           
static java.lang.String cutString(java.lang.String a_string, int a_maxLength)
           
private static int divide(java.lang.String[] a_IDs, java.lang.String[] a_values, int a_left, int a_right)
           
private static int divide(java.util.Vector a_vec, int a_left, int a_right, Util.Comparable c)
           
static java.lang.String encodeWhiteSpaces(java.lang.String stringWithWhitespaces)
           
static java.lang.String formatBytesValueOnlyUnit(long c)
           
static java.lang.String formatBytesValueOnlyUnit(long c, int a_maxFormat)
           
static java.lang.String formatBytesValueWithoutUnit(long c)
           
static java.lang.String formatBytesValueWithoutUnit(long c, int a_maxFormat)
          Returns a formated number which respects different units (Bytes, kBytes, MBytes, GBytes)
static java.lang.String formatBytesValueWithUnit(long c)
          Returns the desired unit for this amount of Bytes (Bytes, kBytes, MBytes,GBytes)
static java.lang.String formatBytesValueWithUnit(long c, int a_maxFormat)
           
static java.lang.String formatKbitPerSecValueOnlyUnit(long c)
           
static java.lang.String formatKbitPerSecValueOnlyUnit(long c, int a_maxFormat)
           
static java.lang.String formatKbitPerSecValueWithoutUnit(long c)
           
static java.lang.String formatKbitPerSecValueWithoutUnit(long c, int a_maxFormat)
           
static java.lang.String formatKbitPerSecValueWithUnit(long c)
           
static java.lang.String formatKbitPerSecValueWithUnit(long c, int a_maxFormat)
           
static java.lang.String getStackTrace(java.lang.Throwable a_t)
          Gets the stack trace of a Throwable as String.
static java.lang.String getStaticFieldValue(java.lang.Class a_class, java.lang.String a_fieldName)
          Uses the reflection API to get the value of a static field in the given class, if the field is present.
private static boolean isUmlaut(char a_character, java.lang.String[] a_transformedUmlauts, int a_position)
          Tests if a character is an umlaut and, if yes, writes the umlaut in an ASCII form to the array of transformed umlauts at the specified position.
static java.lang.String normaliseString(java.lang.String a_string, int a_normLength)
          Normalises a String to the given length by filling it up with spaces, if it does not already have this length or is even longer.
static double parseDouble(java.lang.String a_string)
          Implementation of parseFloat not implemented in JDK 1.1.8
private static void quicksort(java.lang.String[] a_IDs, java.lang.String[] a_values, int a_left, int a_right)
           
private static void quicksort(java.util.Vector a_vec, int a_left, int a_right, Util.Comparable c)
           
static java.lang.String replaceAll(java.lang.String a_source, java.lang.String a_toReplace, java.lang.String a_replaceWith)
          Since JDK 1.1.8 does not provide String.replaceAll(), this is an equivalent method.
static java.lang.String replaceAll(java.lang.String a_source, java.lang.String a_toReplace, java.lang.String a_replaceWith, java.lang.String[] omit)
          String replace algorithm.
static void sort(java.lang.String[] a_ids, java.lang.String[] a_values)
           
static void sort(java.util.Vector a_vec, Util.Comparable c)
           
static java.util.Vector sortStrings(java.util.Vector a_vector)
          Sorts a Vector alphabetically using the toString() method of each object.
static java.lang.String stripString(java.lang.String a_string, java.lang.String a_charactersToStrip)
           
private static void swap(java.lang.String[] a_IDs, java.lang.String[] a_values, int a, int b)
           
private static void swap(java.util.Vector a_vec, int a, int b)
           
static java.lang.Object[] toArray(java.lang.Object a_object)
          Creates an Object array from a single Object.
static java.lang.String toHTMLEntities(java.lang.String buf)
           
static java.util.Vector toVector(java.lang.Object a_object)
          Creates a Vector from a single Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION_FORMAT

public static final java.lang.String VERSION_FORMAT
Defines the format of version numbers in the AN.ON project.

See Also:
Constant Field Values

WHITESPACE_ENCODED

private static final java.lang.String WHITESPACE_ENCODED
See Also:
Constant Field Values

WHITESPACE

private static final java.lang.String WHITESPACE
See Also:
Constant Field Values

MAX_FORMAT_BYTES

public static final int MAX_FORMAT_BYTES
See Also:
Constant Field Values

MAX_FORMAT_KBYTES

public static final int MAX_FORMAT_KBYTES
See Also:
Constant Field Values

MAX_FORMAT_MBYTES

public static final int MAX_FORMAT_MBYTES
See Also:
Constant Field Values

MAX_FORMAT_GBYTES

public static final int MAX_FORMAT_GBYTES
See Also:
Constant Field Values

MAX_FORMAT_KBIT_PER_SEC

public static final int MAX_FORMAT_KBIT_PER_SEC
See Also:
Constant Field Values

MAX_FORMAT_MBIT_PER_SEC

public static final int MAX_FORMAT_MBIT_PER_SEC
See Also:
Constant Field Values

MAX_FORMAT_GBIT_PER_SEC

public static final int MAX_FORMAT_GBIT_PER_SEC
See Also:
Constant Field Values

MAX_FORMAT_ALL

public static final int MAX_FORMAT_ALL
See Also:
Constant Field Values
Constructor Detail

Util

private Util()
This class works without being initialised and is completely static. Therefore, the constructor is not needed and private.

Method Detail

cutString

public static java.lang.String cutString(java.lang.String a_string,
                                         int a_maxLength)

stripString

public static java.lang.String stripString(java.lang.String a_string,
                                           java.lang.String a_charactersToStrip)

normaliseString

public static java.lang.String normaliseString(java.lang.String a_string,
                                               int a_normLength)
Normalises a String to the given length by filling it up with spaces, if it does not already have this length or is even longer.

Parameters:
a_string - a String
a_normLength - a length to normalise the String
Returns:
the normalised String

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable a_t)
Gets the stack trace of a Throwable as String.

Parameters:
a_t - a Throwable
Returns:
the stack trace of a throwable as String

arraysEqual

public static boolean arraysEqual(byte[] arrayOne,
                                  byte[] arrayTwo)
Tests if two byte arrays are equal.

Parameters:
arrayOne - a byte array
arrayTwo - another byte array
Returns:
true if the two byte arrays are equal or both arrays are null; false otherwise

arraysEqual

public static boolean arraysEqual(char[] arrayOne,
                                  char[] arrayTwo)
Tests if two charactet arrays are equal.

Parameters:
arrayOne - a charactet array
arrayTwo - another charactet array
Returns:
true if the two charactet arrays are equal or both arrays are null; false otherwise

arraysEqual

public static final boolean arraysEqual(byte[] a_arrayA,
                                        int a_Aoff,
                                        byte[] a_arrayB,
                                        int a_Boff,
                                        int a_length)
Tests if a_length positions of two arrays are equal.

Parameters:
a_arrayA - byte[]
a_Aoff - int
a_arrayB - byte[]
a_Boff - int
a_length - int
Returns:
boolean

toVector

public static java.util.Vector toVector(java.lang.Object a_object)
Creates a Vector from a single Object.

Parameters:
a_object - an Object
Returns:
a Vector containing the given Object or an empty Vector if the Object was null

toArray

public static java.lang.Object[] toArray(java.lang.Object a_object)
Creates an Object array from a single Object.

Parameters:
a_object - an Object
Returns:
an Object array containing the given Object or an empty array if the Object was null

swap

private static void swap(java.lang.String[] a_IDs,
                         java.lang.String[] a_values,
                         int a,
                         int b)

sortStrings

public static java.util.Vector sortStrings(java.util.Vector a_vector)
Sorts a Vector alphabetically using the toString() method of each object.

Parameters:
a_vector - a Vector
Returns:
an alphabetically sorted Vector

parseDouble

public static double parseDouble(java.lang.String a_string)
                          throws java.lang.NumberFormatException
Implementation of parseFloat not implemented in JDK 1.1.8

Parameters:
a_string - String
Returns:
float
Throws:
java.lang.NumberFormatException

sort

public static void sort(java.lang.String[] a_ids,
                        java.lang.String[] a_values)

divide

private static int divide(java.lang.String[] a_IDs,
                          java.lang.String[] a_values,
                          int a_left,
                          int a_right)

quicksort

private static void quicksort(java.lang.String[] a_IDs,
                              java.lang.String[] a_values,
                              int a_left,
                              int a_right)

sort

public static void sort(java.util.Vector a_vec,
                        Util.Comparable c)

divide

private static int divide(java.util.Vector a_vec,
                          int a_left,
                          int a_right,
                          Util.Comparable c)

quicksort

private static void quicksort(java.util.Vector a_vec,
                              int a_left,
                              int a_right,
                              Util.Comparable c)

swap

private static void swap(java.util.Vector a_vec,
                         int a,
                         int b)

bubbleSortStrings

private static void bubbleSortStrings(java.util.Vector a_vector,
                                      java.lang.String[] buffer,
                                      int[] bufferIndices)
Uses the Bubble Sort method to sort a vector of objects by comparing the output of the toString() method.

Parameters:
a_vector - a Vector
buffer - a buffer
bufferIndices - indices for the buffer

isUmlaut

private static boolean isUmlaut(char a_character,
                                java.lang.String[] a_transformedUmlauts,
                                int a_position)
Tests if a character is an umlaut and, if yes, writes the umlaut in an ASCII form to the array of transformed umlauts at the specified position.

Parameters:
a_character - a character; must be lower case !
a_transformedUmlauts - an array of transformed umlauts
a_position - the position to write into the array of umlauts; if the character is not an umlaut, 'null' is written at this position, otherwise the character transformed into an ASCII form
Returns:
if the given character is an umlaut; false otherwise

convertVersionStringToNumber

public static long convertVersionStringToNumber(java.lang.String a_version)
                                         throws java.lang.NumberFormatException
Converts a version string of the form xx.xx.xxx to a number

Parameters:
a_version - a version string of the form xx.xx.xxx
Returns:
the given version string as number
Throws:
java.lang.NumberFormatException - if the version has an illegal format

replaceAll

public static java.lang.String replaceAll(java.lang.String a_source,
                                          java.lang.String a_toReplace,
                                          java.lang.String a_replaceWith)
Since JDK 1.1.8 does not provide String.replaceAll(), this is an equivalent method.


replaceAll

public static java.lang.String replaceAll(java.lang.String a_source,
                                          java.lang.String a_toReplace,
                                          java.lang.String a_replaceWith,
                                          java.lang.String[] omit)
String replace algorithm. Strings specified in omit will not be replaced even if their prefices matches a_toReplace

Parameters:
a_source - Source String
a_toReplace - substring which is to be replaced
a_replaceWith - string which should replace a_toReplace
omit - Strings that not be replaced when their prefix matches a_toReplace
Returns:
a new string with all replacements

encodeWhiteSpaces

public static java.lang.String encodeWhiteSpaces(java.lang.String stringWithWhitespaces)

closeStream

public static void closeStream(java.io.InputStream a_input)

closeStream

public static void closeStream(java.io.OutputStream a_input)

copyStream

public static void copyStream(java.io.InputStream a_input,
                              java.io.OutputStream a_output)
                       throws java.io.IOException
Throws:
java.io.IOException

getStaticFieldValue

public static java.lang.String getStaticFieldValue(java.lang.Class a_class,
                                                   java.lang.String a_fieldName)
Uses the reflection API to get the value of a static field in the given class, if the field is present.

Parameters:
a_class - a Class
a_fieldName - the field to read the value from
Returns:
the value of a static field in the given class or null if the value or field is not present

colonizeSKI

public static java.lang.String colonizeSKI(java.lang.String a_ski)

createDefaultInfoServices

public static InfoServiceDBEntry[] createDefaultInfoServices(java.lang.String[] a_defaultNames,
                                                             java.lang.String[] a_defaultHostNames,
                                                             int[][] a_defaultPortNumbers)
                                                      throws java.lang.Exception
Throws:
java.lang.Exception

formatKbitPerSecValueWithUnit

public static java.lang.String formatKbitPerSecValueWithUnit(long c)

formatKbitPerSecValueWithUnit

public static java.lang.String formatKbitPerSecValueWithUnit(long c,
                                                             int a_maxFormat)

formatKbitPerSecValueOnlyUnit

public static java.lang.String formatKbitPerSecValueOnlyUnit(long c)

formatKbitPerSecValueOnlyUnit

public static java.lang.String formatKbitPerSecValueOnlyUnit(long c,
                                                             int a_maxFormat)

formatKbitPerSecValueWithoutUnit

public static java.lang.String formatKbitPerSecValueWithoutUnit(long c)

formatKbitPerSecValueWithoutUnit

public static java.lang.String formatKbitPerSecValueWithoutUnit(long c,
                                                                int a_maxFormat)

formatBytesValueWithUnit

public static java.lang.String formatBytesValueWithUnit(long c)
Returns the desired unit for this amount of Bytes (Bytes, kBytes, MBytes,GBytes)


formatBytesValueWithUnit

public static java.lang.String formatBytesValueWithUnit(long c,
                                                        int a_maxFormat)

formatBytesValueOnlyUnit

public static java.lang.String formatBytesValueOnlyUnit(long c)

formatBytesValueOnlyUnit

public static java.lang.String formatBytesValueOnlyUnit(long c,
                                                        int a_maxFormat)

formatBytesValueWithoutUnit

public static java.lang.String formatBytesValueWithoutUnit(long c)

formatBytesValueWithoutUnit

public static java.lang.String formatBytesValueWithoutUnit(long c,
                                                           int a_maxFormat)
Returns a formated number which respects different units (Bytes, kBytes, MBytes, GBytes)


toHTMLEntities

public static java.lang.String toHTMLEntities(java.lang.String buf)