com.xerox.amazonws.sdb
Class DataUtils

java.lang.Object
  extended by com.xerox.amazonws.sdb.DataUtils

public class DataUtils
extends Object

Provides collection of static functions for conversion of various values into strings that may be compared lexicographically.


Constructor Summary
DataUtils()
           
 
Method Summary
static Date decodeDate(String value)
          Decodes date value from the string representation created using encodeDate(..) function.
static double decodeDouble(String s)
           
static double decodeRealNumberRangeDouble(String value, int maxDigitsRight, long offsetValue)
          Decodes double value from the string representation that was created by using encodeRealNumberRange(..) function.
static float decodeRealNumberRangeFloat(String value, int maxDigitsRight, int offsetValue)
          Decodes float value from the string representation that was created by using encodeRealNumberRange(..) function.
static int decodeRealNumberRangeInt(String value, int offsetValue)
          Decodes integer value from the string representation that was created by using encodeRealNumberRange(..) function.
static long decodeRealNumberRangeLong(String value, long offsetValue)
          Decodes long value from the string representation that was created by using encodeRealNumberRange(..) function.
static double decodeZeroPaddingDouble(String value)
          Decodes zero-padded positive double value from the string representation
static float decodeZeroPaddingFloat(String value)
          Decodes zero-padded positive float value from the string representation
static int decodeZeroPaddingInt(String value)
          Decodes zero-padded positive integer value from the string representation
static long decodeZeroPaddingLong(String value)
          Decodes zero-padded positive long value from the string representation
static String encodeDate(Date date)
          Encodes date value into string format that can be compared lexicographically
static String encodeDouble(double d)
           
static String encodeRealNumberRange(double number, int maxDigitsLeft, int maxDigitsRight, long offsetValue)
          Encodes real double value into a string by offsetting and zero-padding number up to the specified number of digits.
static String encodeRealNumberRange(float number, int maxDigitsLeft, int maxDigitsRight, int offsetValue)
          Encodes real float value into a string by offsetting and zero-padding number up to the specified number of digits.
static String encodeRealNumberRange(int number, int maxNumDigits, int offsetValue)
          Encodes real integer value into a string by offsetting and zero-padding number up to the specified number of digits.
static String encodeRealNumberRange(long number, int maxNumDigits, int offsetValue)
          Encodes real long value into a string by offsetting and zero-padding number up to the specified number of digits.
static String encodeZeroPadding(double number, int maxNumDigits)
          Encodes positive double value into a string by zero-padding number up to the specified number of digits
static String encodeZeroPadding(float number, int maxNumDigits)
          Encodes positive float value into a string by zero-padding number up to the specified number of digits
static String encodeZeroPadding(int number, int maxNumDigits)
          Encodes positive integer value into a string by zero-padding number up to the specified number of digits.
static String encodeZeroPadding(long number, int maxNumDigits)
          Encodes positive long value into a string by zero-padding number up to the specified number of digits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataUtils

public DataUtils()
Method Detail

encodeZeroPadding

public static String encodeZeroPadding(int number,
                                       int maxNumDigits)
Encodes positive integer value into a string by zero-padding number up to the specified number of digits.

Parameters:
number - positive integer to be encoded
maxNumDigits - maximum number of digits in the largest value in the data set
Returns:
string representation of the zero-padded integer

encodeZeroPadding

public static String encodeZeroPadding(long number,
                                       int maxNumDigits)
Encodes positive long value into a string by zero-padding number up to the specified number of digits.

Parameters:
number - positive long to be encoded
maxNumDigits - maximum number of digits in the largest value in the data set
Returns:
string representation of the zero-padded long

encodeZeroPadding

public static String encodeZeroPadding(float number,
                                       int maxNumDigits)
Encodes positive float value into a string by zero-padding number up to the specified number of digits

Parameters:
number - positive float value to be encoded
maxNumDigits - maximum number of digits preceding the decimal point in the largest value in the data set
Returns:
string representation of the zero-padded float value

encodeZeroPadding

public static String encodeZeroPadding(double number,
                                       int maxNumDigits)
Encodes positive double value into a string by zero-padding number up to the specified number of digits

Parameters:
number - positive double value to be encoded
maxNumDigits - maximum number of digits preceding the decimal point in the largest value in the data set
Returns:
string representation of the zero-padded double value

decodeZeroPaddingInt

public static int decodeZeroPaddingInt(String value)
Decodes zero-padded positive integer value from the string representation

Parameters:
value - zero-padded string representation of the integer
Returns:
original integer value

decodeZeroPaddingLong

public static long decodeZeroPaddingLong(String value)
Decodes zero-padded positive long value from the string representation

Parameters:
value - zero-padded string representation of the long
Returns:
original long value

decodeZeroPaddingFloat

