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