sg.edu.nus.util
Class Tools

java.lang.Object
  extended by sg.edu.nus.util.Tools

public class Tools
extends java.lang.Object

A utility that defines a set of methods used for general purpose, such as Date transformation, string description of Throwable, and numeric type conversion.

Version:
1.0 2006-7-5
Author:
Xu Linhao

Constructor Summary
Tools()
           
 
Method Summary
static int byteArrayToInt(byte[] buf, int start)
          Convert a 4-bytes array to an integer value from the specified start position of the array.
static java.lang.String getAM(java.util.Date d)
          Returns the AM/PM of the date.
static java.lang.String getDigest(byte[] input)
          Returns the digest of the byte array.
static java.lang.String getException(java.lang.Throwable e)
          Returns the string description of a Throwable instance.
static int getHour(java.util.Date d)
          Returns the hour of the date.
static int getMinute(java.util.Date d)
          Returns the minute of the date.
static long getTime(java.lang.String f, java.util.Date d)
          Returns the time of the date.
static void intToByteArray(int val, byte[] buf, int start)
          Convert an integer value into 4 bytes and keep the bytes into an array by specifying the start position to be used for storing.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools

public Tools()
Method Detail

getDigest

public static java.lang.String getDigest(byte[] input)
Returns the digest of the byte array.

Parameters:
input - the byte array
Returns:
the digest of the input byte array

getTime

public static long getTime(java.lang.String f,
                           java.util.Date d)
Returns the time of the date.

Parameters:
f - the date format used for describing the time of the date
d - the date
Returns:
the time of the date

getHour

public static int getHour(java.util.Date d)
Returns the hour of the date.

Parameters:
d - the date
Returns:
the hour of the date

getMinute

public static int getMinute(java.util.Date d)
Returns the minute of the date.

Parameters:
d - the date
Returns:
the minute of the date

getAM

public static java.lang.String getAM(java.util.Date d)
Returns the AM/PM of the date.

Parameters:
d - the date
Returns:
the AM/PM of the date

getException

public static java.lang.String getException(java.lang.Throwable e)
Returns the string description of a Throwable instance.

Parameters:
e - the Throwable instance
Returns:
the string description of a Throwable instance

intToByteArray

public static void intToByteArray(int val,
                                  byte[] buf,
                                  int start)
Convert an integer value into 4 bytes and keep the bytes into an array by specifying the start position to be used for storing.

Parameters:
val - the integer value to be converted
buf - the byte array used for storing converted bytes
start - the position to store the converted bytes
See Also:
byteArrayToInt(byte[], int)

byteArrayToInt

public static int byteArrayToInt(byte[] buf,
                                 int start)
Convert a 4-bytes array to an integer value from the specified start position of the array.

Parameters:
buf - the byte array to be used for transformation
start - the position to start conversion
Returns:
an integer value converted from the array
See Also:
intToByteArray(int, byte[], int)