本文整理匯總了Java中java.text.Collator類的典型用法代碼示例。如果您正苦於以下問題:Java Collator類的具體用法?Java Collator怎麽用?Java Collator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Collator類屬於java.text包,在下文中一共展示了Collator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: keyToString
import java.text.Collator; //導入依賴的package包/類
/**
* Construct a key based on the key columns:
* Single key: Use the value as key
* Multiple keys: Serialize the key using a JSON map.
*/
private String keyToString(String[] columnNames, Object[] columnValues) {
if ( columnNames.length == 1 ) {
return columnValues[0].toString();
}
Collator collator = Collator.getInstance( Locale.ENGLISH );
collator.setStrength( Collator.SECONDARY );
Map<String, Object> idObject = new TreeMap<>( collator );
for ( int i = 0; i < columnNames.length; i++ ) {
idObject.put( columnNames[i], columnValues[i] );
}
return strategy.serialize( idObject );
}
示例2: getCallableTargetNames
import java.text.Collator; //導入依賴的package包/類
/**
* Finds the names of callable targets in an Ant script.
* @param script Ant script to inspect
* @return list of target names, sorted (by locale)
* @throws IOException if the script cannot be inspected
*/
public static List<String> getCallableTargetNames(FileObject script) throws IOException {
AntProjectCookie apc = antProjectCookieFor(script);
Set<TargetLister.Target> allTargets = TargetLister.getTargets(apc);
SortedSet<String> targetNames = new TreeSet<String>(Collator.getInstance());
for (TargetLister.Target target : allTargets) {
if (target.isOverridden()) {
// Cannot call it directly.
continue;
}
if (target.isInternal()) {
// Should not be called from outside.
continue;
}
targetNames.add(target.getName());
}
return new ArrayList<String>(targetNames);
}
示例3: testLocalizedNameComparator
import java.text.Collator; //導入依賴的package包/類
public void testLocalizedNameComparator() throws Exception {
NbModuleProject module = generateStandaloneModule("module");
ModuleList ml = module.getModuleList();
ModuleDependency[] deps = new ModuleDependency[] {
new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")),
new ModuleDependency(ml.getEntry("org.openide.loaders")),
new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")),
new ModuleDependency(ml.getEntry("org.openide.io")),
new ModuleDependency(ml.getEntry("org.jdesktop.layout")),
new ModuleDependency(ml.getEntry("org.openide.filesystems")),
new ModuleDependency(ml.getEntry("org.openide.execution")),
};
for (int i = 0; i < deps.length; i++) {
for (int j = 0; j < deps.length; j++) {
int locNameResult = Collator.getInstance().compare(
deps[i].getModuleEntry().getLocalizedName(),
deps[j].getModuleEntry().getLocalizedName());
int realResult = ModuleDependency.LOCALIZED_NAME_COMPARATOR.compare(deps[i], deps[j]);
assertTrue("ordering works: " + deps[i] + " <--> " + deps[j],
locNameResult > 0 ? realResult > 0 :
(locNameResult == 0 ? realResult == 0 : realResult < 0));
// (int) Math.signum(locNameResult), (int) Math.signum(realResult));
}
}
}
示例4: projectDisplayNameComparator
import java.text.Collator; //導入依賴的package包/類
/**
* Order projects by display name.
*/
public static Comparator<Project> projectDisplayNameComparator() {
return new Comparator<Project>() {
private final Collator LOC_COLLATOR = Collator.getInstance();
public int compare(Project o1, Project o2) {
ProjectInformation i1 = ProjectUtils.getInformation(o1);
ProjectInformation i2 = ProjectUtils.getInformation(o2);
int result = LOC_COLLATOR.compare(i1.getDisplayName(), i2.getDisplayName());
if (result != 0) {
return result;
} else {
result = i1.getName().compareTo(i2.getName());
if (result != 0) {
return result;
} else {
return System.identityHashCode(o1) - System.identityHashCode(o2);
}
}
}
};
}
示例5: addNotify
import java.text.Collator; //導入依賴的package包/類
@Override
protected void addNotify() {
super.addNotify();
List<FileObject> l = new ArrayList<FileObject>();
for (FileObject f : fo.getChildren()) {
if (f.isFolder() && group.contains(f) && VisibilityQuery.getDefault().isVisible(f)) {
l.add(f);
}
}
Collections.sort(l, new Comparator<FileObject>() { // #116545
Collator COLL = Collator.getInstance();
@Override
public int compare(FileObject f1, FileObject f2) {
return COLL.compare(f1.getNameExt(), f2.getNameExt());
}
});
setKeys(l);
}
示例6: refreshJavaPlatforms
import java.text.Collator; //導入依賴的package包/類
private void refreshJavaPlatforms() {
SortedSet<JavaPlatform> platforms = new TreeSet<JavaPlatform>(new Comparator<JavaPlatform>() {
Collator COLL = Collator.getInstance();
public int compare(JavaPlatform p1, JavaPlatform p2) {
int res = COLL.compare(p1.getDisplayName(), p2.getDisplayName());
if (res != 0) {
return res;
} else {
return System.identityHashCode(p1) - System.identityHashCode(p2);
}
}
});
platforms.addAll(Arrays.asList(JavaPlatformManager.getDefault().getInstalledPlatforms()));
javaPlatform.setModel(new DefaultComboBoxModel(platforms.toArray(new JavaPlatform[platforms.size()])));
JavaPlatform pf = jdkConf.getSelectedPlatform();
if (pf == null) {
pf = JavaPlatformManager.getDefault().getDefaultPlatform();
}
javaPlatform.setSelectedItem(pf);
}
示例7: Collation
import java.text.Collator; //導入依賴的package包/類
private Collation(String name, String language, String country,
int strength, int decomposition, boolean ucc) {
locale = new Locale(language, country);
collator = Collator.getInstance(locale);
if (strength >= 0) {
collator.setStrength(strength);
}
if (decomposition >= 0) {
collator.setDecomposition(decomposition);
}
strength = collator.getStrength();
isUnicodeSimple = false;
this.name = HsqlNameManager.newInfoSchemaObjectName(name, true,
SchemaObject.COLLATION);
charset = Charset.SQL_TEXT;
isUpperCaseCompare = ucc;
isFinal = true;
}
示例8: compareTo
import java.text.Collator; //導入依賴的package包/類
/** Compares two elements.
* @param obj the reference object with which to compare.
* @return the value 0 if the argument object is equal to
* this object; -1 if this object is less than the object
* argument; and 1 if this object is greater than the object argument.
* Null objects are "smaller".
*/
public int compareTo(Object obj) {
// null is not allowed
if (obj == null)
throw new ClassCastException();
if (obj == this)
return 0;
String thisName = getName().getFullName();
String otherName = ((DBElement) obj).getName().getFullName();
if (thisName == null)
return (otherName == null) ? 0 : -1;
if (otherName == null)
return 1;
int ret = Collator.getInstance().compare(thisName, otherName);
// if both names are equal, both objects might have different types.
// If so order both objects by their type names
// (necessary to be consistent with equals)
if ((ret == 0) && (getClass() != obj.getClass()))
ret = getClass().getName().compareTo(obj.getClass().getName());
return ret;
}
示例9: sortLinesAsc
import java.text.Collator; //導入依賴的package包/類
/**
* Sorts lines in given text ascending.
*
* @param text
* Input text.
* @return Text with sorted lines.
*/
private String sortLinesAsc(String text) {
String[] lines = text.split("\\n");
Arrays.sort(lines, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
String language = LocalizationProvider.getInstance()
.getLanguage();
Locale locale = new Locale(language);
Collator collator = Collator.getInstance(locale);
int r = collator.compare(o1, o2);
return r;
}
});
StringBuilder builder = new StringBuilder(text.length());
for (int i = 0; i < lines.length; ++i) {
builder.append(lines[i]);
builder.append("\n");
}
return builder.toString();
}
示例10: TestDemoTest2
import java.text.Collator; //導入依賴的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");
}
}
示例11: AuthComparator
import java.text.Collator; //導入依賴的package包/類
public AuthComparator(String fieldName, SortOrder sortOrder)
{
if (DISPLAY_NAME.equals(fieldName))
{
sortByDisplayName = true;
sortByShortName = false;
}
else if (SHORT_NAME.equals(fieldName))
{
sortByDisplayName = false;
sortByShortName = true;
}
else if (AUTHORITY_NAME.equals(fieldName))
{
sortByDisplayName = false;
sortByShortName = false;
}
else
{
throw new IllegalArgumentException("Authorities should be sorted by "+DISPLAY_NAME+", "+AUTHORITY_NAME+" or "+SHORT_NAME+". Asked use "+fieldName);
}
this.sortOrder = sortOrder;
this.collator = Collator.getInstance(); // note: currently default locale
}
示例12: getInstance
import java.text.Collator; //導入依賴的package包/類
public static HanziToPinyin getInstance() {
synchronized (HanziToPinyin.class) {
if (sInstance != null) {
return sInstance;
}
// Check if zh_CN collation data is available
final Locale locale[] = Collator.getAvailableLocales();
for (int i = 0; i < locale.length; i++) {
if (locale[i].equals(Locale.CHINA)) {
// Do self validation just once.
if (DEBUG) {
android.util.Log.d(TAG, "Self validation. Result: " +
doSelfValidation());
}
sInstance = new HanziToPinyin(true);
return sInstance;
}
}
android.util.Log.w(TAG,
"There is no Chinese collator, HanziToPinyin is disabled");
sInstance = new HanziToPinyin(false);
return sInstance;
}
}
示例13: sortLinesDesc
import java.text.Collator; //導入依賴的package包/類
/**
* Sorts lines in given text descending.
*
* @param text
* Input text.
* @return Text with sorted lines.
*/
private String sortLinesDesc(String text) {
String[] lines = text.split("\\n");
Arrays.sort(lines, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
String language = LocalizationProvider.getInstance()
.getLanguage();
Locale locale = new Locale(language);
Collator collator = Collator.getInstance(locale);
int r = collator.compare(o2, o1);
return r;
}
});
StringBuilder builder = new StringBuilder(text.length());
for (int i = 0; i < lines.length; ++i) {
builder.append(lines[i]);
builder.append("\n");
}
return builder.toString();
}
示例14: sortCategories
import java.text.Collator; //導入依賴的package包/類
public static void sortCategories()
{
List<NotebookCategory> ours = NotebookCategory.REGISTRY.getValues().stream()
.filter((c) -> c.getRegistryName().getResourceDomain().equals(ArcaneMagic.MODID))
.collect(Collectors.toList());
List<ResourceLocation> theirNames = new ArrayList<>();
NotebookCategory.REGISTRY.getValues().stream()
.filter((c) -> !c.getRegistryName().getResourceDomain().equals(ArcaneMagic.MODID))
.sorted(Collator.getInstance()).forEach((c) -> theirNames.add(c.getRegistryName()));
theirNames.sort(Collator.getInstance());
ImmutableList.Builder<NotebookCategory> bob = ImmutableList.builder();
bob.addAll(ours);
for (ResourceLocation loc : theirNames)
bob.add(NotebookCategory.REGISTRY.getValue(loc));
ArcaneMagicAPI.setCategoryList(bob.build());
freeze();
}
示例15: 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;
}