+++ /dev/null
-/*
- * 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.io.Serializable;
-import java.util.Date;
-import org.mxchange.jfinancials.model.receipt.BillableReceipt;
-import org.mxchange.jproduct.model.product.Product;
-
-/**
- * An interface for receipt items
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface BillableReceiptItem extends Serializable {
-
- /**
- * Getter when this receipt item has been created in database
- * <p>
- * @return When this item has been created
- */
- Date getItemCreated ();
-
- /**
- * Setter when this receipt item has been created in database
- * <p>
- * @param itemCreated When this item has been created
- */
- void setItemCreated (final Date itemCreated);
-
- /**
- * Getter for primary key
- * <p>
- * @return Primary key
- */
- Long getItemId ();
-
- /**
- * Setter for primary key
- * <p>
- * @param itemId Primary key
- */
- void setItemId (final Long itemId);
-
- /**
- * Getter for receipt instance
- * <p>
- * @return Receipt instance
- */
- BillableReceipt getItemReceipt ();
-
- /**
- * Setter for receipt instance
- * <p>
- * @param itemReceipt Receipt instance
- */
- void setItemReceipt (final BillableReceipt itemReceipt);
-
- /**
- * Getter for linked product
- * <p>
- * @return Product
- */
- Product getItemProduct ();
-
- /**
- * Setter for linked product
- * <p>
- * @param itemProduct Product
- */
- void setItemProduct (final Product itemProduct);
-
- /**
- * Getter for product discount
- * <p>
- * @return Product discount
- */
- Float getItemProductDiscount ();
-
- /**
- * Setter for product discount
- * <p>
- * @param productDiscount Product discount
- */
- void setItemProductDiscount (final Float productDiscount);
-
- /**
- * Getter for product quantity
- * <p>
- * @return Product quantity
- */
- Long getItemProductQuantity ();
-
- /**
- * Setter for product quantity
- * <p>
- * @param itemProductQuantity Product quantity
- */
- void setItemProductQuantity (final Long itemProductQuantity);
-
- @Override
- boolean equals (final Object object);
-
- @Override
- int hashCode ();
-
-}
+++ /dev/null
-/*
- * 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.NamedQueries;
-import javax.persistence.NamedQuery;
-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)
- }
-)
-@NamedQueries(
- {
- @NamedQuery(name = "AllReceiptItems", query = "SELECT ri FROM receipt_items AS ri ORDER BY ri.itemId ASC"),
- @NamedQuery(name = "SearchAssignedReceiptItems", query = "SELECT ri FROM receipt_items AS ri WHERE ri.itemReceipt = :itemReceipt ORDER BY ri.itemId ASC"),
- @NamedQuery(name = "SearchAllUserReceiptItems", query = "SELECT ri FROM receipt_items AS ri JOIN receipts AS r ON ri.itemReceipt=r WHERE r.receiptUser = :receiptUser ORDER BY ri.itemId ASC")
- }
-)
-@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;
-
- /**
- * 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;
-
- /**
- * Discount on item
- */
- @Column (name = "item_product_discount")
- private Float itemProductDiscount;
-
- /**
- * 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 itemProductQuantity Product quantity
- * @param itemReceipt FinancialReceipt instance
- */
- public FinancialReceiptItem (final Product itemProduct, final Long itemProductQuantity, final BillableReceipt itemReceipt) {
- // Call other constructor
- this();
-
- // Set all values
- this.itemProduct = itemProduct;
- 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.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 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 getItemProductDiscount () {
- return this.itemProductDiscount;
- }
-
- @Override
- public void setItemProductDiscount (final Float itemProductDiscount) {
- this.itemProductDiscount = itemProductDiscount;
- }
-
- @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.getItemProductQuantity());
- hash = 53 * hash + Objects.hashCode(this.getItemReceipt());
-
- return hash;
- }
-
-}
+++ /dev/null
-/*
- * 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;
-
- /**
- * Checks if both receipt items are the same by assigned receipt, product
- * and quantity.
- * <p>
- * @param receiptItem1 Receipt item 1
- * @param receiptItem2 Receipt item 2
- * <p>
- * @return Whether both are equal
- */
- public static boolean isSameReceiptItem (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"); //NOI18N
- } else if ((receiptItem1.getItemId() instanceof Long) && (receiptItem1.getItemId() < 1)) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemId={0} is not valid.", receiptItem1.getItemId())); //NOI18N
- } else if (receiptItem1.getItemReceipt() == null) {
- // Throw NPE
- throw new NullPointerException("receiptItem1.itemReceipt is null"); //NOI18N
- } else if (receiptItem1.getItemReceipt().getReceiptId() == null) {
- // Throw NPE
- throw new NullPointerException("receiptItem1.itemReceipt.receiptId is null"); //NOI18N
- } else if (receiptItem1.getItemReceipt().getReceiptId() < 1) {
- // Throw NPE
- throw new NullPointerException(MessageFormat.format("receiptItem1.itemReceipt.receiptId={0} is not valid", receiptItem1.getItemReceipt().getReceiptId())); //NOI18N
- } else if (receiptItem1.getItemProduct() == null) {
- // Throw NPE again
- throw new NullPointerException("receiptItem1.itemProduct is null."); //NOI18N
- } else if (receiptItem1.getItemProduct().getProductId() == null) {
- // Throw NPE again
- throw new NullPointerException("receiptItem1.itemProduct.productId is null."); //NOI18N
- } else if (receiptItem1.getItemProduct().getProductId() < 1) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemProduct.productId={0} is invalid.", receiptItem1.getItemProduct().getProductId())); //NOI18N
- } else if (null == receiptItem2) {
- // Throw NPE
- throw new NullPointerException("receiptItem2 is null"); //NOI18N
- } else if ((receiptItem2.getItemId() instanceof Long) && (receiptItem2.getItemId() < 1)) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemId={0} is not valid.", receiptItem2.getItemId())); //NOI18N
- } else if (receiptItem2.getItemReceipt() == null) {
- // Throw NPE
- throw new NullPointerException("receiptItem2.itemReceipt is null"); //NOI18N
- } else if (receiptItem2.getItemReceipt().getReceiptId() == null) {
- // Throw NPE
- throw new NullPointerException("receiptItem2.itemReceipt.receiptId is null"); //NOI18N
- } else if (receiptItem2.getItemReceipt().getReceiptId() < 1) {
- // Throw NPE
- throw new NullPointerException(MessageFormat.format("receiptItem2.itemReceipt.receiptId={0} is not valid", receiptItem2.getItemReceipt().getReceiptId())); //NOI18N
- } else if (receiptItem2.getItemProduct() == null) {
- // Throw NPE again
- throw new NullPointerException("receiptItem2.itemProduct is null."); //NOI18N
- } else if (receiptItem2.getItemProduct().getProductId() == null) {
- // Throw NPE again
- throw new NullPointerException("receiptItem2.itemProduct.productId is null."); //NOI18N
- } else if (receiptItem2.getItemProduct().getProductId() < 1) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemProduct.productId={0} is invalid.", receiptItem2.getItemProduct().getProductId())); //NOI18N
- } else if (null == receiptItem2) {
- // Throw NPE
- throw new NullPointerException("receiptItem2 is null"); //NOI18N
- }
-
- // 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.getItemProductQuantity(), receiptItem2.getItemProductQuantity())) {
- // Other item quantity
- return false;
- }
-
- // Maybe same receipt!
- return true;
- }
-
- /**
- * Private default constructor
- */
- private ReceiptItems () {
- // Utilities don't have instances
- }
-
-}
--- /dev/null
+/*
+ * 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.io.Serializable;
+import java.util.Date;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * An interface for receipt items
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface BillableReceiptItem extends Serializable {
+
+ /**
+ * Getter when this receipt item has been created in database
+ * <p>
+ * @return When this item has been created
+ */
+ Date getItemCreated ();
+
+ /**
+ * Setter when this receipt item has been created in database
+ * <p>
+ * @param itemCreated When this item has been created
+ */
+ void setItemCreated (final Date itemCreated);
+
+ /**
+ * Getter for primary key
+ * <p>
+ * @return Primary key
+ */
+ Long getItemId ();
+
+ /**
+ * Setter for primary key
+ * <p>
+ * @param itemId Primary key
+ */
+ void setItemId (final Long itemId);
+
+ /**
+ * Getter for receipt instance
+ * <p>
+ * @return Receipt instance
+ */
+ BillableReceipt getItemReceipt ();
+
+ /**
+ * Setter for receipt instance
+ * <p>
+ * @param itemReceipt Receipt instance
+ */
+ void setItemReceipt (final BillableReceipt itemReceipt);
+
+ /**
+ * Getter for linked product
+ * <p>
+ * @return Product
+ */
+ Product getItemProduct ();
+
+ /**
+ * Setter for linked product
+ * <p>
+ * @param itemProduct Product
+ */
+ void setItemProduct (final Product itemProduct);
+
+ /**
+ * Getter for product discount
+ * <p>
+ * @return Product discount
+ */
+ Float getItemProductDiscount ();
+
+ /**
+ * Setter for product discount
+ * <p>
+ * @param productDiscount Product discount
+ */
+ void setItemProductDiscount (final Float productDiscount);
+
+ /**
+ * Getter for product quantity
+ * <p>
+ * @return Product quantity
+ */
+ Long getItemProductQuantity ();
+
+ /**
+ * Setter for product quantity
+ * <p>
+ * @param itemProductQuantity Product quantity
+ */
+ void setItemProductQuantity (final Long itemProductQuantity);
+
+ @Override
+ boolean equals (final Object object);
+
+ @Override
+ int hashCode ();
+
+}
--- /dev/null
+/*
+ * 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.NamedQueries;
+import javax.persistence.NamedQuery;
+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)
+ }
+)
+@NamedQueries(
+ {
+ @NamedQuery(name = "AllReceiptItems", query = "SELECT ri FROM receipt_items AS ri ORDER BY ri.itemId ASC"),
+ @NamedQuery(name = "SearchAssignedReceiptItems", query = "SELECT ri FROM receipt_items AS ri WHERE ri.itemReceipt = :itemReceipt ORDER BY ri.itemId ASC"),
+ @NamedQuery(name = "SearchAllUserReceiptItems", query = "SELECT ri FROM receipt_items AS ri JOIN receipts AS r ON ri.itemReceipt=r WHERE r.receiptUser = :receiptUser ORDER BY ri.itemId ASC")
+ }
+)
+@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;
+
+ /**
+ * 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;
+
+ /**
+ * Discount on item
+ */
+ @Column (name = "item_product_discount")
+ private Float itemProductDiscount;
+
+ /**
+ * 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 itemProductQuantity Product quantity
+ * @param itemReceipt FinancialReceipt instance
+ */
+ public FinancialReceiptItem (final Product itemProduct, final Long itemProductQuantity, final BillableReceipt itemReceipt) {
+ // Call other constructor
+ this();
+
+ // Set all values
+ this.itemProduct = itemProduct;
+ 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.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 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 getItemProductDiscount () {
+ return this.itemProductDiscount;
+ }
+
+ @Override
+ public void setItemProductDiscount (final Float itemProductDiscount) {
+ this.itemProductDiscount = itemProductDiscount;
+ }
+
+ @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.getItemProductQuantity());
+ hash = 53 * hash + Objects.hashCode(this.getItemReceipt());
+
+ return hash;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+
+ /**
+ * Checks if both receipt items are the same by assigned receipt, product
+ * and quantity.
+ * <p>
+ * @param receiptItem1 Receipt item 1
+ * @param receiptItem2 Receipt item 2
+ * <p>
+ * @return Whether both are equal
+ */
+ public static boolean isSameReceiptItem (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"); //NOI18N
+ } else if ((receiptItem1.getItemId() instanceof Long) && (receiptItem1.getItemId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemId={0} is not valid.", receiptItem1.getItemId())); //NOI18N
+ } else if (receiptItem1.getItemReceipt() == null) {
+ // Throw NPE
+ throw new NullPointerException("receiptItem1.itemReceipt is null"); //NOI18N
+ } else if (receiptItem1.getItemReceipt().getReceiptId() == null) {
+ // Throw NPE
+ throw new NullPointerException("receiptItem1.itemReceipt.receiptId is null"); //NOI18N
+ } else if (receiptItem1.getItemReceipt().getReceiptId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("receiptItem1.itemReceipt.receiptId={0} is not valid", receiptItem1.getItemReceipt().getReceiptId())); //NOI18N
+ } else if (receiptItem1.getItemProduct() == null) {
+ // Throw NPE again
+ throw new NullPointerException("receiptItem1.itemProduct is null."); //NOI18N
+ } else if (receiptItem1.getItemProduct().getProductId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("receiptItem1.itemProduct.productId is null."); //NOI18N
+ } else if (receiptItem1.getItemProduct().getProductId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemProduct.productId={0} is invalid.", receiptItem1.getItemProduct().getProductId())); //NOI18N
+ } else if (null == receiptItem2) {
+ // Throw NPE
+ throw new NullPointerException("receiptItem2 is null"); //NOI18N
+ } else if ((receiptItem2.getItemId() instanceof Long) && (receiptItem2.getItemId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemId={0} is not valid.", receiptItem2.getItemId())); //NOI18N
+ } else if (receiptItem2.getItemReceipt() == null) {
+ // Throw NPE
+ throw new NullPointerException("receiptItem2.itemReceipt is null"); //NOI18N
+ } else if (receiptItem2.getItemReceipt().getReceiptId() == null) {
+ // Throw NPE
+ throw new NullPointerException("receiptItem2.itemReceipt.receiptId is null"); //NOI18N
+ } else if (receiptItem2.getItemReceipt().getReceiptId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("receiptItem2.itemReceipt.receiptId={0} is not valid", receiptItem2.getItemReceipt().getReceiptId())); //NOI18N
+ } else if (receiptItem2.getItemProduct() == null) {
+ // Throw NPE again
+ throw new NullPointerException("receiptItem2.itemProduct is null."); //NOI18N
+ } else if (receiptItem2.getItemProduct().getProductId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("receiptItem2.itemProduct.productId is null."); //NOI18N
+ } else if (receiptItem2.getItemProduct().getProductId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemProduct.productId={0} is invalid.", receiptItem2.getItemProduct().getProductId())); //NOI18N
+ } else if (null == receiptItem2) {
+ // Throw NPE
+ throw new NullPointerException("receiptItem2 is null"); //NOI18N
+ }
+
+ // 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.getItemProductQuantity(), receiptItem2.getItemProductQuantity())) {
+ // Other item quantity
+ return false;
+ }
+
+ // Maybe same receipt!
+ return true;
+ }
+
+ /**
+ * Private default constructor
+ */
+ private ReceiptItems () {
+ // Utilities don't have instances
+ }
+
+}