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