Class SimpleDBUtils
- java.lang.Object
-
- com.amazonaws.services.simpledb.util.SimpleDBUtils
-
public class SimpleDBUtils extends Object
Provides collection of static functions for conversion of various values into strings that may be compared lexicographically.
-
-
Constructor Summary
Constructors Constructor Description SimpleDBUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Date
decodeDate(String value)
Decodes date value from the string representation created using encodeDate(..) 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 a long value from the string representation that was created by using encodeRealNumberRange(..) function.static float
decodeZeroPaddingFloat(String value)
Decodes zero-padded positive float value from the string representationstatic int
decodeZeroPaddingInt(String value)
Decodes zero-padded positive integer value from the string representationstatic long
decodeZeroPaddingLong(String value)
Decodes a zero-padded positive long value from the string representationstatic String
encodeDate(Date date)
Encodes date value into string format that can be compared lexicographicallystatic 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, long offsetValue)
Encodes a positive or negative long value into a string by offsetting and zero-padding the 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 digitsstatic 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 the value up to the specified number of digits.static String
quoteName(String name)
Quotes and escapes an attribute name or domain name by wrapping it with backticks and escaping any backticks inside the name.static String
quoteValue(String value)
Quotes and escapes an attribute value by wrapping it with single quotes and escaping any single quotes inside the value.static String
quoteValues(Collection<String> values)
Quotes and escapes a list of values so that they can be used in a SimpleDB query.protected static String
replaceChar(String value, String termToFind, String replacementTerm)
-
-
-
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 encodedmaxNumDigits
- 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 the value up to the specified number of digits.- Parameters:
number
- positive long to be encodedmaxNumDigits
- 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 encodedmaxNumDigits
- 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
-
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 a 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
-
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 encodedmaxNumDigits
- maximum number of digits in the largest absolute value in the data setoffsetValue
- 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, long offsetValue)
Encodes a positive or negative long value into a string by offsetting and zero-padding the number up to the specified number of digits. Use this encoding method if the data set includes both positive and negative values.- Parameters:
number
- positive or negative long value to be encodedmaxNumDigits
- maximum number of digits in the largest absolute value in the data setoffsetValue
- 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 encodedmaxDigitsLeft
- maximum number of digits left of the decimal point in the largest absolute value in the data setmaxDigitsRight
- maximum number of digits right of the decimal point in the largest absolute value in the data set, i.e. precisionoffsetValue
- 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 valueoffsetValue
- offset value that was used in the original encoding- Returns:
- original integer value
-
decodeRealNumberRangeLong
public static long decodeRealNumberRangeLong(String value, long offsetValue)
Decodes a long value from the string representation that was created by using encodeRealNumberRange(..) function.- Parameters:
value
- string representation of the long valueoffsetValue
- 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 valuemaxDigitsRight
- 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
-
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
-
quoteValues
public static String quoteValues(Collection<String> values)
Quotes and escapes a list of values so that they can be used in a SimpleDB query.- Parameters:
values
- The collection of attribute values that will be quoted, escaped, and included in the returned string list.- Returns:
- A string representation of the list of specified values, with individual values properly quoted and escaped.
-
quoteValue
public static String quoteValue(String value)
Quotes and escapes an attribute value by wrapping it with single quotes and escaping any single quotes inside the value.- Parameters:
value
- The attribute value to quote and escape.- Returns:
- The properly quoted and escaped attribute value, ready to be used in a SimpleDB select query.
-
quoteName
public static String quoteName(String name)
Quotes and escapes an attribute name or domain name by wrapping it with backticks and escaping any backticks inside the name.- Parameters:
name
- The attribute name or domain name to quote and escape.- Returns:
- The properly quoted and escaped attribute name or domain name, ready to be used in a SimpleDB select query.
-
-