本文整理匯總了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);
}