Java Code Examples for java.text.Collator

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project com.idega.content, under directory /src/java/com/idega/content/data/.

Source file: ContentCategoryComparator.java

  22 
vote

public int compare(ContentCategory category1,ContentCategory category2){
  String name1=category1.getName(locale.toString());
  String name2=category2.getName(locale.toString());
  Collator collator=Collator.getInstance(locale);
  return collator.compare(name1,name2);
}
 

Example 2

From project mkgmap, under directory /test/uk/me/parabola/imgfmt/app/srt/.

Source file: SortTest.java

  22 
vote

@Test public void testCollatorPrimary(){
  Collator collator=sort.getCollator();
  collator.setStrength(Collator.PRIMARY);
  assertEquals(0,collator.compare("aa","aa"));
  assertEquals(0,collator.compare("aa","?a"));
  assertEquals(0,collator.compare("Aa","aA"));
  assertEquals(1,collator.compare("ab","?a"));
  assertEquals(1,collator.compare("aaa","aa"));
  assertEquals(-1,collator.compare("aa","aaa"));
}
 

Example 3

From project RA_Launcher, under directory /src/com/android/ra/launcher/settings/.

Source file: Preferences.java

  22 
vote

private Comparator<IconItemInfo> getAppNameComparator(){
  final IconCache myIconCache=mLauncher.getIconCache();
  final Collator sCollator=Collator.getInstance();
  return new Comparator<IconItemInfo>(){
    @Override public final int compare(    IconItemInfo a,    IconItemInfo b){
      return sCollator.compare(a.getTitle(myIconCache),b.getTitle(myIconCache));
    }
  }
;
}
 

Example 4

From project Sphero-Desktop-API, under directory /bluecove-bluez/org/freedesktop/dbus/test/.

Source file: test.java

  22 
vote

public void handle(String r){
  System.out.println("Handling callback: " + r);
  Collator col=Collator.getInstance();
  col.setDecomposition(Collator.FULL_DECOMPOSITION);
  col.setStrength(Collator.PRIMARY);
  if (0 != col.compare("This Is A UTF-8 Name: ? !!",r))   test.fail("call with callback, wrong return value");
  if (test.done4)   test.fail("Already ran callback handler");
  test.done4=true;
}
 

Example 5

From project tinfoil-sms, under directory /branches/compression-dev/Compression/src/.

Source file: CompressionActivity.java

  22 
vote

/** 
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
  String messages[]=readLines("sms_messages.txt");
  Collator strictCollator=Collator.getInstance(Locale.US);
  strictCollator.setDecomposition(Collator.FULL_DECOMPOSITION);
  strictCollator.setStrength(Collator.IDENTICAL);
  BWTTest(messages,strictCollator);
}
 

Example 6

From project upm-swing, under directory /src/com/_17od/upm/gui/.

Source file: SortedListModel.java

  22 
vote

public SortedListModel(){
  model=new TreeSet(new Comparator(){
    public int compare(    Object o1,    Object o2){
      String str1=o1.toString();
      String str2=o2.toString();
      Collator collator=Collator.getInstance();
      int result=collator.compare(str1,str2);
      return result;
    }
  }
);
}
 

Example 7

From project Android-Terminal-Emulator, under directory /src/jackpal/androidterm/.

Source file: Term.java

  21 
vote

private String makePathFromBundle(Bundle extras){
  if (extras == null || extras.size() == 0) {
    return "";
  }
  String[] keys=new String[extras.size()];
  keys=extras.keySet().toArray(keys);
  Collator collator=Collator.getInstance(Locale.US);
  Arrays.sort(keys,collator);
  StringBuilder path=new StringBuilder();
  for (  String key : keys) {
    String dir=extras.getString(key);
    if (dir != null && !dir.equals("")) {
      path.append(dir);
      path.append(":");
    }
  }
  return path.substring(0,path.length() - 1);
}
 

Example 8

From project apps-for-android, under directory /RingsExtended/src/com/example/android/rings_extended/.

Source file: MusicPicker.java

  21 
vote

/** 
 * Common method for performing a query of the music database, called for both top-level queries and filtering.
 * @param sync If true, this query should be done synchronously and theresulting cursor returned.  If false, it will be done asynchronously and null returned.
 * @param filterstring If non-null, this is a filter to apply to the query.
 */
