/** @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */
 public int compare(FormField formField, FormField other) {
   int temp =
       OpenmrsUtil.compareWithNullAsGreatest(formField.getPageNumber(), other.getPageNumber());
   if (temp == 0) {
     temp =
         OpenmrsUtil.compareWithNullAsGreatest(
             formField.getFieldNumber(), other.getFieldNumber());
   }
   if (temp == 0) {
     temp =
         OpenmrsUtil.compareWithNullAsGreatest(formField.getFieldPart(), other.getFieldPart());
   }
   if (temp == 0
       && formField.getPageNumber() == null
       && formField.getFieldNumber() == null
       && formField.getFieldPart() == null) {
     temp =
         OpenmrsUtil.compareWithNullAsGreatest(formField.getSortWeight(), other.getSortWeight());
   }
   if (temp == 0) {
     // to prevent ties
     temp =
         OpenmrsUtil.compareWithNullAsGreatest(
             formField.getFormFieldId(), other.getFormFieldId());
   }
   return temp;
 }
Esempio n. 2
0
  /** @see java.lang.Comparable#compareTo(java.lang.Object) */
  public int compareTo(PersonAddress other) {
    int retValue = 0;
    if (other != null) {
      retValue = isVoided().compareTo(other.isVoided());
      if (retValue == 0) retValue = other.isPreferred().compareTo(isPreferred());
      if (retValue == 0 && getDateCreated() != null)
        retValue = OpenmrsUtil.compareWithNullAsLatest(getDateCreated(), other.getDateCreated());
      if (retValue == 0)
        retValue =
            OpenmrsUtil.compareWithNullAsGreatest(getPersonAddressId(), other.getPersonAddressId());

      // if we've gotten this far, just check all address values. If they are
      // equal, leave the objects at 0. If not, arbitrarily pick retValue=1
      // and return that (they are not equal).
      if (retValue == 0 && !equalsContent(other)) retValue = 1;
    }
    return retValue;
  }