]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jshopcore/model/item/BaseItem.java
Continued:
[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.jcoreee.BaseEeSystem;
22 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
23 import org.mxchange.jshopcore.model.product.Product;
24
25 /**
26  * An item (addedable to a basket) could respresent a product or a discount
27  * coupon. This depends on the type of the item.
28  *
29  * @author Roland Haeder
30  */
31 public abstract class BaseItem extends BaseEeSystem implements AddableBasketItem, Comparable<AddableBasketItem> {
32         /**
33          * Serial number
34          */
35         private static final long serialVersionUID = 24_348_671_457_829_156L;
36
37         /**
38          * Entry id (from database backend)
39          */
40         private Long id;
41
42         /**
43          * Item amount
44          */
45         private Long amount;
46
47         /**
48          * Item id number
49          */
50         private Long itemId;
51
52         /**
53          * Item type
54          */
55         private String itemType;
56
57         /**
58          * Item instance
59          */
60         private Product product;
61
62         @Override
63         public int compareTo (final AddableBasketItem item) {
64                 // Trace message
65                 this.getLogger().logTrace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
66                 
67                 // item should not be null
68                 if (null == item) {
69                         throw new NullPointerException("item is null"); //NOI18N
70                 }
71
72                 // Debug message
73                 this.getLogger().logDebug(MessageFormat.format("this.itemId={0},item.itemId={1}", this.getItemId(), item.getItemId())); //NOI18N
74
75                 // Is the id the same?
76                 if (Objects.equals(this.getItemId(), item.getItemId())) {
77                         // Same id, means same item
78                         return 0;
79                 } else if (this.getItemId() > item.getItemId()) {
80                         // This id is larger than compared to
81                         return -1;
82                 }
83
84                 // The other id is larger
85                 return 1;
86         }
87
88         @Override
89         public Long getAmount () {
90                 return this.amount;
91         }
92
93         @Override
94         public void setAmount (final Long amount) {
95                 this.amount = amount;
96         }
97
98         @Override
99         public Long getId () {
100                 return this.id;
101         }
102
103         @Override
104         public void setId (final Long id) {
105                 this.id = id;
106         }
107
108         @Override
109         public Long getItemId () {
110                 return this.itemId;
111         }
112
113         @Override
114         public void setItemId( final Long itemId) {
115                 this.itemId = itemId;
116         }
117
118         @Override
119         public String getItemType () {
120                 return this.itemType;
121         }
122
123         @Override
124         public void setItemType (final String itemType) {
125                 this.itemType = itemType;
126         }
127
128         @Override
129         public Product getProduct () {
130                 return this.product;
131         }
132
133         @Override
134         public void setProduct (final Product product) {
135                 this.product = product;
136         }
137 }