Android Open Source - ListIndex Index Comparator






From Project

Back to project page ListIndex.

License

The source code is released under:

Apache License

If you think the Android project ListIndex listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nozomi.listindex.view;
/* w  ww .ja v  a 2  s  . c  o  m*/
import java.util.Comparator;

public class IndexComparator implements Comparator<IndexString> {

  @Override
  public int compare(IndexString lhs, IndexString rhs) {
    boolean isLhsLetter = lhs.getFirstChar() >= 'A'
        && lhs.getFirstChar() <= 'Z';
    boolean isRhsLetter = rhs.getFirstChar() >= 'A'
        && rhs.getFirstChar() <= 'Z';

    if (isLhsLetter && !isRhsLetter) {
      return 1;
    } else if (!isLhsLetter && isRhsLetter) {
      return -1;
    } else {
      if (lhs.getFirstChar() == rhs.getFirstChar()) {
        // chs
        // return
        // Collator.getInstance(Locale.CHINA).compare(lhs.getString(),
        // rhs.getString());
        return lhs.getString().compareTo(rhs.getString());
      } else {
        return lhs.getFirstChar() - rhs.getFirstChar();
      }

    }
  }
}




Java Source Code List

com.nozomi.listindex.demo.Item.java
com.nozomi.listindex.demo.MainActivity.java
com.nozomi.listindex.view.IndexComparator.java
com.nozomi.listindex.view.IndexString.java
com.nozomi.listindex.view.IndexView.java