Class TStringType
- java.lang.Object
-
- com.mckoi.database.TType
-
- com.mckoi.database.TStringType
-
- All Implemented Interfaces:
java.io.Serializable
public final class TStringType extends TType
An implementation of TType for a String.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.Collator
collator
The Collator object for this type, created when we first compare objects.private int
decomposition
The decomposition mode of the collator for this string type (as defined in java.text.Collator).private java.util.Locale
locale
The locale of the string.private int
max_size
The maximum allowed size for the string.(package private) static long
serialVersionUID
private int
strength
The strength of the collator for this string (as defined in java.text.Collator).-
Fields inherited from class com.mckoi.database.TType
ARRAY_TYPE, BINARY_TYPE, BOOLEAN_TYPE, DATE_TYPE, NULL_TYPE, NUMERIC_TYPE, QUERY_PLAN_TYPE, STRING_TYPE
-
-
Constructor Summary
Constructors Constructor Description TStringType(int sql_type, int max_size, java.lang.String locale_str)
Constructor without strength and decomposition that sets to default levels.TStringType(int sql_type, int max_size, java.lang.String locale_str, int strength, int decomposition)
Constructs a type with the given sql_type value, the maximum size, and the locale of the string.TStringType(int sql_type, int max_size, java.util.Locale locale, int strength, int decomposition)
Constructs a type with the given sql_type value, the maximum size, and the locale of the string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
calculateApproximateMemoryUse(java.lang.Object ob)
Calculates the approximate memory usage of an object of this type in bytes.boolean
comparableTypes(TType type)
For strings, the locale must be the same for the types to be comparable.int
compareObs(java.lang.Object ob1, java.lang.Object ob2)
Compares two objects that are logically comparable under this type.private java.text.Collator
getCollator()
Returns the java.text.Collator object for this string type.int
getDecomposition()
Returns the decomposition of this string type as defined in java.text.Collator.java.util.Locale
getLocale()
Returns the locale of the string.java.lang.String
getLocaleString()
Returns the locale information as a formatted string.int
getMaximumSize()
Returns the maximum size of the string (-1 is don't care).int
getStrength()
Returns the strength of this string type as defined in java.text.Collator.java.lang.Class
javaClass()
Returns the Java Class that is used to represent this type of object.private int
lexicographicalOrder(StringAccessor str1, StringAccessor str2)
An implementation of a lexicographical compareTo operation on a StringAccessor object.-
Methods inherited from class com.mckoi.database.TType
asEncodedString, asEncodedString, asSQLString, binaryType, booleanType, castObjectToTType, dateType, decodeString, decodeTypes, fromClass, getSQLType, getWidestType, javaObjectType, numericType, stringType
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
max_size
private int max_size
The maximum allowed size for the string.
-
locale
private java.util.Locale locale
The locale of the string.
-
strength
private int strength
The strength of the collator for this string (as defined in java.text.Collator).
-
decomposition
private int decomposition
The decomposition mode of the collator for this string type (as defined in java.text.Collator).
-
collator
private transient java.text.Collator collator
The Collator object for this type, created when we first compare objects.
-
-
Constructor Detail
-
TStringType
public TStringType(int sql_type, int max_size, java.util.Locale locale, int strength, int decomposition)
Constructs a type with the given sql_type value, the maximum size, and the locale of the string. Note that the 'sql_type' MUST be a string SQL type.Note that a string type may be constructed with a NULL locale which means strings are compared lexicographically.
-
TStringType
public TStringType(int sql_type, int max_size, java.lang.String locale_str, int strength, int decomposition)
Constructs a type with the given sql_type value, the maximum size, and the locale of the string. Note that the 'sql_type' MUST be a string SQL type.Note that a string type may be constructed with a NULL locale which means strings are compared lexicographically. The string locale is formated as [2 char language][2 char country][rest is variant]. For example, US english would be 'enUS', French would be 'fr' and Germany would be 'deDE'.
-
TStringType
public TStringType(int sql_type, int max_size, java.lang.String locale_str)
Constructor without strength and decomposition that sets to default levels.
-
-
Method Detail
-
getMaximumSize
public int getMaximumSize()
Returns the maximum size of the string (-1 is don't care).
-
getStrength
public int getStrength()
Returns the strength of this string type as defined in java.text.Collator.
-
getDecomposition
public int getDecomposition()
Returns the decomposition of this string type as defined in java.text.Collator.
-
getLocale
public java.util.Locale getLocale()
Returns the locale of the string.
-
getLocaleString
public java.lang.String getLocaleString()
Returns the locale information as a formatted string.Note that a string type may be constructed with a NULL locale which means strings are compared lexicographically. The string locale is formated as [2 char language][2 char country][rest is variant]. For example, US english would be 'enUS', French would be 'fr' and Germany would be 'deDE'.
-
lexicographicalOrder
private int lexicographicalOrder(StringAccessor str1, StringAccessor str2)
An implementation of a lexicographical compareTo operation on a StringAccessor object. This uses the Reader object to compare the strings over a stream if the size is such that it is more efficient to do so.
-
getCollator
private java.text.Collator getCollator()
Returns the java.text.Collator object for this string type. This collator is used to compare strings of this locale.This method is synchronized because a side effect of this method is to store the collator object instance in a local variable.
-
comparableTypes
public boolean comparableTypes(TType type)
For strings, the locale must be the same for the types to be comparable. If the locale is not the same then they are not comparable. Note that strings with a locale of null can be compared with any other locale. So this will only return false if both types have different (but defined) locales.- Specified by:
comparableTypes
in classTType
-
compareObs
public int compareObs(java.lang.Object ob1, java.lang.Object ob2)
Description copied from class:TType
Compares two objects that are logically comparable under this type. Returns 0 if the values are equal, >1 if ob1 is greater than ob2, and <1 if ob1 is less than ob2. It is illegal to pass NULL values for ob1 or ob2 into this method.- Specified by:
compareObs
in classTType
-
calculateApproximateMemoryUse
public int calculateApproximateMemoryUse(java.lang.Object ob)
Description copied from class:TType
Calculates the approximate memory usage of an object of this type in bytes.- Specified by:
calculateApproximateMemoryUse
in classTType
-
-