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.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.jcore.BaseFrameworkSystem;
22 import org.mxchange.jshopcore.model.product.Product;
25 * An item (addedable to a basket) could respresent a product or a discount
26 * coupon. This depends on the type of the item.
28 * @author Roland Haeder
30 public abstract class BaseItem extends BaseFrameworkSystem implements AddableBasketItem {
32 * Entry id (from database backend)
49 private String itemType;
54 private Product product;
57 public Float calculateTotalPrice () {
58 // product should be set
59 if (this.getProduct() == null) {
61 throw new NullPointerException("product is null"); //NOI18N
64 // Calculate and return it
65 // TODO: If later other purchaseable items (other than products) are handled through this class, this needs expansion
66 return (this.getAmount() * this.getProduct().getPrice());
70 public int compareTo (final AddableBasketItem item) {
72 this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
74 // item should not be null
76 throw new NullPointerException("item is null"); //NOI18N
80 this.getLogger().debug(MessageFormat.format("this.itemId={0},item.itemId={1}", this.getItemId(), item.getItemId())); //NOI18N
82 // Is the id the same?
83 if (Objects.equals(this.getItemId(), item.getItemId())) {
84 // Same id, means same item
86 } else if (this.getItemId() > item.getItemId()) {
87 // This id is larger than compared to
91 // The other id is larger
96 public Long getAmount () {
101 public void setAmount (final Long amount) {
102 this.amount = amount;
106 public Long getId () {
111 public void setId (final Long id) {
116 public Long getItemId () {
121 public void setItemId( final Long itemId) {
122 this.itemId = itemId;
126 public String getItemType () {
127 return this.itemType;
131 public void setItemType (final String itemType) {
132 this.itemType = itemType;
136 * @return the product
139 public Product getProduct () {
144 * @param product the product to set
147 public void setProduct (final Product product) {
148 this.product = product;