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