From: Roland Häder Date: Mon, 19 Mar 2018 23:37:05 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7cae5a73ec5548541256567d5ffe364e5fd510b1;p=jbonuscard-core.git Continued: - implemented Comparable interface Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java b/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java index f9c9f2a..1007da0 100644 --- a/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java +++ b/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java @@ -162,11 +162,11 @@ public class FinancialBonusCard implements BonusCard { @Override public int compareTo (final BonusCard bonusCard) { - // For performance reasons + // Check parameter on null-reference and equality to this if (null == bonusCard) { // Should not happen throw new NullPointerException("bonusCard is null"); //NOI18N - } else if (Objects.equals(this, bonusCard)) { + } else if (bonusCard.equals(this)) { // Same object return 0; } diff --git a/src/org/mxchange/jfinancials/model/income/BillableIncome.java b/src/org/mxchange/jfinancials/model/income/BillableIncome.java index 2285c97..080d0a1 100644 --- a/src/org/mxchange/jfinancials/model/income/BillableIncome.java +++ b/src/org/mxchange/jfinancials/model/income/BillableIncome.java @@ -17,6 +17,7 @@ package org.mxchange.jfinancials.model.income; import java.io.Serializable; +import java.math.BigDecimal; import java.util.Date; import org.mxchange.jfinancials.model.income.interval.FinancialInterval; import org.mxchange.jusercore.model.user.User; @@ -26,7 +27,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface BillableIncome extends Serializable { +public interface BillableIncome extends Comparable, Serializable { /** * Getter for income id (primary key) @@ -89,14 +90,14 @@ public interface BillableIncome extends Serializable { *

* @return Income single amount */ - Float getIncomeSingleAmount (); + BigDecimal getIncomeSingleAmount (); /** * Setter for income single amount *

* @param incomeSingleAmount Income single amount */ - void setIncomeSingleAmount (final Float incomeSingleAmount); + void setIncomeSingleAmount (final BigDecimal incomeSingleAmount); /** * Getter for income title diff --git a/src/org/mxchange/jfinancials/model/income/FinancialIncome.java b/src/org/mxchange/jfinancials/model/income/FinancialIncome.java index 92ba782..734abb8 100644 --- a/src/org/mxchange/jfinancials/model/income/FinancialIncome.java +++ b/src/org/mxchange/jfinancials/model/income/FinancialIncome.java @@ -16,6 +16,7 @@ */ package org.mxchange.jfinancials.model.income; +import java.math.BigDecimal; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -33,6 +34,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.mxchange.jcoreutils.Comparables; import org.mxchange.jfinancials.model.income.interval.FinancialInterval; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -90,7 +92,7 @@ public class FinancialIncome implements BillableIncome { */ @Basic (optional = false) @Column (name = "income_single_amount", nullable = false) - private Float incomeSingleAmount; + private BigDecimal incomeSingleAmount; /** * Income title @@ -128,7 +130,7 @@ public class FinancialIncome implements BillableIncome { * @param incomeInterval Interval * @param incomeUser Connected user */ - public FinancialIncome (final String incomeTitle, final Float incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) { + public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) { // Call default constructor this(); @@ -142,6 +144,36 @@ public class FinancialIncome implements BillableIncome { this.incomeEnabled = Boolean.TRUE; } + @Override + public int compareTo (final BillableIncome billableIncome) { + // Check parameter on null-reference and equality to this + if (null == billableIncome) { + // Should not happen + throw new NullPointerException("billableIncome is null"); //NOI18N + } else if (billableIncome.equals(this)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First compare title + this.getIncomeTitle().compareToIgnoreCase(billableIncome.getIncomeTitle()), + // ... then compare interval + this.getIncomeInterval().compareTo(billableIncome.getIncomeInterval()), + // ... value + this.getIncomeSingleAmount().compareTo(billableIncome.getIncomeSingleAmount()), + // ... user instance + this.getIncomeUser().compareTo(billableIncome.getIncomeUser()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (this == object) { @@ -202,17 +234,17 @@ public class FinancialIncome implements BillableIncome { } @Override - public void setIncomeInterval (FinancialInterval incomeInterval) { + public void setIncomeInterval (final FinancialInterval incomeInterval) { this.incomeInterval = incomeInterval; } @Override - public Float getIncomeSingleAmount () { + public BigDecimal getIncomeSingleAmount () { return this.incomeSingleAmount; } @Override - public void setIncomeSingleAmount (Float incomeSingleAmount) { + public void setIncomeSingleAmount (final BigDecimal incomeSingleAmount) { this.incomeSingleAmount = incomeSingleAmount; } diff --git a/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java b/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java index 5e5ca0d..7938dcb 100644 --- a/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java @@ -29,7 +29,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface BillableReceipt extends Serializable { +public interface BillableReceipt extends Comparable, Serializable { /** * Getter for receipt bar-code number diff --git a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java index de53976..818496f 100644 --- a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java @@ -36,15 +36,21 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices; import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.employee.Employees; +import org.mxchange.jcoreutils.Comparables; +import org.mxchange.jcoreutils.SafeNumberUtils; import org.mxchange.jfinancials.model.bonus_card.BonusCard; import org.mxchange.jfinancials.model.bonus_card.FinancialBonusCard; import org.mxchange.jproduct.model.payment.PaymentType; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.Users; /** * @@ -228,6 +234,46 @@ public class FinancialReceipt implements BillableReceipt { this.receiptIssued = receiptIssued; } + @Override + public int compareTo (final BillableReceipt billableReceipt) { + // Check parameter on null-reference and equality to this + if (null == billableReceipt) { + // Should not happen + throw new NullPointerException("billableReceipt is null"); //NOI18N + } else if (billableReceipt.equals(this)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First compare receipt number + StringUtils.compare(this.getReceiptNumber(), billableReceipt.getReceiptNumber()), + // ... next bar-code + StringUtils.compare(this.getReceiptBarCodeNumber(), billableReceipt.getReceiptBarCodeNumber()), + // ... sequence number + SafeNumberUtils.compare(this.getReceiptSequenceNumber(), billableReceipt.getReceiptSequenceNumber()), + // ... payment type + this.getReceiptPaymentType().compareTo(billableReceipt.getReceiptPaymentType()), + // ... register number + SafeNumberUtils.compare(this.getReceiptRegisterNumber(), billableReceipt.getReceiptRegisterNumber()), + // ... issue date + this.getReceiptIssued().compareTo(billableReceipt.getReceiptIssued()), + // ... next is seller instance + Employees.compare(this.getReceiptSellerEmployee(), billableReceipt.getReceiptSellerEmployee()), + // .. branch office + BranchOffices.compare(this.getReceiptBranchOffice(), billableReceipt.getReceiptBranchOffice()), + // ... and user instance + Users.compare(this.getReceiptUser(), billableReceipt.getReceiptUser()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (this == object) { diff --git a/src/org/mxchange/jfinancials/model/receipt_item/BillableReceiptItem.java b/src/org/mxchange/jfinancials/model/receipt_item/BillableReceiptItem.java index b573f09..3ced262 100644 --- a/src/org/mxchange/jfinancials/model/receipt_item/BillableReceiptItem.java +++ b/src/org/mxchange/jfinancials/model/receipt_item/BillableReceiptItem.java @@ -29,7 +29,7 @@ import org.mxchange.jproduct.model.product.Product; *

* @author Roland Häder */ -public interface BillableReceiptItem extends Serializable { +public interface BillableReceiptItem extends Comparable, Serializable { /** * Getter for item's product category diff --git a/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java b/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java index 93c6735..7ddc830 100644 --- a/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java +++ b/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java @@ -34,14 +34,18 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; +import org.mxchange.jcoreutils.Comparables; +import org.mxchange.jcoreutils.SafeNumberUtils; import org.mxchange.jfinancials.model.receipt.BillableReceipt; import org.mxchange.jfinancials.model.receipt.FinancialReceipt; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.category.ProductCategory; import org.mxchange.jproduct.model.product.GenericProduct; import org.mxchange.jproduct.model.product.Product; +import org.mxchange.jproduct.model.product.Products; /** * A POJO for receipt items @@ -194,6 +198,44 @@ public class FinancialReceiptItem implements BillableReceiptItem { this.itemReceipt = itemReceipt; } + @Override + public int compareTo (final BillableReceiptItem billableReceiptItem) { + // Check parameter on null-reference and equality to this + if (null == billableReceiptItem) { + // Should not happen + throw new NullPointerException("billableReceiptItem is null"); //NOI18N + } else if (billableReceiptItem.equals(this)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First check brand name ... + StringUtils.compare(this.getItemBrandName(), billableReceiptItem.getItemBrandName()), + // ... item number + SafeNumberUtils.compare(this.getItemNumber(), billableReceiptItem.getItemNumber()), + // ... coupon number + StringUtils.compare(this.getItemCouponNumber(), billableReceiptItem.getItemCouponNumber()), + // ... gross price + SafeNumberUtils.compare(this.getItemGrossPrice(), billableReceiptItem.getItemGrossPrice()), + // ... net price + SafeNumberUtils.compare(this.getItemNetPrice(), billableReceiptItem.getItemNetPrice()), + // ... tax rate + SafeNumberUtils.compare(this.getItemTaxRate(), billableReceiptItem.getItemTaxRate()), + // ... product quanity + this.getItemProductQuantity().compareTo(billableReceiptItem.getItemProductQuantity()), + // ... product instance + Products.compare(this.getItemProduct(), billableReceiptItem.getItemProduct()), + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (this == object) {