]> git.mxchange.org Git - jshop-core.git/blob - src/org/mxchange/jshopcore/model/basket/BaseBasket.java
Updated jcoreee.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.util.Map;
20
21 /**
22  * A general basket class
23  *
24  * @author Roland Haeder
25  * @param <T> Any instance that implements AddableBasketItem
26  */
27 public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<T> {
28         /**
29          * Serial number
30          */
31         private static final long serialVersionUID = 782_396_762_230_845_717L;
32
33         /**
34          * Protected constructor with session instance
35          */
36         protected BaseBasket () {
37         }
38
39         @Override
40         public void init () {
41         }
42
43         @Override
44         public void addItem (final T item) {
45                 // item must not be null
46                 if (null == item) {
47                         // Then abort here
48                         throw new NullPointerException("item is null"); //NOI18N
49                 } else if (this.isAdded(item)) {
50                         // Already been added
51                         throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N
52                 }
53
54                 // Add item to database
55                 // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId());
56         }
57
58         @Override
59         public boolean isEmpty () {
60                 // Deligate call to frontend
61                 // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty();
62                 throw new UnsupportedOperationException("Not yet implmeneted.");
63         }
64
65         @Override
66         public Map<Long, T> getAll () {
67                 // Init map
68                 // TODO: Map<Long, T> map = ((BasketFrontend) this.getFrontend()).getAll();
69                 Map<Long, T> map = null;
70
71                 // Return it
72                 return map;
73         }
74
75         @Override
76         public AddableBasketItem getLast () {
77                 // Deligate to frontend
78                 // TODO: return ((BasketFrontend) this.getFrontend()).getLast();
79                 throw new UnsupportedOperationException("Not yet implmeneted.");
80         }
81
82         @Override
83         public int getLastNumRows () {
84                 // Deligate to frontend
85                 // TODO: return this.getFrontend().getLastNumRows();
86                 throw new UnsupportedOperationException("Not yet implmeneted.");
87         }
88
89         @Override
90         public boolean isAdded (final T item) {
91                 // item must not be null
92                 if (null == item) {
93                         // Then abort here
94                         throw new NullPointerException("item is null"); //NOI18N
95                 }
96
97                 // Call map's method
98                 // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId());
99                 boolean isAdded = true;
100
101                 // Return it
102                 return isAdded;
103         }
104 }