Cursor doQuery(boolean sync,String filterstring){
  mQueryHandler.cancelOperation(MY_QUERY_TOKEN);
  StringBuilder where=new StringBuilder();
  where.append(MediaStore.Audio.Media.TITLE + " != ''");
  String[] keywords=null;
  if (filterstring != null) {
    String[] searchWords=filterstring.split(" ");
    keywords=new String[searchWords.length];
    Collator col=Collator.getInstance();
    col.setStrength(Collator.PRIMARY);
    for (int i=0; i < searchWords.length; i++) {
      keywords[i]='%' + MediaStore.Audio.keyFor(searchWords[i]) + '%';
    }
    for (int i=0; i < searchWords.length; i++) {
      where.append(" AND ");
      where.append(MediaStore.Audio.Media.ARTIST_KEY + "||");
      where.append(MediaStore.Audio.Media.ALBUM_KEY + "||");
      where.append(MediaStore.Audio.Media.TITLE_KEY + " LIKE ?");
    }
  }
  if (sync) {
    try {
      return getContentResolver().query(mBaseUri,CURSOR_COLS,where.toString(),keywords,mSortOrder);
    }
 catch (    UnsupportedOperationException ex) {
    }
  }
 else {
    mAdapter.setLoading(true);
    setProgressBarIndeterminateVisibility(true);
    mQueryHandler.startQuery(MY_QUERY_TOKEN,null,mBaseUri,CURSOR_COLS,where.toString(),keywords,mSortOrder);
  }
  return null;
}
 

Example 9

From project jspwiki, under directory /src/org/apache/wiki/plugin/.

Source file: AbstractReferralPlugin.java

  21 
vote

/** 
 * Helper method to initialize the comparator for this page.
 */
private void initSorter(WikiContext context,Map params){
  String order=(String)params.get(PARAM_SORTORDER);
  if (order == null || order.length() == 0) {
    m_sorter=context.getEngine().getPageSorter();
  }
 else   if (order.equalsIgnoreCase(PARAM_SORTORDER_JAVA)) {
    m_sorter=new PageSorter(JavaNaturalComparator.DEFAULT_JAVA_COMPARATOR);
  }
 else   if (order.equalsIgnoreCase(PARAM_SORTORDER_LOCALE)) {
    m_sorter=new PageSorter(LocaleComparator.DEFAULT_LOCALE_COMPARATOR);
  }
 else   if (order.equalsIgnoreCase(PARAM_SORTORDER_HUMAN)) {
    m_sorter=new PageSorter(HumanComparator.DEFAULT_HUMAN_COMPARATOR);
  }
 else   try {
    Collator collator=new RuleBasedCollator(order);
    collator.setStrength(Collator.PRIMARY);
    m_sorter=new PageSorter(new CollatorComparator(collator));
  }
 catch (  ParseException pe) {
    log.info("Failed to parse requested collator - using default ordering",pe);
    m_sorter=context.getEngine().getPageSorter();
  }
}
 

Example 10

From project montysolr, under directory /contrib/antlrqueryparser/src/test/org/apache/lucene/queryParser/aqp/.

Source file: TestAqpSLGStandardTest.java

  21 
vote

