本文整理汇总了Java中java.text.Collator.compare方法的典型用法代码示例。如果您正苦于以下问题:Java Collator.compare方法的具体用法?Java Collator.compare怎么用?Java Collator.compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.Collator
的用法示例。
在下文中一共展示了Collator.compare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareGraphObjects
import java.text.Collator; //导入方法依赖的package包/类
private static int compareGraphObjects(GraphObject a, GraphObject b, Collection<String> sortFields,
Collator collator) {
for (String sortField : sortFields) {
String sa = (String) a.getProperty(sortField);
String sb = (String) b.getProperty(sortField);
if (sa != null && sb != null) {
int result = collator.compare(sa, sb);
if (result != 0) {
return result;
}
} else if (!(sa == null && sb == null)) {
return (sa == null) ? -1 : 1;
}
}
return 0;
}
示例2: compareTo
import java.text.Collator; //导入方法依赖的package包/类
@Override
public int compareTo( DocumentGroupImpl o ) {
Collator collator = Collator.getInstance();
int res = collator.compare( displayName, o.displayName );
if( 0 == res )
res = collator.compare( name, o.name );
return res;
}
示例3: compare
import java.text.Collator; //导入方法依赖的package包/类
@Override
public int compare(AppInfo lhs, AppInfo rhs)
{
// 为了适应汉字的比较
Collator c = Collator.getInstance(Locale.CHINA);
return (asc == 1) ? c.compare(lhs.appName, rhs.appName)
: c.compare(rhs.appName, lhs.appName);
}
示例4: localeCompare
import java.text.Collator; //导入方法依赖的package包/类
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
示例5: compareTo
import java.text.Collator; //导入方法依赖的package包/类
@Override
public int compareTo(ApplicationInfoEx other) {
// Locale respecting sorter
Collator collator = Collator.getInstance(Locale.getDefault());
return collator.compare(TextUtils.join(", ", getApplicationName()),
TextUtils.join(", ", other.getApplicationName()));
}
示例6: compareTo
import java.text.Collator; //导入方法依赖的package包/类
@Override
public int compareTo(FileNavigator o) {
Collator collator = Collator.getInstance();
return collator.compare(this.modelName, o.modelName);
}
示例7: compareTo
import java.text.Collator; //导入方法依赖的package包/类
@Override
public int compareTo(Item o) {
Collator collator = Collator.getInstance();
return collator.compare(this.modelName, o.modelName);
}
示例8: buildSenseCollectionAsSynstes
import java.text.Collator; //导入方法依赖的package包/类
public Collection<Sense> buildSenseCollectionAsSynstes(List<Sense> sense, String sortFrase) {
Collection<Sense> synsets = new ArrayList<Sense>();
if (!sense.isEmpty()) {
for (Sense senseItem : sense) {
// if (senseItem.getSenseToSynset().getSenseIndex() == 0) {
// synsets.add(senseItem);
// }
// if (senseItem.getLexicon().getId() == 2
// && senseItem.getSenseToSynset().getSenseIndex() == 1) {
// synsets.add(senseItem);
// }
}
}
Collator collator = Collator.getInstance(Locale.US);
String rules = ((RuleBasedCollator) collator).getRules();
try {
RuleBasedCollator correctedCollator
= new RuleBasedCollator(rules.replaceAll("<'\u005f'", "<' '<'\u005f'"));
collator = correctedCollator;
} catch (ParseException e) {
e.printStackTrace();
}
collator.setStrength(Collator.PRIMARY);
collator.setDecomposition(Collator.NO_DECOMPOSITION);
final Collator myFavouriteCollator = collator;
Comparator<Sense> senseComparator = new Comparator<Sense>() {
@Override
public int compare(Sense a, Sense b) {
String aa = a.getWord().getWord().toLowerCase();
String bb = b.getWord().getWord().toLowerCase();
int c = myFavouriteCollator.compare(aa, bb);
if (c == 0) {
aa = a.getPartOfSpeech().getId().toString();
bb = b.getPartOfSpeech().getId().toString();
c = myFavouriteCollator.compare(aa, bb);
}
if (c == 0) {
if (a.getVariant() == b.getVariant()) {
c = 0;
}
if (a.getVariant() > b.getVariant()) {
c = 1;
}
if (a.getVariant() < b.getVariant()) {
c = -1;
}
}
if (c == 0) {
aa = a.getLexicon().getId().toString();
bb = b.getLexicon().getId().toString();
c = myFavouriteCollator.compare(aa, bb);
}
return c;
}
};
//Items starting with frase
List<Sense> withFraseOnBegining = new ArrayList<>();
//Other items
List<Sense> other = new ArrayList<>();
for (Sense se : synsets) {
if (se.getWord().toString().startsWith(sortFrase.toLowerCase())) {
withFraseOnBegining.add(se);
} else {
other.add(se);
}
}
Collections.sort(withFraseOnBegining, senseComparator);
Collections.sort(other, senseComparator);
withFraseOnBegining.addAll(other);
return withFraseOnBegining;
}
示例9: compare
import java.text.Collator; //导入方法依赖的package包/类
/**
* Compare two strings with Locale.ENGLISH
* This method is preferred over String.compareTo() method.
* @param str1 String 1
* @param str2 String 2
* @return negative integer if str1 lexicographically precedes str2
* positive integer if str1 lexicographically follows str2
* 0 if both strings are equal
* @throws IllegalArgumentException throws exception if both or either of the strings is null
*/
public static int compare(String str1, String str2) {
if (str1 == null || str2 == null) {
throw new IllegalArgumentException("Arguments cannot be null");
}
Collator collator = Collator.getInstance(LOCALE_ENGLISH);
return collator.compare(str1, str2);
}
示例10: compare
import java.text.Collator; //导入方法依赖的package包/类
/**
* Compare two strings with Locale.ENGLISH
* This method is preferred over String.compareTo() method.
* @param str1 String 1
* @param str2 String 2
* @return negative integer if str1 lexicographically precedes str2
* positive integer if str1 lexicographically follows str2
* 0 if both strings are equal
* @throws IllegalArgumentException throws exception if both or either of the strings is null
*/
public static int compare(String str1, String str2) {
if( str1 == null || str2 == null) {
throw new IllegalArgumentException("Arguments cannot be null");
}
Collator collator = Collator.getInstance(LOCALE_ENGLISH);
return collator.compare(str1, str2);
}