]> git.mxchange.org Git - jfinancials-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 13 Oct 2017 21:43:54 +0000 (23:43 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 13 Oct 2017 21:43:54 +0000 (23:43 +0200)
- renamed ReceiptItem -> FinancialReceiptItem
- added utils class ReceiptItems

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/model/receipt/item/FinancialReceiptItem.java [new file with mode: 0644]
src/org/mxchange/jfinancials/model/receipt/item/ReceiptItem.java [deleted file]
src/org/mxchange/jfinancials/model/receipt/item/ReceiptItems.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jfinancials/model/receipt/item/FinancialReceiptItem.java b/src/org/mxchange/jfinancials/model/receipt/item/FinancialReceiptItem.java
new file mode 100644 (file)
index 0000000..66a602b
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.model.receipt.item;
+
+import java.util.Date;
+import java.util.Objects;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
+import org.mxchange.jfinancials.model.receipt.FinancialReceipt;
+import org.mxchange.jproduct.model.product.GenericProduct;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * A POJO for receipt items
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Entity (name = "receipt_items")
+@Table (
+               name = "receipt_items",
+               indexes = {
+                       @Index (name = "item_receipt_product", columnList = "item_receipt_id,item_product_id", unique = true)
+               }
+)
+@SuppressWarnings ("PersistenceUnitPresent")
+public class FinancialReceiptItem implements BillableReceiptItem {
+
+       /**
+        * Serial number
+        */
+       @Transient
+       private static final long serialVersionUID = 126_498_698_378_571L;
+
+       /**
+        * When this item has been created in database
+        */
+       @Basic (optional = false)
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "item_created", nullable = false)
+       private Date itemCreated;
+
+       /**
+        * Discount on item
+        */
+       @Column (name = "item_product_discount")
+       private Float itemDiscount;
+
+       /**
+        * Primary key
+        */
+       @Id
+       @GeneratedValue (strategy = GenerationType.IDENTITY)
+       @Column (name = "item_id", nullable = false, updatable = false)
+       private Long itemId;
+
+       /**
+        * Product being linked in this itemReceipt item
+        */
+       @JoinColumn (name = "item_product_id", referencedColumnName = "product_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH, optional = false)
+       private Product itemProduct;
+
+       /**
+        * Single product price (being copied here from GenericProduct)
+        */
+       @Basic (optional = false)
+       @Column (name = "item_product_price", nullable = false)
+       private Float itemProductPrice;
+
+       /**
+        * Product quantity
+        */
+       @Basic (optional = false)
+       @Column (name = "item_product_quantity", nullable = false)
+       private Long itemProductQuantity;
+
+       /**
+        * Connected itemReceipt item
+        */
+       @JoinColumn (name = "item_receipt_id", referencedColumnName = "receipt_id", nullable = false, updatable = false)
+       @OneToOne (targetEntity = FinancialReceipt.class, cascade = CascadeType.REFRESH, optional = false)
+       private BillableReceipt itemReceipt;
+
+       /**
+        * Default constructor
+        */
+       public FinancialReceiptItem () {
+       }
+
+       /**
+        * Constructor with product, price, quantity and receipt instance
+        * <p>
+        * @param itemProduct         Product instance
+        * @param itemProductPrice    Product price (copied)
+        * @param itemProductQuantity Product quantity
+        * @param itemReceipt         FinancialReceipt instance
+        */
+       public FinancialReceiptItem (final Product itemProduct, final Float itemProductPrice, final Long itemProductQuantity, final BillableReceipt itemReceipt) {
+               // Call other constructor
+               this();
+
+               // Set all values
+               this.itemProduct = itemProduct;
+               this.itemProductPrice = itemProductPrice;
+               this.itemProductQuantity = itemProductQuantity;
+               this.itemReceipt = itemReceipt;
+       }
+
+       @Override
+       public boolean equals (final Object object) {
+               if (this == object) {
+                       return true;
+               } else if (null == object) {
+                       return false;
+               } else if (this.getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final BillableReceiptItem receiptItem = (BillableReceiptItem) object;
+
+               if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
+                       return false;
+               } else if (!Objects.equals(this.getItemProduct(), receiptItem.getItemProduct())) {
+                       return false;
+               } else if (!Objects.equals(this.getItemProductPrice(), receiptItem.getItemProductPrice())) {
+                       return false;
+               } else if (!Objects.equals(this.getItemProductQuantity(), receiptItem.getItemProductQuantity())) {
+                       return false;
+               } else if (!Objects.equals(this.getItemReceipt(), receiptItem.getItemReceipt())) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getItemCreated () {
+               return this.itemCreated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setItemCreated (final Date itemCreated) {
+               this.itemCreated = itemCreated;
+       }
+
+       @Override
+       public Float getItemDiscount () {
+               return this.itemDiscount;
+       }
+
+       @Override
+       public void setItemDiscount (final Float itemDiscount) {
+               this.itemDiscount = itemDiscount;
+       }
+
+       @Override
+       public Long getItemId () {
+               return this.itemId;
+       }
+
+       @Override
+       public void setItemId (final Long itemId) {
+               this.itemId = itemId;
+       }
+
+       @Override
+       public Product getItemProduct () {
+               return this.itemProduct;
+       }
+
+       @Override
+       public void setItemProduct (final Product itemProduct) {
+               this.itemProduct = itemProduct;
+       }
+
+       @Override
+       public Float getItemProductPrice () {
+               return this.itemProductPrice;
+       }
+
+       @Override
+       public void setItemProductPrice (final Float itemProductPrice) {
+               this.itemProductPrice = itemProductPrice;
+       }
+
+       @Override
+       public Long getItemProductQuantity () {
+               return this.itemProductQuantity;
+       }
+
+       @Override
+       public void setItemProductQuantity (final Long itemProductQuantity) {
+               this.itemProductQuantity = itemProductQuantity;
+       }
+
+       @Override
+       public BillableReceipt getItemReceipt () {
+               return this.itemReceipt;
+       }
+
+       @Override
+       public void setItemReceipt (final BillableReceipt itemReceipt) {
+               this.itemReceipt = itemReceipt;
+       }
+
+       @Override
+       public int hashCode () {
+               int hash = 5;
+
+               hash = 53 * hash + Objects.hashCode(this.getItemId());
+               hash = 53 * hash + Objects.hashCode(this.getItemProduct());
+               hash = 53 * hash + Objects.hashCode(this.getItemProductPrice());
+               hash = 53 * hash + Objects.hashCode(this.getItemProductQuantity());
+               hash = 53 * hash + Objects.hashCode(this.getItemReceipt());
+
+               return hash;
+       }
+
+}
diff --git a/src/org/mxchange/jfinancials/model/receipt/item/ReceiptItem.java b/src/org/mxchange/jfinancials/model/receipt/item/ReceiptItem.java
deleted file mode 100644 (file)
index 8d9773d..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.model.receipt.item;
-
-import java.util.Date;
-import java.util.Objects;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Index;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import javax.persistence.Transient;
-import org.mxchange.jfinancials.model.receipt.BillableReceipt;
-import org.mxchange.jfinancials.model.receipt.FinancialReceipt;
-import org.mxchange.jproduct.model.product.GenericProduct;
-import org.mxchange.jproduct.model.product.Product;
-
-/**
- * A POJO for receipt items
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Entity (name = "receipt_items")
-@Table (
-               name = "receipt_items",
-               indexes = {
-                       @Index (name = "item_receipt_product", columnList = "item_receipt_id,item_product_id", unique = true)
-               }
-)
-@SuppressWarnings ("PersistenceUnitPresent")
-public class ReceiptItem implements BillableReceiptItem {
-
-       /**
-        * Serial number
-        */
-       @Transient
-       private static final long serialVersionUID = 126_498_698_378_571L;
-
-       /**
-        * When this item has been created in database
-        */
-       @Basic (optional = false)
-       @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "item_created", nullable = false)
-       private Date itemCreated;
-
-       /**
-        * Discount on item
-        */
-       @Column (name = "item_product_discount")
-       private Float itemDiscount;
-
-       /**
-        * Primary key
-        */
-       @Id
-       @GeneratedValue (strategy = GenerationType.IDENTITY)
-       @Column (name = "item_id", nullable = false, updatable = false)
-       private Long itemId;
-
-       /**
-        * Product being linked in this itemReceipt item
-        */
-       @JoinColumn (name = "item_product_id", referencedColumnName = "product_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH, optional = false)
-       private Product itemProduct;
-
-       /**
-        * Single product price (being copied here from GenericProduct)
-        */
-       @Basic (optional = false)
-       @Column (name = "item_product_price", nullable = false)
-       private Float itemProductPrice;
-
-       /**
-        * Product quantity
-        */
-       @Basic (optional = false)
-       @Column (name = "item_product_quantity", nullable = false)
-       private Long itemProductQuantity;
-
-       /**
-        * Connected itemReceipt item
-        */
-       @JoinColumn (name = "item_receipt_id", referencedColumnName = "receipt_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = FinancialReceipt.class, cascade = CascadeType.REFRESH, optional = false)
-       private BillableReceipt itemReceipt;
-
-       /**
-        * Default constructor
-        */
-       public ReceiptItem () {
-       }
-
-       /**
-        * Constructor with product, price, quantity and receipt instance
-        * <p>
-        * @param itemProduct         Product instance
-        * @param itemProductPrice    Product price (copied)
-        * @param itemProductQuantity Product quantity
-        * @param itemReceipt         FinancialReceipt instance
-        */
-       public ReceiptItem (final Product itemProduct, final Float itemProductPrice, final Long itemProductQuantity, final BillableReceipt itemReceipt) {
-               // Call other constructor
-               this();
-
-               // Set all values
-               this.itemProduct = itemProduct;
-               this.itemProductPrice = itemProductPrice;
-               this.itemProductQuantity = itemProductQuantity;
-               this.itemReceipt = itemReceipt;
-       }
-
-       @Override
-       public boolean equals (final Object object) {
-               if (this == object) {
-                       return true;
-               } else if (null == object) {
-                       return false;
-               } else if (this.getClass() != object.getClass()) {
-                       return false;
-               }
-
-               final BillableReceiptItem receiptItem = (BillableReceiptItem) object;
-
-               if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
-                       return false;
-               } else if (!Objects.equals(this.getItemProduct(), receiptItem.getItemProduct())) {
-                       return false;
-               } else if (!Objects.equals(this.getItemProductPrice(), receiptItem.getItemProductPrice())) {
-                       return false;
-               } else if (!Objects.equals(this.getItemProductQuantity(), receiptItem.getItemProductQuantity())) {
-                       return false;
-               } else if (!Objects.equals(this.getItemReceipt(), receiptItem.getItemReceipt())) {
-                       return false;
-               }
-
-               return true;
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfDateField")
-       public Date getItemCreated () {
-               return this.itemCreated;
-       }
-
-       @Override
-       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setItemCreated (final Date itemCreated) {
-               this.itemCreated = itemCreated;
-       }
-
-       @Override
-       public Float getItemDiscount () {
-               return this.itemDiscount;
-       }
-
-       @Override
-       public void setItemDiscount (final Float itemDiscount) {
-               this.itemDiscount = itemDiscount;
-       }
-
-       @Override
-       public Long getItemId () {
-               return this.itemId;
-       }
-
-       @Override
-       public void setItemId (final Long itemId) {
-               this.itemId = itemId;
-       }
-
-       @Override
-       public Product getItemProduct () {
-               return this.itemProduct;
-       }
-
-       @Override
-       public void setItemProduct (final Product itemProduct) {
-               this.itemProduct = itemProduct;
-       }
-
-       @Override
-       public Float getItemProductPrice () {
-               return this.itemProductPrice;
-       }
-
-       @Override
-       public void setItemProductPrice (final Float itemProductPrice) {
-               this.itemProductPrice = itemProductPrice;
-       }
-
-       @Override
-       public Long getItemProductQuantity () {
-               return this.itemProductQuantity;
-       }
-
-       @Override
-       public void setItemProductQuantity (final Long itemProductQuantity) {
-               this.itemProductQuantity = itemProductQuantity;
-       }
-
-       @Override
-       public BillableReceipt getItemReceipt () {
-               return this.itemReceipt;
-       }
-
-       @Override
-       public void setItemReceipt (final BillableReceipt itemReceipt) {
-               this.itemReceipt = itemReceipt;
-       }
-
-       @Override
-       public int hashCode () {
-               int hash = 5;
-
-               hash = 53 * hash + Objects.hashCode(this.getItemId());
-               hash = 53 * hash + Objects.hashCode(this.getItemProduct());
-               hash = 53 * hash + Objects.hashCode(this.getItemProductPrice());
-               hash = 53 * hash + Objects.hashCode(this.getItemProductQuantity());
-               hash = 53 * hash + Objects.hashCode(this.getItemReceipt());
-
-               return hash;
-       }
-
-}
diff --git a/src/org/mxchange/jfinancials/model/receipt/item/ReceiptItems.java b/src/org/mxchange/jfinancials/model/receipt/item/ReceiptItems.java
new file mode 100644 (file)
index 0000000..d7d4fd7
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.model.receipt.item;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Objects;
+
+/**
+ * A utilities class for receipts
+ *
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class ReceiptItems implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 2_867_938_676_165_402L;
+
+       public static boolean isSameReceipt (final BillableReceiptItem receiptItem1, final BillableReceiptItem receiptItem2) {
+               // Pre-compare both as entities (same id)
+               if (Objects.equals(receiptItem1, receiptItem2)) {
+                       // Same entity (with id number)
+                       return true;
+               }
+
+               // Validate parameter
+               if (null == receiptItem1) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem1 is null");
+               } else if ((receiptItem1.getItemId() instanceof Long) && (receiptItem1.getItemId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemId={0} is not valid.", receiptItem1.getItemId()));
+               } else if (receiptItem1.getItemReceipt()== null) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem1.itemReceipt is null");
+               } else if (receiptItem1.getItemReceipt().getReceiptId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem1.itemReceipt.receiptId is null");
+               } else if (receiptItem1.getItemReceipt().getReceiptId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("receiptItem1.itemReceipt.receiptId={0} is not valid", receiptItem1.getItemReceipt().getReceiptId()));
+               } else if (receiptItem1.getItemProduct() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("receiptItem1.itemProduct is null.");
+               } else if (receiptItem1.getItemProduct().getProductId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("receiptItem1.itemProduct.productId is null.");
+               } else if (receiptItem1.getItemProduct().getProductId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemProduct.productId={0} is invalid.", receiptItem1.getItemProduct().getProductId()));
+               } else if (null == receiptItem2) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem2 is null");
+               } else if ((receiptItem2.getItemId() instanceof Long) && (receiptItem2.getItemId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemId={0} is not valid.", receiptItem2.getItemId()));
+               } else if (receiptItem2.getItemReceipt()== null) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem2.itemReceipt is null");
+               } else if (receiptItem2.getItemReceipt().getReceiptId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem2.itemReceipt.receiptId is null");
+               } else if (receiptItem2.getItemReceipt().getReceiptId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("receiptItem2.itemReceipt.receiptId={0} is not valid", receiptItem2.getItemReceipt().getReceiptId()));
+               } else if (receiptItem2.getItemProduct() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("receiptItem2.itemProduct is null.");
+               } else if (receiptItem2.getItemProduct().getProductId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("receiptItem2.itemProduct.productId is null.");
+               } else if (receiptItem2.getItemProduct().getProductId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemProduct.productId={0} is invalid.", receiptItem2.getItemProduct().getProductId()));
+               } else if (null == receiptItem2) {
+                       // Throw NPE
+                       throw new NullPointerException("receiptItem2 is null");
+               }
+
+               // Now check all individually
+               if (!Objects.equals(receiptItem1.getItemReceipt(), receiptItem2.getItemReceipt())) {
+                       // Other item receipt
+                       return false;
+               } else if (!Objects.equals(receiptItem1.getItemProduct(), receiptItem2.getItemProduct())) {
+                       // Other item product
+                       return false;
+               } else if (!Objects.equals(receiptItem1.getItemProductPrice(), receiptItem2.getItemProductPrice())) {
+                       // Other product price
+                       return false;
+               } else if (!Objects.equals(receiptItem1.getItemProductQuantity(), receiptItem2.getItemProductQuantity())) {
+                       // Other item quantity
+                       return false;
+               }
+
+               // Maybe same receipt!
+               return true;
+       }
+
+       /**
+        * Private default constructor
+        */
+       private ReceiptItems () {
+               // Utilities don't have instances
+       }
+
+}