Package oracle.i18n.text
Class OraCollator
- java.lang.Object
-
- oracle.i18n.text.OraCollator
-
- All Implemented Interfaces:
Cloneable,Comparator
public class OraCollator extends Object implements Cloneable, Comparator
TheOraCollatorclass performs locale-sensitive string comparisons, including linguistic collation and binary sorting.- Since:
- Oracle 10.1.0.2
-
-
Field Summary
Fields Modifier and Type Field Description static intCANONICAL_COMPOSITIONTheOraCollatorclass composition level value.static intEQUALThe result of the comparison that theOraCollatorobject returns if the two strings are equal.static intGREATERThe result of the comparison that theOraCollatorobject returns if the first string is greater than the second string.static intLESSThe result of the comparison that theOraCollatorobject returns if the first string is less than the second string.static intNO_COMPOSITIONTheOraCollatorclass composition level value.static intPRIMARYTheOraCollatorclass strength value.static intSECONDARYTheOraCollatorclass strength value.static intTERTIARYTheOraCollatorclass strength value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedOraCollator()The constructor is here only for completeness.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Objectclone()Makes an independent duplicate of theOraCollatorobject.intcompare(Object source, Object target)Compares two objects using the current collation rule.intcompare(String source, String target)Compares two strings using the current collation rule.StringconvertToBaseLetter(String source)StringconvertToCaseFold(String source)booleanequals(Object obj)Returnstrueif thisOraCollatorobject is equal to another.StringgetCharSet()Gets thecharSetname of thisOraCollatorobject.OraCollationKeygetCollationKey(String source)Gets theOraCollationKeyobject for a given source string.intgetComposition()Gets the composition level used for comparison.static OraCollatorgetInstance()Deprecated.As of Oracle Database 10g Release 2 (10.2), replaced bygetInstance(Locale)static OraCollatorgetInstance(String sortRule)Constructs anOraCollatorinstance from the specifiedsortRulevalue.static OraCollatorgetInstance(String sortRule, String charSet)Constructs anOraCollatorinstance from the specifiedsortRulevalue.static OraCollatorgetInstance(Locale locale)Constructs an Oracle collation object from the Java locale.static OraCollatorgetInstance(Locale locale, String sortRule, String charSet)Constructs anOraCollatorinstance from the specifiedsortRulevalue and locale.static OraCollatorgetInstance(OraLocaleInfo oraLocale)Constructs an Oracle collation object from anOraLocaleInfoobject.StringgetName()Gets the sorting rule name of thisOraCollatorobject.intgetStrength()Gets the strength used in comparisons.inthashCode()Creates a hash code for thisOraCollatorobject based on sort rule, strength, and decomposition level.int[]matchFirst(String source, String pattern)This method searches pattern string from the beginning of source string.int[]matchLast(String source, String pattern)This method searches pattern string from the end of source string.voidsetComposition(int compositionMode)Sets the composition level used for comparison.voidsetStrength(int newStrength)Sets the strength used in comparisons.-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
PRIMARY
public static final int PRIMARY
TheOraCollatorclass strength value. When set, only primary differences are considered significant during comparison. The assignment of strengths to language features is locale dependant. For example, different base letters ("a" vs. "b") are considered a primary difference. For monolingual and binary sort, a primary setting means accent insensitive.- See Also:
setStrength(int),getStrength(), Constant Field Values
-
SECONDARY
public static final int SECONDARY
TheOraCollatorclass strength value. When set, only secondary and higher-order differences are considered significant during comparison. The assignment of strengths to language features is locale dependant. For example, different accented forms of the same base letter ("a" vs. "â") are considered a secondary difference. For monolingual and binary sort, a secondary setting means case insensitive .- See Also:
setStrength(int),getStrength(), Constant Field Values
-
TERTIARY
public static final int TERTIARY
TheOraCollatorclass strength value. When set, only tertiary and higher-order differences are considered significant during comparison. The assignment of strengths to language features is locale dependant. For example, case differences ("a" vs. "A") are considered a tertiary difference.- See Also:
setStrength(int),getStrength(), Constant Field Values
-
NO_COMPOSITION
public static final int NO_COMPOSITION
TheOraCollatorclass composition level value. When the composition level set toNO_COMPOSITION, canonical equivalence is not considered.- See Also:
setComposition(int),getComposition(), Constant Field Values
-
CANONICAL_COMPOSITION
public static final int CANONICAL_COMPOSITION
TheOraCollatorclass composition level value. When the composition level set toCANONICAL_COMPOSITION, canonical equivalence is considered as the same.- See Also:
setComposition(int),getComposition(), Constant Field Values
-
EQUAL
public static final int EQUAL
The result of the comparison that theOraCollatorobject returns if the two strings are equal.- See Also:
- Constant Field Values
-
LESS
public static final int LESS
The result of the comparison that theOraCollatorobject returns if the first string is less than the second string.- See Also:
- Constant Field Values
-
GREATER
public static final int GREATER
The result of the comparison that theOraCollatorobject returns if the first string is greater than the second string.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static OraCollator getInstance()
Deprecated.As of Oracle Database 10g Release 2 (10.2), replaced bygetInstance(Locale)Constructs an Oracle collation object from the default Java locale. Converts the default Java locale to theOraLocaleInfoobject using the default sorting rule.- Returns:
OraCollatorinstance
-
getInstance
public static OraCollator getInstance(Locale locale)
Constructs an Oracle collation object from the Java locale. It converts the Java locale to Oracle locale and uses the result to get theOraCollatorobject.- Parameters:
locale- JavaLocaleobject- Returns:
OraCollatorinstance
-
getInstance
public static OraCollator getInstance(OraLocaleInfo oraLocale)
Constructs an Oracle collation object from anOraLocaleInfoobject. Retrieves the default collator associated with theOraLocaleInfoobject.- Parameters:
oraLocale-OraLocaleInfoobject- Returns:
OraCollatorinstance
-
getInstance
public static OraCollator getInstance(String sortRule)
Constructs anOraCollatorinstance from the specifiedsortRulevalue. ThesortRulevalues are the same as NLSRTL's NLS_SORT names; for example,xgerman,GENERIC_M,unicode_binary,binary, etc.aiorcican be attached to sort rules to specify the comparison level.- Parameters:
sortRule- Oracle sort rule name- Returns:
OraCollatorinstance- Throws:
IllegalArgumentException- if an invalid sort rule name is specified
-
getInstance
public static OraCollator getInstance(String sortRule, String charSet)
Constructs anOraCollatorinstance from the specifiedsortRulevalue. This method will take both Oracle sorting rule and "binary" assortRulevalue. If using Oracle sorting rule, thecharSetvalues will be ignored. If using binary sorting rule, thecharSetvalue could be specified by a valid character set on the database server.aiorcican be attached to "binary" for specifying the comparison level.- Parameters:
sortRule- Oracle sort rule namecharSet- Oracle database character set, could benull. The default is UTF16- Returns:
OraCollatorinstance- Throws:
IllegalArgumentException- if an invalid sort rule name is specified
-
getInstance
public static OraCollator getInstance(Locale locale, String sortRule, String charSet)
Constructs anOraCollatorinstance from the specifiedsortRulevalue and locale. This method will take both Oracle sorting rule and "binary" assortRulevalue. If using Oracle sorting rule, thecharSetvalues will be ignored. If using binary sorting rule, thecharSetvalue could be specified by a valid character set on the database server.aiorcican be attached to "binary" for specifying the comparison level. It also records the locale information in the instance.- Parameters:
locale- JavaLocaleobjectsortRule- Oracle sort rule namecharSet- Oracle database character set, could benull. The default is UTF16- Returns:
OraCollatorinstance
-
getName
public String getName()
Gets the sorting rule name of thisOraCollatorobject.- Returns:
- sorting rule name
-
getCharSet
public String getCharSet()
Gets thecharSetname of thisOraCollatorobject.- Returns:
- database character set
-
setStrength
public void setStrength(int newStrength)
Sets the strength used in comparisons. Strength could have the values ofPRIMARY,SECONDARY, orTERTIARY.- Parameters:
newStrength- the new strength to be set, options arePRIMARY,SECONDARYorTERTIARY- Throws:
IllegalArgumentException- if an invalid strength is specified- See Also:
PRIMARY,SECONDARY,TERTIARY
-
getStrength
public int getStrength()
Gets the strength used in comparisons. Strength could have the values ofPRIMARY,SECONDARY, orTERTIARY.
-
setComposition
public void setComposition(int compositionMode)
Sets the composition level used for comparison. Composition level could be eitherCANONICAL_COMPOSITIONorNO_COMPOSITION.- Parameters:
compositionMode- the composition level to be set, options are eitherCANONICAL_COMPOSITIONorNO_COMPOSITION- Throws:
IllegalArgumentException- if an invalid composition mode is specified- See Also:
NO_COMPOSITION,CANONICAL_COMPOSITION
-
getComposition
public int getComposition()
Gets the composition level used for comparison. Composition level could be eitherCANONICAL_COMPOSITIONorNO_COMPOSITION.- Returns:
- the current composition level
- See Also:
NO_COMPOSITION,CANONICAL_COMPOSITION
-
clone
public Object clone()
Makes an independent duplicate of theOraCollatorobject.
-
hashCode
public int hashCode()
Creates a hash code for thisOraCollatorobject based on sort rule, strength, and decomposition level.
-
equals
public boolean equals(Object obj)
Returnstrueif thisOraCollatorobject is equal to another.- Specified by:
equalsin interfaceComparator- Overrides:
equalsin classObject- Parameters:
obj- a target object with which to be compared- Returns:
trueif equal orfalseif not
-
compare
public int compare(Object source, Object target)
Compares two objects using the current collation rule. The comparison result depends on the sorting rule and the setting of comparison level.This implementation merely returns
compare((String)o1, (String)o2).- Specified by:
comparein interfaceComparator- Parameters:
source- firstObjectto be comparedtarget- secondObjectto be compared- Returns:
OraCollator.GREATER,OraCollator.EQUAL, orOraCollator.LESS
-
compare
public int compare(String source, String target)
Compares two strings using the current collation rule. The comparison result depends on the sorting rule and the setting of comparison level.- Parameters:
source- firstStringto be comparedtarget- secondStringto be compared- Returns:
OraCollator.GREATER,OraCollator.EQUAL, orOraCollator.LESS
-
getCollationKey
public OraCollationKey getCollationKey(String source)
Gets theOraCollationKeyobject for a given source string.- Parameters:
source- source string to get Oracle collation key- Returns:
OraCollationKeyobject
-
matchFirst
public int[] matchFirst(String source, String pattern)
This method searches pattern string from the beginning of source string.- Parameters:
source- source string as the target.pattern- as pattern string.- Returns:
- If match found, return the first index(position) of source string to int[0] and the index of the last character matched plus one to int[1]. The returning index range is from 0 to n for the source string length of n. Return -1 to int[0] and int[1] if no match.
-
matchLast
public int[] matchLast(String source, String pattern)
This method searches pattern string from the end of source string.- Parameters:
source- source string as the target.pattern- as pattern string.- Returns:
- If match found, return the index(position) of source string to int[0] and the index of the last character matched plus one to int[1]. The returning index range is from 0 to n for the source string length of n. Return -1 to int[0] and int[1] if no match.
-
-