Advertisement
Guest User

111

a guest
May 31st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. public static final Comparator<R020Operation> COMPARATOR_NEW = new Comparator<R020Operation>() {
  2.         @Override
  3.         public int compare(R020Operation a, R020Operation b) {
  4.             int result = 0;
  5.  
  6.             if (a.getDebet() == null) a.setDebet(BigDecimal.ZERO);
  7.             if (b.getDebet() == null) b.setDebet(BigDecimal.ZERO);
  8.             if (a.getCredit() == null) a.setCredit(BigDecimal.ZERO);
  9.             if (b.getCredit() == null) b.setCredit(BigDecimal.ZERO);
  10.             boolean isDebetOperationA = a.getDebet().compareTo(BigDecimal.ZERO) > 0;
  11.             boolean isDebetOperationB = b.getDebet().compareTo(BigDecimal.ZERO) > 0;
  12.  
  13.             if (a.getOperationDate() != null && b.getOperationDate() != null) {
  14.                 Date dateA = DateUtils.truncateTime(a.getOperationDate());
  15.                 Date dateB = DateUtils.truncateTime(b.getOperationDate());
  16.                 result = dateA.compareTo(dateB);
  17.             }
  18.  
  19.             if (result == 0) result = ((Boolean) (!isDebetOperationA)).compareTo(!isDebetOperationB);
  20.             if (result == 0) result = (isDebetOperationA ? a.getDebet() : a.getCredit()).compareTo(isDebetOperationB ? b.getDebet() : b.getCredit());
  21.             if (result == 0){
  22.                 Integer documentNumberA;
  23.                 Integer documentNumberB;
  24.                 try {
  25.                     documentNumberA = Integer.parseInt(a.getDocumentNumber());
  26.                 } catch (NumberFormatException e) {
  27.                     documentNumberA = 0;
  28.                 }
  29.                 try {
  30.                     documentNumberB = Integer.parseInt(b.getDocumentNumber());
  31.                 } catch (NumberFormatException e) {
  32.                     documentNumberB = 0;
  33.                 }
  34.  
  35.                 result = documentNumberA.compareTo(documentNumberB);
  36.             }
  37.  
  38.             return result;
  39.         }
  40.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement