本文整理匯總了Java中java.text.RuleBasedCollator類的典型用法代碼示例。如果您正苦於以下問題:Java RuleBasedCollator類的具體用法?Java RuleBasedCollator怎麽用?Java RuleBasedCollator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RuleBasedCollator類屬於java.text包,在下文中一共展示了RuleBasedCollator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateCollatorRules
import java.text.RuleBasedCollator; //導入依賴的package包/類
private static synchronized Collator updateCollatorRules(Collator collator)
{
if (collator instanceof RuleBasedCollator)
{
try
{
// get current collator rules
String collatorRules = ((RuleBasedCollator)collator).getRules();
// we shoudn't ignore space character in character comparison - put it before u0021 character
String newCollatorRules = collatorRules.replaceAll("<'\u0021'", "<'\u0020'<'\u0021'");
// create new collator with overridden rules
return new RuleBasedCollator(newCollatorRules);
}
catch(ParseException e)
{
return collator;
}
}
return collator;
}
示例2: getCollator
import java.text.RuleBasedCollator; //導入依賴的package包/類
private Collator getCollator() {
RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();
String rule = base.getRules();
try {
return new RuleBasedCollator(rule
+ "&B < \ud800\udc01 < \ud800\udc00"
+ ", \ud800\udc02, \ud800\udc03"
+ "; \ud800\udc04, \ud800\udc05"
+ "< \ud800\udc06 < \ud800\udc07"
+ "&FE < \ud800\udc08"
+ "&PE, \ud800\udc09"
+ "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"
+ "&\ud800\udc0a < x, X"
+ "&A < \ud800\udc04\ud800\udc05");
} catch (Exception e) {
errln("Failed to create new RulebasedCollator object");
return null;
}
}
示例3: TestDemoTest2
import java.text.RuleBasedCollator; //導入依賴的package包/類
public void TestDemoTest2() {
final Collator myCollation = Collator.getInstance(Locale.US);
final String defRules = ((RuleBasedCollator)myCollation).getRules();
String newRules = defRules + "& C < ch , cH, Ch, CH";
try {
RuleBasedCollator tblColl = new RuleBasedCollator(newRules);
for (int j = 0; j < TOTALTESTSET; j++) {
for (int n = j+1; n < TOTALTESTSET; n++) {
doTest(tblColl, testCases[Test2Results[j]],
testCases[Test2Results[n]], -1);
}
}
} catch (Exception foo) {
errln("Exception: " + foo.getMessage() +
"\nDemo Test 2 Table Collation object creation failed.\n");
}
}
示例4: getCharacterCollator
import java.text.RuleBasedCollator; //導入依賴的package包/類
/** @see DataValueFactory#getCharacterCollator(int) */
public RuleBasedCollator getCharacterCollator(int collationType)
throws StandardException {
if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
return (RuleBasedCollator)null;
else if (collatorForCharacterTypes == null) {
//This is the first access to Collator because otherwise
//it will not be null. Verify that JVM has support for
//the Collator for the database locale.
// Calculate the collator strength. COLLATION_TYPE_TERRITORY_BASED use strength -1, i e unspecified.
int strength = collationType - StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
collatorForCharacterTypes = verifyCollatorSupport(strength);
return collatorForCharacterTypes;
} else
return collatorForCharacterTypes;
}
示例5: verifyCollatorSupport
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
* Verify that JVM has support for the Collator for the datbase's locale.
*
* @param strength Collator strength or -1 for locale default.
* @return Collator for database's locale
* @throws StandardException if JVM does not have support for Collator
*/
private RuleBasedCollator verifyCollatorSupport(int strength)
throws StandardException {
Locale[] availLocales = Collator.getAvailableLocales();
//Verify that Collator can be instantiated for the given locale.
boolean localeFound = false;
for (int i=0; i<availLocales.length;i++)
{
if (availLocales[i].equals(databaseLocale)) {
localeFound = true;
break;
}
}
if (!localeFound)
throw StandardException.newException(
SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE,
(databaseLocale != null ? databaseLocale.toString() : "null"));
RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);
if (strength != -1)
collator.setStrength(strength);
return collator;
}
示例6: getValue
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
* We do not anticipate this method on collation sensitive DVD to be
* ever called in Derby 10.3 In future, when Derby will start supporting
* SQL standard COLLATE clause, this method might get called on the
* collation sensitive DVDs.
*
* @see StringDataValue#getValue(RuleBasedCollator)
*/
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
if (collatorForComparison != null)
{
//non-null collatorForComparison means use this collator sensitive
//implementation of SQLChar
setCollator(collatorForComparison);
return this;
} else {
//null collatorForComparison means use UCS_BASIC for collation.
//For that, we need to use the base class SQLChar
SQLChar s = new SQLChar();
s.copyState(this);
return s;
}
}
示例7: getValue
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
* We do not anticipate this method on collation sensitive DVD to be
* ever called in Derby 10.3 In future, when Derby will start supporting
* SQL standard COLLATE clause, this method might get called on the
* collation sensitive DVDs.
*
* @see StringDataValue#getValue(RuleBasedCollator)
*/
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
if (collatorForComparison != null)
{
//non-null collatorForComparison means use this collator sensitive
//implementation of SQLVarchar
setCollator(collatorForComparison);
return this;
} else {
//null collatorForComparison means use UCS_BASIC for collation.
//For that, we need to use the base class SQLVarchar
SQLVarchar s = new SQLVarchar();
s.copyState(this);
return s;
}
}
示例8: getValue
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
* We do not anticipate this method on collation sensitive DVD to be
* ever called in Derby 10.3 In future, when Derby will start supporting
* SQL standard COLLATE clause, this method might get called on the
* collation sensitive DVDs.
*
* @see StringDataValue#getValue(RuleBasedCollator)
*/
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
if (collatorForComparison != null)
{
//non-null collatorForComparison means use this collator sensitive
//implementation of SQLClob
setCollator(collatorForComparison);
return this;
} else {
//null collatorForComparison means use UCS_BASIC for collation.
//For that, we need to use the base class SQLClob
SQLClob s = new SQLClob();
s.copyState(this);
return s;
}
}
示例9: getValue
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
* We do not anticipate this method on collation sensitive DVD to be
* ever called in Derby 10.3 In future, when Derby will start supporting
* SQL standard COLLATE clause, this method might get called on the
* collation sensitive DVDs.
*
* @see StringDataValue#getValue(RuleBasedCollator)
*/
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
if (collatorForComparison != null)
{
//non-null collatorForComparison means use this collator sensitive
//implementation of SQLLongvarchar
setCollator(collatorForComparison);
return this;
} else {
//null collatorForComparison means use UCS_BASIC for collation.
//For that, we need to use the base class SQLLongvarchar
SQLLongvarchar s = new SQLLongvarchar();
s.copyState(this);
return s;
}
}
示例10: getNull
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
Get a Null for this type.
*/
public DataValueDescriptor getNull() throws StandardException {
DataValueDescriptor returnDVD = typeId.getNull();
//If we are dealing with default collation, then we have got the
//right DVD already. Just return it.
if (typeDescriptor.getCollationType() == StringDataValue.COLLATION_TYPE_UCS_BASIC
|| returnDVD instanceof JSON) {
return returnDVD;
}
//If we are dealing with territory based collation and returnDVD is
//of type StringDataValue, then we need to return a StringDataValue
//with territory based collation.
if (returnDVD instanceof StringDataValue) {
try {
RuleBasedCollator rbs = ConnectionUtil.getCurrentLCC().getDataValueFactory().
getCharacterCollator(typeDescriptor.getCollationType());
return ((StringDataValue)returnDVD).getValue(rbs);
}
catch( java.sql.SQLException sqle)
{
throw StandardException.plainWrapException( sqle);
}
}
else
return returnDVD;
}
示例11: testPrevious
import java.text.RuleBasedCollator; //導入依賴的package包/類
public void testPrevious() {
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
String text = "abc";
CollationElementIterator iterator = coll
.getCollationElementIterator(text);
int[] orders = new int[text.length()];
int order = iterator.next();
int i = 0;
while (order != CollationElementIterator.NULLORDER) {
orders[i++] = order;
order = iterator.next();
}
int offset = iterator.getOffset();
assertEquals(text.length(), offset);
order = iterator.previous();
while (order != CollationElementIterator.NULLORDER) {
assertEquals(orders[--i], order);
order = iterator.previous();
}
assertEquals(0, iterator.getOffset());
}
示例12: testEqualsObject
import java.text.RuleBasedCollator; //導入依賴的package包/類
public void testEqualsObject() throws ParseException {
String rule = "< a < b < c < d < e";
RuleBasedCollator coll = new RuleBasedCollator(rule);
assertEquals(Collator.TERTIARY, coll.getStrength());
// This is a harmony test, but it assumes that RuleBasedCollators default to
// NO_DECOMPOSITION, which isn't true on Android.
// assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
RuleBasedCollator other = new RuleBasedCollator(rule);
assertTrue(coll.equals(other));
coll.setStrength(Collator.PRIMARY);
assertFalse(coll.equals(other));
coll.setStrength(Collator.TERTIARY);
coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
other.setDecomposition(Collator.NO_DECOMPOSITION); // See comment above.
assertFalse(coll.equals(other));
}
示例13: testTertiaryOrder
import java.text.RuleBasedCollator; //導入依賴的package包/類
public void testTertiaryOrder() {
RuleBasedCollator rbColl = (RuleBasedCollator) Collator
.getInstance(new Locale("fr", "FR"));
String text = "abAB";
CollationElementIterator iterator = rbColl
.getCollationElementIterator(text);
int order = iterator.next();
int tOrder1 = CollationElementIterator.tertiaryOrder(order);
order = iterator.next();
int tOrder2 = CollationElementIterator.tertiaryOrder(order);
assertEquals(tOrder1, tOrder2);
order = iterator.next();
tOrder1 = CollationElementIterator.tertiaryOrder(order);
order = iterator.next();
tOrder2 = CollationElementIterator.tertiaryOrder(order);
assertEquals(tOrder1, tOrder2);
}
示例14: testEqualsObject
import java.text.RuleBasedCollator; //導入依賴的package包/類
public void testEqualsObject() throws ParseException {
String rule = "< a < b < c < d < e";
RuleBasedCollator coll = new RuleBasedCollator(rule);
assertEquals(Collator.TERTIARY, coll.getStrength());
assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
RuleBasedCollator other = new RuleBasedCollator(rule);
assertTrue(coll.equals(other));
coll.setStrength(Collator.PRIMARY);
assertFalse(coll.equals(other));
coll.setStrength(Collator.TERTIARY);
coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
assertFalse(coll.equals(other));
}
示例15: verifyCollatorSupport
import java.text.RuleBasedCollator; //導入依賴的package包/類
/**
* Verify that JVM has support for the Collator for the datbase's locale.
*
* @param strength Collator strength or -1 for locale default.
* @return Collator for database's locale
* @throws StandardException if JVM does not have support for Collator
*/
private RuleBasedCollator verifyCollatorSupport(int strength)
throws StandardException {
Locale[] availLocales = Collator.getAvailableLocales();
//Verify that Collator can be instantiated for the given locale.
boolean localeFound = false;
for (Locale availLocale : availLocales) {
if (availLocale.equals(databaseLocale)) {
localeFound = true;
break;
}
}
if (!localeFound)
throw StandardException.newException(
SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE,
databaseLocale.toString());
RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);
if (strength != -1)
collator.setStrength(strength);
return collator;
}