Пример #1
0
  @Override
  public int compareTo(Item another) {

    int comp1 = 0;
    if (getCategory() != null && another.getCategory() != null)
      comp1 = getCategory().compareToIgnoreCase(another.getCategory());
    else if (getCategory() == null) comp1 = -1;
    else if (another.getCategory() == null) comp1 = 1;
    else comp1 = 0;

    int comp2 = getName().compareToIgnoreCase(another.getName());
    int comp3 = getId().compareTo(another.getId());

    return comp1 * 10000 + comp2 * 100 + comp3;
  }
Пример #2
0
 /*
  * (non-Javadoc)
  *
  * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
  */
 @Override
 public int compare(Item object1, Item object2) {
   return object1.getName().compareToIgnoreCase(object2.getName());
 }