Android Open Source - notes Note Comparator

From Project

Back to project page notes.


The source code is released under:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <> Everyone is permitted to copy and distribute verbatim or...

If you think the Android project notes 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.iliakplv.notes.notes;
/*w ww .  j av  a  2s  .  com*/
import java.util.Comparator;

public class NoteComparator implements Comparator<AbstractNote> {

  NotesUtils.NoteSortOrder order;

  public NoteComparator() {

  public NoteComparator(NotesUtils.NoteSortOrder order) {
    if (order == null) {
      throw new NullPointerException("Order is null");
    this.order = order;

  public NotesUtils.NoteSortOrder getSortOrder() {
    return order;

  public void setSortOrder(NotesUtils.NoteSortOrder order) {
    this.order = order;

  public int compare(AbstractNote lhs, AbstractNote rhs) {
    switch (order) {
      case Title:
        return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
      case CreateDateAscending:
        return lhs.getCreateTime().compareTo(rhs.getCreateTime());
      case CreateDateDescending:
        return rhs.getCreateTime().compareTo(lhs.getCreateTime());
      case ChangeDate: // Descending
        return rhs.getChangeTime().compareTo(lhs.getChangeTime());
        throw new IllegalArgumentException("Unknown sort order type: " + order.toString());

Java Source Code List