本文整理汇总了Java中com.ibm.icu.text.RuleBasedCollator.setNumericCollation方法的典型用法代码示例。如果您正苦于以下问题:Java RuleBasedCollator.setNumericCollation方法的具体用法?Java RuleBasedCollator.setNumericCollation怎么用?Java RuleBasedCollator.setNumericCollation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.RuleBasedCollator
的用法示例。
在下文中一共展示了RuleBasedCollator.setNumericCollation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: catch
import com.ibm.icu.text.RuleBasedCollator; //导入方法依赖的package包/类
public void Init(String locale, boolean numeric_ordering) {
try {
this.collator = Collator.getInstance(Locale.forLanguageTag(locale));
if (numeric_ordering) {
RuleBasedCollator rbc = (RuleBasedCollator)collator;
rbc.setNumericCollation(true);
}
} catch (Exception e) {throw Err_.new_wo_type("collator init failed", "err", Err_.Message_lang(e));}
}
示例2: inform
import com.ibm.icu.text.RuleBasedCollator; //导入方法依赖的package包/类
public void inform(ResourceLoader loader) throws IOException {
if (localeID != null) {
// create from a system collator, based on Locale.
collator = createFromLocale(localeID);
} else {
// create from a custom ruleset
collator = createFromRules(custom, loader);
}
// set the strength flag, otherwise it will be the default.
if (strength != null) {
if (strength.equalsIgnoreCase("primary"))
collator.setStrength(Collator.PRIMARY);
else if (strength.equalsIgnoreCase("secondary"))
collator.setStrength(Collator.SECONDARY);
else if (strength.equalsIgnoreCase("tertiary"))
collator.setStrength(Collator.TERTIARY);
else if (strength.equalsIgnoreCase("quaternary"))
collator.setStrength(Collator.QUATERNARY);
else if (strength.equalsIgnoreCase("identical"))
collator.setStrength(Collator.IDENTICAL);
else
throw new IllegalArgumentException("Invalid strength: " + strength);
}
// set the decomposition flag, otherwise it will be the default.
if (decomposition != null) {
if (decomposition.equalsIgnoreCase("no"))
collator.setDecomposition(Collator.NO_DECOMPOSITION);
else if (decomposition.equalsIgnoreCase("canonical"))
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
else
throw new IllegalArgumentException("Invalid decomposition: " + decomposition);
}
// expert options: concrete subclasses are always a RuleBasedCollator
RuleBasedCollator rbc = (RuleBasedCollator) collator;
if (alternate != null) {
if (alternate.equalsIgnoreCase("shifted")) {
rbc.setAlternateHandlingShifted(true);
} else if (alternate.equalsIgnoreCase("non-ignorable")) {
rbc.setAlternateHandlingShifted(false);
} else {
throw new IllegalArgumentException("Invalid alternate: " + alternate);
}
}
if (caseLevel != null) {
rbc.setCaseLevel(Boolean.parseBoolean(caseLevel));
}
if (caseFirst != null) {
if (caseFirst.equalsIgnoreCase("lower")) {
rbc.setLowerCaseFirst(true);
} else if (caseFirst.equalsIgnoreCase("upper")) {
rbc.setUpperCaseFirst(true);
} else {
throw new IllegalArgumentException("Invalid caseFirst: " + caseFirst);
}
}
if (numeric != null) {
rbc.setNumericCollation(Boolean.parseBoolean(numeric));
}
if (variableTop != null) {
rbc.setVariableTop(variableTop);
}
}
示例3: makeCheck
import com.ibm.icu.text.RuleBasedCollator; //导入方法依赖的package包/类
@Override
protected void makeCheck(Placeholder target, ImmutableList<String> tokenizedInput, ULocale locale,
String message) {
if (tokenizedInput.size() < 2) {
// Test passed. Nothing to sort.
return;
}
int strength = Collator.SECONDARY;
if (!target.isLenient()) {
if (!target.isStrict()) {
strength = Collator.TERTIARY;
} else {
strength = Collator.IDENTICAL;
}
}
// Init collators.
Collator collator = Collator.getInstance(locale);
ImmutableList.Builder<Collator> collators = ImmutableList.builder();
collators.add(collator);
try {
Collator collator2 = (RuleBasedCollator) collator.clone();
collator2.setStrength(strength);
collators.add(collator2);
RuleBasedCollator collator3 = (RuleBasedCollator) collator.clone();
collator3.setStrength(strength);
collator3.setAlternateHandlingShifted(true);
collators.add(collator3);
RuleBasedCollator collator4 = (RuleBasedCollator) collator.clone();
collator4.setStrength(strength);
collator4.setNumericCollation(true);
collators.add(collator4);
RuleBasedCollator collator5 = (RuleBasedCollator) collator.clone();
collator5.setStrength(strength);
collator5.setAlternateHandlingShifted(true);
collator5.setNumericCollation(true);
collators.add(collator5);
} catch (CloneNotSupportedException e) {
// Do nothing.
}
makeCheck(collators.build(), tokenizedInput, locale, message);
}
示例4: createCollator
import com.ibm.icu.text.RuleBasedCollator; //导入方法依赖的package包/类
private Collator createCollator() {
ULocale locale = ULocale.forLanguageTag(this.locale);
if ("search".equals(usage)) {
// "search" usage cannot be set through unicode extensions (u-co-search), handle here:
locale = locale.setKeywordValue("collation", "search");
}
RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(locale);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
collator.setNumericCollation(numeric);
switch (caseFirst) {
case "upper":
collator.setUpperCaseFirst(true);
break;
case "lower":
collator.setLowerCaseFirst(true);
break;
case "false":
if (collator.isLowerCaseFirst()) {
collator.setLowerCaseFirst(false);
}
if (collator.isUpperCaseFirst()) {
collator.setUpperCaseFirst(false);
}
break;
default:
throw new AssertionError();
}
switch (sensitivity) {
case "base":
collator.setStrength(Collator.PRIMARY);
break;
case "accent":
collator.setStrength(Collator.SECONDARY);
break;
case "case":
collator.setStrength(Collator.PRIMARY);
collator.setCaseLevel(true);
break;
case "variant":
collator.setStrength(Collator.TERTIARY);
break;
default:
throw new AssertionError();
}
collator.setAlternateHandlingShifted(ignorePunctuation);
return collator;
}