public static float decodeZeroPaddingFloat(String value)
Decodes zero-padded positive float value from the string representation

Parameters:
value - zero-padded string representation of the float value
Returns:
original float value

decodeZeroPaddingDouble

public static double decodeZeroPaddingDouble(String value)
Decodes zero-padded positive double value from the string representation

Parameters:
value - zero-padded string representation of the double value
Returns:
original double value

encodeRealNumberRange

public static String encodeRealNumberRange(int number,
                                           int maxNumDigits,
                                           int offsetValue)
Encodes real integer value into a string by offsetting and zero-padding number up to the specified number of digits. Use this encoding method if the data range set includes both positive and negative values.

Parameters:
number - integer to be encoded
maxNumDigits - maximum number of digits in the largest absolute value in the data set
offsetValue - offset value, has to be greater than absolute value of any negative number in the data set.
Returns:
string representation of the integer

encodeRealNumberRange

public static String encodeRealNumberRange(long number,
                                           int maxNumDigits,
                                           int offsetValue)
Encodes real long value into a string by offsetting and zero-padding number up to the specified number of digits. Use this encoding method if the data range set includes both positive and negative values.

Parameters:
number - long to be encoded
maxNumDigits - maximum number of digits in the largest absolute value in the data set
offsetValue - offset value, has to be greater than absolute value of any negative number in the data set.
Returns:
string representation of the long

encodeRealNumberRange

public static String encodeRealNumberRange(float number,
                                           int maxDigitsLeft,
                                           int maxDigitsRight,
                                           int offsetValue)
Encodes real float value into a string by offsetting and zero-padding number up to the specified number of digits. Use this encoding method if the data range set includes both positive and negative values.

Parameters:
number - float to be encoded
maxDigitsLeft - maximum number of digits left of the decimal point in the largest absolute value in the data set
maxDigitsRight - maximum number of digits right of the decimal point in the largest absolute value in the data set, i.e. precision
offsetValue - offset value, has to be greater than absolute value of any negative number in the data set.
Returns:
string representation of the integer

encodeRealNumberRange

public static String encodeRealNumberRange(double number,
                                           int maxDigitsLeft,
                                           int maxDigitsRight,
                                           long offsetValue)
Encodes real double value into a string by offsetting and zero-padding number up to the specified number of digits. Use this encoding method if the data range set includes both positive and negative values.

Parameters:
number - double to be encoded
maxDigitsLeft - maximum number of digits left of the decimal point in the largest absolute value in the data set
maxDigitsRight - maximum number of digits right of the decimal point in the largest absolute value in the data set, i.e. precision
offsetValue - offset value, has to be greater than absolute value of any negative number in the data set.
Returns:
string representation of the integer

decodeRealNumberRangeInt

public static int decodeRealNumberRangeInt(String value,
                                           int offsetValue)
Decodes integer value from the string representation that was created by using encodeRealNumberRange(..) function.

Parameters:
value - string representation of the integer value
offsetValue - offset value that was used in the original encoding
Returns:
original integer value

decodeRealNumberRangeLong

public static long decodeRealNumberRangeLong(String value,
                                             long offsetValue)
Decodes long value from the string representation that was created by using encodeRealNumberRange(..) function.

Parameters:
value - string representation of the long value
offsetValue - offset value that was used in the original encoding
Returns:
original long value

decodeRealNumberRangeFloat

public static float decodeRealNumberRangeFloat(String value,
                                               int maxDigitsRight,
                                               int offsetValue)
Decodes float value from the string representation that was created by using encodeRealNumberRange(..) function.

Parameters:
value - string representation of the integer value
maxDigitsRight - maximum number of digits left of the decimal point in the largest absolute value in the data set (must be the same as the one used for encoding).
offsetValue - offset value that was used in the original encoding
Returns:
original float value

decodeRealNumberRangeDouble

public static double decodeRealNumberRangeDouble(String value,
                                                 int maxDigitsRight,
                                                 long offsetValue)
Decodes double value from the string representation that was created by using encodeRealNumberRange(..) function.

Parameters:
value - string representation of the integer value
maxDigitsRight - maximum number of digits left of the decimal point in the largest absolute value in the data set (must be the same as the one used for encoding).
offsetValue - offset value that was used in the original encoding
Returns:
original double value

encodeDate

public static String encodeDate(Date date)
Encodes date value into string format that can be compared lexicographically

Parameters:
date - date value to be encoded
Returns:
string representation of the date value

decodeDate

public static Date decodeDate(String value)
                       throws ParseException
Decodes date value from the string representation created using encodeDate(..) function.

Parameters:
value - string representation of the date value
Returns:
original date value
Throws:
ParseException

encodeDouble

public static String encodeDouble(double d)

decodeDouble

public static double decodeDouble(String s)