X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjfinancials%2Fmodel%2Freceipt%2FReceipts.java;h=a2f6d8a317f78d5951f292616b8215ca269d3184;hb=4269f830856a18f6c65f1ba5ced59db10bfd4de3;hp=24fb923a928acbfcdc6b36197dfacf2153eb528b;hpb=7cae5a73ec5548541256567d5ffe364e5fd510b1;p=jfinancials-core.git diff --git a/src/org/mxchange/jfinancials/model/receipt/Receipts.java b/src/org/mxchange/jfinancials/model/receipt/Receipts.java index 24fb923..a2f6d8a 100644 --- a/src/org/mxchange/jfinancials/model/receipt/Receipts.java +++ b/src/org/mxchange/jfinancials/model/receipt/Receipts.java @@ -32,6 +32,42 @@ public class Receipts implements Serializable { */ private static final long serialVersionUID = 2_867_938_676_165_401L; + /** + * Compares both receipt instances. This method returns -1 if second + * instance is null. + *

+ * @param receipt1 BillableReceipt instance 1 + * @param receipt2 BillableReceipt instance 2 + *

+ * @return Comparison value + */ + public static int compare (final BillableReceipt receipt1, final BillableReceipt receipt2) { + // Check euqality, then at least first must be given + if (Objects.equals(receipt1, receipt2)) { + // Both are same + return 0; + } else if (null == receipt1) { + // First is null + return -1; + } else if (null == receipt2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return receipt1.compareTo(receipt2); + } + + /** + * Checks whether both receipts are the same, means not true entity equality + * but if the receipt in general terms does already exist. A pre-check on + * entity equality is however performed to avoid below much longer code. + *

+ * @param receipt1 BillableReceipt instance 1 + * @param receipt2 BillableReceipt instance 2 + *

+ * @return Whether both receipts are the same (not instances) + */ public static boolean isSameReceipt (final BillableReceipt receipt1, final BillableReceipt receipt2) { // Pre-compare both as entities (same id) if (Objects.equals(receipt1, receipt2)) { @@ -58,7 +94,7 @@ public class Receipts implements Serializable { } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) { // Throw IAE throw new IllegalArgumentException("receipt1.receiptNumber is empty."); - } else if (receipt1.getReceiptPaymentType()== null) { + } else if (receipt1.getReceiptPaymentType() == null) { // Throw NPE throw new NullPointerException("receipt1.receiptPaymentType is null"); } else if (null == receipt2) { @@ -79,7 +115,7 @@ public class Receipts implements Serializable { } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) { // Throw IAE throw new IllegalArgumentException("receipt2.receiptNumber is empty."); - } else if (receipt2.getReceiptPaymentType()== null) { + } else if (receipt2.getReceiptPaymentType() == null) { // Throw NPE throw new NullPointerException("receipt2.receiptPaymentType is null"); }