当前位置: 首页>>代码示例>>Java>>正文


Java Collator类代码示例

本文整理汇总了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 );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:22,代码来源:AbstractRedisDialect.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:AntScriptUtils.java

示例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));
            }
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ModuleDependencyTest.java

示例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);
                }
            }
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Util.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:BrowseFolders.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ClasspathPanel.java

示例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;
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:23,代码来源:Collation.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:DBElement.java

示例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();
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:31,代码来源:SortLinesAscendingAction.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:G7Test.java

示例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
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:GetAuthoritiesCannedQuery.java

示例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;
    }
}
 
开发者ID:weileng11,项目名称:KUtils-master,代码行数:26,代码来源:HanziToPinyin.java

示例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();

}
 
开发者ID:fgulan,项目名称:java-course,代码行数:32,代码来源:SortLinesDescendingAction.java

示例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();
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:18,代码来源:CategoryRegistry.java

示例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;
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:18,代码来源:GraphObjectAdapter.java


注:本文中的java.text.Collator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。