]> git.mxchange.org Git - jfinancials-core.git/blobdiff - src/org/mxchange/jfinancials/model/receipt/Receipts.java
Continued:
[jfinancials-core.git] / src / org / mxchange / jfinancials / model / receipt / Receipts.java
index 24fb923a928acbfcdc6b36197dfacf2153eb528b..a2f6d8a317f78d5951f292616b8215ca269d3184 100644 (file)
@@ -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.
+        * <p>
+        * @param receipt1 BillableReceipt instance 1
+        * @param receipt2 BillableReceipt instance 2
+        * <p>
+        * @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.
+        * <p>
+        * @param receipt1 BillableReceipt instance 1
+        * @param receipt2 BillableReceipt instance 2
+        * <p>
+        * @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");
                }