]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jshopcore/model/item/BaseItem.java
Moved stuff around + added dist.sh
[jcustomer-core.git] / src / org / mxchange / jshopcore / model / item / BaseItem.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jshopcore.model.item;
18
19 import java.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.jshopcore.BaseShopCore;
22
23 /**
24  * An item (addedable to a basket) could respresent a product or a discount
25  * coupon. This depends on the type of the item.
26  *
27  * @author Roland Haeder
28  */
29 public class BaseItem extends BaseShopCore implements AddableBasketItem {
30         /**
31          * Entry id (from database backend)
32          */
33         private Long id;
34
35         /**
36          * Item amount
37          */
38         private Long amount;
39
40         /**
41          * Item id number
42          */
43         private Long itemId;
44
45         /**
46          * Item type
47          */
48         private String itemType;
49
50         @Override
51         public Float calculateTotalPrice () {
52                 // product should be set
53                 if (this.getProduct() == null) {
54                         // Abort here
55                         throw new NullPointerException("product is null"); //NOI18N
56                 }
57
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());
61         }
62
63         @Override
64         public int compareTo (final AddableBasketItem item) {
65                 // Trace message
66                 this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
67                 
68                 // item should not be null
69                 if (null == item) {
70                         throw new NullPointerException("item is null"); //NOI18N
71                 }
72
73                 // Debug message
74                 this.getLogger().debug(MessageFormat.format("this.itemId={0},item.itemId={1}", this.getItemId(), item.getItemId())); //NOI18N
75
76                 // Is the id the same?
77                 if (Objects.equals(this.getItemId(), item.getItemId())) {
78                         // Same id, means same item
79                         return 0;
80                 } else if (this.getItemId() > item.getItemId()) {
81                         // This id is larger than compared to
82                         return -1;
83                 }
84
85                 // The other id is larger
86                 return 1;
87         }
88
89         @Override
90         public final Long getAmount () {
91                 return this.amount;
92         }
93
94         @Override
95         public final void setAmount (final Long amount) {
96                 this.amount = amount;
97         }
98
99         @Override
100         public final Long getId () {
101                 return this.id;
102         }
103
104         @Override
105         public final void setId (final Long id) {
106                 this.id = id;
107         }
108
109         @Override
110         public final Long getItemId () {
111                 return this.itemId;
112         }
113
114         @Override
115         public final void setItemId( final Long itemId) {
116                 this.itemId = itemId;
117         }
118
119         @Override
120         public final String getItemType () {
121                 return this.itemType;
122         }
123
124         @Override
125         public final void setItemType (final String itemType) {
126                 this.itemType = itemType;
127         }
128 }