2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jshopcore.model.item;
19 import java.util.Objects;
20 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
21 import org.mxchange.jshopcore.model.product.Product;
24 * An item (addedable to a basket) could respresent a product or a discount
25 * coupon. This depends on the type of the item.
27 * @author Roland Haeder<roland@mxchange.org>
29 public abstract class BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
34 private static final long serialVersionUID = 24_348_671_457_829_156L;
37 * Entry id (from database backend)
54 private String itemType;
59 private Product product;
62 public int compareTo (final AddableBasketItem item) {
63 // item should not be null
65 throw new NullPointerException("item is null"); //NOI18N
68 // Is the id the same?
69 if (Objects.equals(this.getItemId(), item.getItemId())) {
70 // Same id, means same item
72 } else if (this.getItemId() > item.getItemId()) {
73 // This id is larger than compared to
77 // The other id is larger
82 public Long getAmount () {
87 public void setAmount (final Long amount) {
92 public Long getId () {
97 public void setId (final Long id) {
102 public Long getItemId () {
107 public void setItemId (final Long itemId) {
108 this.itemId = itemId;
112 public String getItemType () {
113 return this.itemType;
117 public void setItemType (final String itemType) {
118 this.itemType = itemType;
122 public Product getProduct () {
127 public void setProduct (final Product product) {
128 this.product = product;
132 public boolean equals (final Object object) {
134 if (!(object instanceof BaseItem)) {
137 } else if (!(object instanceof AddableBasketItem)) {
138 // Not correct interface
142 // Securely cast to wanted interface
143 AddableBasketItem item = (AddableBasketItem) object;
145 // Item id and type must be the same
146 return ((Objects.equals(item.getItemId(), this.getItemId()))
147 && (Objects.equals(item.getItemType(), this.getItemType())));
151 public int hashCode () {
153 hash = 29 * hash + Objects.hashCode(this.getItemId());
154 hash = 29 * hash + Objects.hashCode(this.getItemType());
159 public boolean isProductType () {
160 // Is the instance set?
161 return (this.getProduct() instanceof Product);