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.jshopcore.BaseShopCore;
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
29 public class BaseItem extends BaseShopCore implements AddableBasketItem {
31 * Entry id (from database backend)
48 private String itemType;
51 public Float calculateTotalPrice () {
52 // product should be set
53 if (this.getProduct() == null) {
55 throw new NullPointerException("product is null"); //NOI18N
58 // Calculate and return it
59 // TODO: If later other purchaseable items (other than products) are handled through this class, this needs expansion
60 return (this.getAmount() * this.getProduct().getPrice());
64 public int compareTo (final AddableBasketItem item) {
66 this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
68 // item should not be null
70 throw new NullPointerException("item is null"); //NOI18N
74 this.getLogger().debug(MessageFormat.format("this.itemId={0},item.itemId={1}", this.getItemId(), item.getItemId())); //NOI18N
76 // Is the id the same?
77 if (Objects.equals(this.getItemId(), item.getItemId())) {
78 // Same id, means same item
80 } else if (this.getItemId() > item.getItemId()) {
81 // This id is larger than compared to
85 // The other id is larger
90 public final Long getAmount () {
95 public final void setAmount (final Long amount) {
100 public final Long getId () {
105 public final void setId (final Long id) {
110 public final Long getItemId () {
115 public final void setItemId( final Long itemId) {
116 this.itemId = itemId;
120 public final String getItemType () {
121 return this.itemType;
125 public final void setItemType (final String itemType) {
126 this.itemType = itemType;