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