]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jshopcore/model/basket/BaseBasket.java
Continued:
[jcustomer-core.git] / src / org / mxchange / jshopcore / model / basket / BaseBasket.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.basket;
18
19 import java.text.MessageFormat;
20 import java.util.Map;
21 import javax.ejb.EJB;
22 import org.mxchange.jcoreeelogger.beans.local.logger.Log;
23 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
24
25 /**
26  * A general basket class
27  *
28  * @author Roland Haeder
29  * @param <T> Any instance that implements AddableBasketItem
30  */
31 public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<T> {
32         /**
33          * Serial number
34          */
35         private static final long serialVersionUID = 782_396_762_230_845_717L;
36
37         /**
38          * Logger instance
39          */
40         @EJB
41         @Log
42         private LoggerBeanLocal logger;
43
44         /**
45          * Protected constructor with session instance
46          */
47         protected BaseBasket () {
48                 // Trace message
49                 this.getLogger().logTrace("CALLED!"); //NOI18N
50         }
51
52         @Override
53         public void init () {
54                 // Trace message
55                 this.getLogger().logTrace("CALLED!"); //NOI18N
56         }
57
58         @Override
59         @SuppressWarnings ("unchecked")
60         public void addItem (final T item) {
61                 // Trace call
62                 this.getLogger().logTrace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
63
64                 // item must not be null
65                 if (null == item) {
66                         // Then abort here
67                         throw new NullPointerException("item is null"); //NOI18N
68                 } else if (this.isAdded(item)) {
69                         // Already been added
70                         throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N
71                 }
72
73                 // Add item to database
74                 // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId());
75
76                 // Trace call
77                 this.getLogger().logTrace("EXIT!"); //NOI18N
78         }
79
80         @Override
81         public boolean isEmpty () {
82                 // Deligate call to frontend
83                 // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty();
84                 throw new UnsupportedOperationException("Not yet implmeneted.");
85         }
86
87         @Override
88         @SuppressWarnings("unchecked")
89         public Map<Long, T> getAll () {
90                 // Trace message
91                 this.getLogger().logTrace("CALLED!"); //NOI18N
92
93                 // Init map
94                 // TODO: Map<Long, T> map = ((BasketFrontend) this.getFrontend()).getAll();
95                 Map<Long, T> map = null;
96
97                 // Trace message
98                 this.getLogger().logTrace("map=" + map); //NOI18N
99
100                 // Return it
101                 return map;
102         }
103
104         @Override
105         public AddableBasketItem getLast () {
106                 // Deligate to frontend
107                 // TODO: return ((BasketFrontend) this.getFrontend()).getLast();
108                 throw new UnsupportedOperationException("Not yet implmeneted.");
109         }
110
111         @Override
112         public int getLastNumRows () {
113                 // Deligate to frontend
114                 // TODO: return this.getFrontend().getLastNumRows();
115                 throw new UnsupportedOperationException("Not yet implmeneted.");
116         }
117
118         @Override
119         public boolean isAdded (final T item) {
120                 // Trace call
121                 this.getLogger().logTrace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
122
123                 // item must not be null
124                 if (null == item) {
125                         // Then abort here
126                         throw new NullPointerException("item is null"); //NOI18N
127                 }
128
129                 // Call map's method
130                 // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId());
131                 boolean isAdded = true;
132
133                 // Trace message
134                 this.getLogger().logTrace(MessageFormat.format("isAdded={0} - EXIT!", isAdded)); //NOI18N
135
136                 // Return it
137                 return isAdded;
138         }
139
140         /**
141          * Getter for logger
142          *
143          * @return Logger instance
144          */
145         private LoggerBeanLocal getLogger () {
146                 return this.logger;
147         }
148 }