public void testFarsiRangeCollating() throws Exception {
  Directory ramDir=newDirectory();
  IndexWriter iw=new IndexWriter(ramDir,newIndexWriterConfig(TEST_VERSION_CURRENT,new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
  Document doc=new Document();
  doc.add(newField("content","\u0633\u0627\u0628",Field.Store.YES,Field.Index.NOT_ANALYZED));
  iw.addDocument(doc);
  iw.close();
  IndexSearcher is=new IndexSearcher(ramDir,true);
  AqpQueryParser qp=getParser();
  qp.setAnalyzer(new WhitespaceAnalyzer(TEST_VERSION_CURRENT));
  Collator c=Collator.getInstance(new Locale("ar"));
  qp.setRangeCollator(c);
  qp.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
  ScoreDoc[] result=is.search(qp.parse("[ \u062F TO \u0698 ]","content"),null,1000).scoreDocs;
  assertEquals("The index Term should not be included.",0,result.length);
  result=is.search(qp.parse("[ \u0633 TO \u0638 ]","content"),null,1000).scoreDocs;
  assertEquals("The index Term should be included.",1,result.length);
  qp.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
  result=is.search(qp.parse("[ \u062F TO \u0698 ]","content"),null,1000).scoreDocs;
  assertEquals("The index Term should not be included.",0,result.length);
  result=is.search(qp.parse("[ \u0633 TO \u0638 ]","content"),null,1000).scoreDocs;
  assertEquals("The index Term should be included.",1,result.length);
  is.close();
  ramDir.close();
}
 

Example 11

From project mp3tunes-android, under directory /src/com/mp3tunes/android/activity/.

Source file: AlbumBrowser.java

  21 
vote

private Cursor getArtistCursor(AsyncQueryHandler async,String filter){
  StringBuilder where=new StringBuilder();
  where.append(MediaStore.Audio.Albums.ALBUM + " != ''");
  String[] keywords=null;
  if (filter != null) {
    String[] searchWords=filter.split(" ");
    keywords=new String[searchWords.length];
    Collator col=Collator.getInstance();
    col.setStrength(Collator.PRIMARY);
    for (int i=0; i < searchWords.length; i++) {
      keywords[i]='%' + MediaStore.Audio.keyFor(searchWords[i]) + '%';
    }
    for (int i=0; i < searchWords.length; i++) {
      where.append(" AND ");
      where.append(MediaStore.Audio.Media.ARTIST_KEY + "||");
      where.append(MediaStore.Audio.Media.ALBUM_KEY + " LIKE ?");
    }
  }
  String whereclause=where.toString();
  String[] cols=new String[]{MediaStore.Audio.Albums._ID,MediaStore.Audio.Albums.ALBUM,MediaStore.Audio.Albums.ALBUM_KEY,MediaStore.Audio.Albums.ARTIST,MediaStore.Audio.Albums.NUMBER_OF_SONGS,MediaStore.Audio.Albums.ALBUM_ART};
  Cursor ret=null;
  if (mArtistId != null) {
    if (async != null) {
      async.startQuery(0,null,MediaStore.Audio.Artists.Albums.getContentUri("external",Long.valueOf(mArtistId)),cols,whereclause,keywords,MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
    }
 else {
    }
  }
 else {
    if (async != null) {
      async.startQuery(0,null,MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,cols,whereclause,keywords,MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
    }
 else {
    }
  }
  return ret;
}
 

Example 12

From project platform_packages_apps_music, under directory /src/com/android/music/.

Source file: PlaylistBrowserActivity.java

  21 
vote

private Cursor getPlaylistCursor(AsyncQueryHandler async,String filterstring){
  StringBuilder where=new StringBuilder();
  where.append(MediaStore.Audio.Playlists.NAME + " != ''");
  String[] keywords=null;
  if (filterstring != null) {
    String[] searchWords=filterstring.split(" ");
    keywords=new String[searchWords.length];
    Collator col=Collator.getInstance();
    col.setStrength(Collator.PRIMARY);
    for (int i=0; i < searchWords.length; i++) {
      keywords[i]='%' + searchWords[i] + '%';
    }
    for (int i=0; i < searchWords.length; i++) {
      where.append(" AND ");
      where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?");
    }
  }
  String whereclause=where.toString();
  if (async != null) {
    async.startQuery(0,null,MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,mCols,whereclause,keywords,MediaStore.Audio.Playlists.NAME);
    return null;
  }
  Cursor c=null;
  c=MusicUtils.query(this,MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,mCols,whereclause,keywords,MediaStore.Audio.Playlists.NAME);
  return mergedCursor(c);
}
 

Example 13

From project Solbase-Solr, under directory /src/java/org/apache/solr/handler/component/.

Source file: ShardDoc.java

  21 
vote

Comparator comparatorStringLocale(final String fieldName,Locale locale){
  final Collator collator=Collator.getInstance(locale);
  return new ShardComparator(fieldName){
    public final int compare(    final Object o1,    final Object o2){
      ShardDoc sd1=(ShardDoc)o1;
      ShardDoc sd2=(ShardDoc)o2;
      Comparable v1=(Comparable)sortVal(sd1);
      Comparable v2=(Comparable)sortVal(sd2);
      if (v1 == v2)       return 0;
      if (v1 == null)       return 1;
      if (v2 == null)       return -1;
      return -collator.compare(v1,v2);
    }
  }
;
}
 

Example 14

From project android-database-sqlcipher, under directory /src/net/sqlcipher/.

Source file: DatabaseUtils.java

  19 
vote

private static byte[] getCollationKeyInBytes(String name){
  if (mColl == null) {
    mColl=Collator.getInstance();
    mColl.setStrength(Collator.PRIMARY);
  }
  return mColl.getCollationKey(name).toByteArray();
}
 

Example 15

From project cowgraph, under directory /ZBeansBase/ZBeansSimple/src/zbeans/simple/views/.

Source file: SimpleOutlineView.java

  19 
vote

/** 
 * Initialize with some default customizations. See class comment for documentation of special customization settings/behaviour of  {@link SimpleOutlineView}. This constructor is private, since the  {@link SimpleOutlineView} provides factorymethods for convenience to setup often used configurations of a {@link SimpleOutlineView}.
 */
private SimpleOutlineView(){
  super();
  addTreeExpansionListener(new LazyLoadChildNodesOnTreeExpansion());
  getColumn(0).setNestedComparator(new Comparator<Node>(){
    private Collator collator=Collator.getInstance();
    @Override public int compare(    final Node n1,    final Node n2){
      if ((n1 instanceof Comparable) && (n1.getClass().isAssignableFrom(n2.getClass()))) {
        @SuppressWarnings("unchecked") Comparable<Node> cn1=(Comparable<Node>)n1;
        return cn1.compareTo(n2);
      }
 else       if ((n2 instanceof Comparable) && (n2.getClass().isAssignableFrom(n1.getClass()))) {
        @SuppressWarnings("unchecked") Comparable<Node> cn2=(Comparable<Node>)n2;
        return -cn2.compareTo(n1);
      }
 else {
        return collator.compare(n1.getDisplayName(),n2.getDisplayName());
      }
    }
  }
);
}
 

Example 16

From project creamed_glacier_app_settings, under directory /src/com/android/settings/.

Source file: AppWidgetPickActivity.java

  19 
vote

/** 
 * Build and return list of items to be shown in dialog. This will mix both installed  {@link AppWidgetProviderInfo} and those provided through{@link AppWidgetManager#EXTRA_CUSTOM_INFO}, sorting them alphabetically.
 */
@Override protected List<PickAdapter.Item> getItems(){
  List<PickAdapter.Item> items=new ArrayList<PickAdapter.Item>();
  putInstalledAppWidgets(items);
  putCustomAppWidgets(items);
  Collections.sort(items,new Comparator<PickAdapter.Item>(){
    Collator mCollator=Collator.getInstance();
    public int compare(    PickAdapter.Item lhs,    PickAdapter.Item rhs){
      return mCollator.compare(lhs.label,rhs.label);
    }
  }
);
  return items;
}
 

Example 17

From project eclim, under directory /org.eclim.jdt/java/org/eclim/plugin/ant/command/run/.

Source file: TargetsCommand.java

  19 
vote

/** 
 * {@inheritDoc}
 */
public Object execute(CommandLine commandLine) throws Exception {
  ArrayList<String> results=new ArrayList<String>();
  String project=commandLine.getValue(Options.PROJECT_OPTION);
  String file=commandLine.getValue(Options.FILE_OPTION);
  AntModel model=(AntModel)AntUtils.getAntModel(project,file);
  AntProjectNode projectNode=model.getProjectNode(true);
  Project antProject=projectNode.getProject();
  @SuppressWarnings("unchecked") Map<String,Object> targets=antProject.getTargets();
  for (  String target : targets.keySet()) {
    if (target.trim().length() > 0) {
      results.add(target);
    }
  }
  Collections.sort(results,Collator.getInstance());
  return results;
}
 

Example 18

From project eclipse.platform.runtime, under directory /bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/search/.

Source file: FindUnusedSearchResultPage.java

  19 
vote

public final Collator getCollator(){
  if (collator == null) {
    collator=Collator.getInstance();
  }
  return collator;
}
 

Example 19

From project formic, under directory /src/java/org/formic/wizard/step/gui/.

Source file: InstallStep.java

  19 
vote

/** 
 * Invoked when an error occurs during execution of this step.
 * @param error The Throwable error that occured.
 */
protected void setError(Throwable error){
  this.error=error;
  error.printStackTrace();
  System.out.println("Installer Context (Please include in bug reports):");
  InstallContext context=Installer.getContext();
  ArrayList values=new ArrayList();
  for (Iterator ii=context.keys(); ii.hasNext(); ) {
    Object key=ii.next();
    values.add(key + "=" + context.getValue(key));
  }
  Collections.sort(values,Collator.getInstance());
  for (Iterator ii=values.iterator(); ii.hasNext(); ) {
    System.out.println("  " + ii.next());
  }
  GuiDialogs.showError(error);
  overallLabel.setText(getName() + ": " + Installer.getString("error.dialog.text"));
  showErrorButton.setVisible(true);
  setValid(false);
}
 

Example 20

From project hackergarten-moreunit, under directory /org.moreunit.plugin/src/org/moreunit/util/.

Source file: TestNamingPatternAwareTypeComparator.java

  19 
vote

public int compare(IType type1,IType type2){
  String type1Name=getNameWithoutTestPrefixAndSufixIfAny(type1);
  String type2Name=getNameWithoutTestPrefixAndSufixIfAny(type2);
  int comparisonResult=Collator.getInstance().compare(type1Name,type2Name);
  if (comparisonResult == 0) {
    comparisonResult=Collator.getInstance().compare(type1.getPackageFragment().getElementName(),type2.getPackageFragment().getElementName());
  }
  return comparisonResult;
}
 

Example 21

From project httpcache4j, under directory /httpcache4j-storage-api/src/main/java/org/codehaus/httpcache4j/cache/.

Source file: Vary.java

  19 
vote

private Collator getCollator(){
  if (collator == null) {
    collator=Collator.getInstance(Locale.UK);
  }
  return collator;
}
 

Example 22

From project incubator, under directory /net.karlmartens.platform/src/net/karlmartens/platform/util/.

Source file: NumberStringComparator.java

  19 
vote

public NumberStringComparator(NumberFormat format,Collator collator,double tolerance){
  _format=format;
  _collator=collator;
  _tolerance=tolerance;
  _bi=new BreakIterator[]{BreakIterator.getWordInstance(),BreakIterator.getWordInstance()};
}
 

Example 23

From project jpropel-light, under directory /src/propel/core/utils/.

Source file: StringUtils.java

  19 
vote

/** 
 * Locale-aware comparison.
 * @throws NullPointerException An argument is null
 */
@Validate private static int compareLocaleSensitive(String a,String b,@NotNull final Locale locale,@NotNull final Collator collator,boolean caseSensitive){
  if (!caseSensitive) {
    a=a.toLowerCase(locale);
    b=b.toLowerCase(locale);
  }
  return collator.compare(a,b);
}
 

Example 24

From project NotePad, under directory /NotePad/src/org/openintents/notepad/noteslist/.

Source file: NotesList.java

  19 
vote

protected void updateTagList(){
  List<String> taglist=new ArrayList<String>();
  Uri notesUri=getIntent().getData();
  Cursor managedCursor=getContentResolver().query(notesUri,new String[]{Notes.TAGS,Notes.ENCRYPTED},null,null,null);
  if (managedCursor.moveToFirst()) {
    do {
      String tags=managedCursor.getString(0);
      long encrypted=managedCursor.getLong(1);
      if (!TextUtils.isEmpty(tags)) {
        if (encrypted == 0) {
          for (          String tag : tags.split(",")) {
            if (!taglist.contains(tag.trim())) {
              taglist.add(tag.trim());
            }
          }
        }
 else {
        }
      }
    }
 while (managedCursor.moveToNext());
  }
  Collections.sort(taglist,Collator.getInstance(Locale.getDefault()));
  taglist.add(0,getString(R.string.all_notes));
  Spinner s=(Spinner)findViewById(R.id.tagselection);
  ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_item,taglist);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  s.setAdapter(adapter);
  if (taglist.size() > 1) {
    s.setVisibility(View.VISIBLE);
  }
 else {
    s.setVisibility(View.GONE);
  }
}
 

Example 25

From project platform_packages_apps_contacts, under directory /src/com/android/contacts/util/.

Source file: PhonebookCollatorFactory.java

  19 
vote

public static final Collator getCollator(){
  final Locale defaultLocale=Locale.getDefault();
  final String defaultLocaleString=defaultLocale.toString();
  final Locale locale;
  if ("ja".equals(defaultLocaleString) || "ja_JP".equals(defaultLocaleString)) {
    locale=new Locale("[email protected]=phonebook");
  }
 else {
    locale=defaultLocale;
  }
  return Collator.getInstance(locale);
}
 

Example 26

From project platform_packages_apps_settings, under directory /src/com/android/settings/.

Source file: AppWidgetPickActivity.java

  19 
vote

/** 
 * Build and return list of items to be shown in dialog. This will mix both installed  {@link AppWidgetProviderInfo} and those provided through{@link AppWidgetManager#EXTRA_CUSTOM_INFO}, sorting them alphabetically.
 */
@Override protected List<PickAdapter.Item> getItems(){
  List<PickAdapter.Item> items=new ArrayList<PickAdapter.Item>();
  putInstalledAppWidgets(items);
  putCustomAppWidgets(items);
  Collections.sort(items,new Comparator<PickAdapter.Item>(){
    Collator mCollator=Collator.getInstance();
    public int compare(    PickAdapter.Item lhs,    PickAdapter.Item rhs){
      return mCollator.compare(lhs.label,rhs.label);
    }
  }
);
  return items;
}
 

Example 27

From project platform_packages_providers_contactsprovider, under directory /src/com/android/providers/contacts/.

Source file: HanziToPinyin.java

  19 
vote

public static HanziToPinyin getInstance(){
synchronized (HanziToPinyin.class) {
    if (sInstance != null) {
      return sInstance;
    }
    final Locale locale[]=Collator.getAvailableLocales();
    for (int i=0; i < locale.length; i++) {
      if (locale[i].equals(Locale.CHINA)) {
        if (DEBUG) {
          Log.d(TAG,"Self validation. Result: " + doSelfValidation());
        }
        sInstance=new HanziToPinyin(true);
        return sInstance;
      }
    }
    Log.w(TAG,"There is no Chinese collator, HanziToPinyin is disabled");
    sInstance=new HanziToPinyin(false);
    return sInstance;
  }
}
 

Example 28

From project ps3mediaserver, under directory /src/main/java/net/pms/util/.

Source file: NaturalComparator.java

  19 
vote

/** 
 * Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.
 * @param collator used for locale specific comparison of text (non-number) subwords - must not be null
 * @return <p>A string comparator that uses the given Collator to compare subwords and handles embedded numberscorrectly.</p>
 * @see #getNaturalComparator()
 */
public static Comparator<String> getNaturalComparator(final Collator collator){
  if (collator == null) {
    throw new NullPointerException("collator must not be null");
  }
  return new Comparator<String>(){
    public int compare(    String o1,    String o2){
      return compareNatural(collator,o1,o2);
    }
  }
;
}
 

Example 29

From project scisoft-ui, under directory /uk.ac.diamond.scisoft.analysis.rcp/src/uk/ac/diamond/scisoft/analysis/rcp/plotting/actions/.

Source file: ShowPlotViewMenu.java

  19 
vote

@Override public int compare(CommandContributionItemParameter o1,CommandContributionItemParameter o2){
  if (collator == null) {
    collator=Collator.getInstance();
  }
  return collator.compare(o1.label,o2.label);
}
 

Example 30

From project SIREn, under directory /siren-core/src/main/java/org/sindice/siren/search/.

Source file: SirenTermRangeQuery.java

  19 
vote

/** 
 * Constructs a query selecting all terms greater/equal than <code>lowerTerm</code> but less/equal than <code>upperTerm</code>. <p> If an endpoint is null, it is said to be "open". Either or both endpoints may be open.  Open endpoints may not be exclusive (you can't select all but the first or last term without explicitly specifying the term to exclude.) <p> If <code>collator</code> is not null, it will be used to decide whether index terms are within the given range, rather than using the Unicode code point order in which index terms are stored. <p> <strong>WARNING:</strong> Using this constructor and supplying a non-null value in the <code>collator</code> parameter will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined.  Depending on the number of index Terms in this Field, the operation could be very slow.
 * @param lowerTerm The Term text at the lower end of the range
 * @param upperTerm The Term text at the upper end of the range
 * @param includeLower If true, the <code>lowerTerm</code> is included in the range.
 * @param includeUpper If true, the <code>upperTerm</code> is included in the range.
 * @param collator The collator to use to collate index Terms, to determinetheir membership in the range bounded by <code>lowerTerm</code> and <code>upperTerm</code>.
 */
public SirenTermRangeQuery(final String field,final String lowerTerm,final String upperTerm,final boolean includeLower,final boolean includeUpper,final Collator collator){
  this.field=field;
  this.lowerTerm=lowerTerm;
  this.upperTerm=upperTerm;
  this.includeLower=includeLower;
  this.includeUpper=includeUpper;
  this.collator=collator;
}
 

Example 31

From project swtbot, under directory /org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/test/ui/editors/.

Source file: MultiPageEditor.java

  19 
vote

/** 
 * Sorts the words in page 0, and shows them in page 2.
 */
void sortWords(){
  String editorText=editor.getDocumentProvider().getDocument(editor.getEditorInput()).get();
  StringTokenizer tokenizer=new StringTokenizer(editorText," \t\n\r\[email protected]#\u0024%^&*()-_=+`~[]{};:'\",.<>/?|\\");
  ArrayList editorWords=new ArrayList();
  while (tokenizer.hasMoreTokens()) {
    editorWords.add(tokenizer.nextToken());
  }
  Collections.sort(editorWords,Collator.getInstance());
  StringWriter displayText=new StringWriter();
  for (int i=0; i < editorWords.size(); i++) {
    displayText.write(((String)editorWords.get(i)));
    displayText.write(System.getProperty("line.separator"));
  }
  text.setText(displayText.toString());
}
 

Example 32

From project UniversalMediaServer, under directory /src/main/java/net/pms/util/.

Source file: NaturalComparator.java

  19 
vote

/** 
 * Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.
 * @param collator used for locale specific comparison of text (non-number) subwords - must not be null
 * @return <p>A string comparator that uses the given Collator to compare subwords and handles embedded numberscorrectly.</p>
 * @see #getNaturalComparator()
 */
public static Comparator<String> getNaturalComparator(final Collator collator){
  if (collator == null) {
    throw new NullPointerException("collator must not be null");
  }
  return new Comparator<String>(){
    public int compare(    String o1,    String o2){
      return compareNatural(collator,o1,o2);
    }
  }
;
}
 

Example 33

From project VisiCut, under directory /src/com/t_oster/visicut/model/.

Source file: MaterialProfile.java

  19 
vote

public int compareTo(Object t){
  if (t instanceof MaterialProfile) {
    return Collator.getInstance().compare(this.name,((MaterialProfile)t).getName());
  }
  return 1;
}