]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/product/BaseProduct.java
Added more thrown exceptions
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / product / BaseProduct.java
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package org.mxchange.pizzaapplication.product;
7
8 import java.lang.reflect.InvocationTargetException;
9 import java.text.MessageFormat;
10 import java.util.Objects;
11 import org.mxchange.jcore.BaseFrameworkSystem;
12
13 /**
14  *
15  * @author quix0r
16  */
17 public class BaseProduct extends BaseFrameworkSystem implements Product {
18         /**
19          * Availability of product
20          */
21         private Boolean available;
22
23         /**
24          * Product category
25          */
26         private Long category;
27
28         /**
29          * Id number of product
30          */
31         private Long id;
32
33         /**
34          * Price of product
35          */
36         private float price;
37
38         /**
39          * Title of product
40          */
41         private String title;
42
43         /**
44          * Getter for product availability
45          *
46          * @return Product availability
47          */
48         @Override
49         public final Boolean getAvailable () {
50                 return this.available;
51         }
52
53         /**
54          * Setter for product availability
55          *
56          * @param available Product availability
57          */
58         @Override
59         public final void setAvailable (final Boolean available) {
60                 this.available = available;
61         }
62
63         /**
64          * Getter for product category
65          *
66          * @return Product category
67          */
68         @Override
69         public final Long getCategory () {
70                 return this.category;
71         }
72
73         /**
74          * Setter for product category
75          *
76          * @param category Product category
77          */
78         @Override
79         public final void setCategory (final Long category) {
80                 this.category = category;
81         }
82
83         /**
84          * Name of product
85          * @return the name
86          */
87         @Override
88         public final Long getId () {
89                 return this.id;
90         }
91
92         /**
93          * Id number of product
94          * @param id the id number to set
95          */
96         @Override
97         public final void setId (final Long id) {
98                 this.id = id;
99         }
100
101         /**
102          * Price of product
103          * @return the price
104          */
105         @Override
106         public final float getPrice () {
107                 return this.price;
108         }
109
110         /**
111          * Price of product
112          * @param price the price to set
113          */
114         @Override
115         public final void setPrice (final float price) {
116                 this.price = price;
117         }
118
119         /**
120          * Title of product
121          * @return the title
122          */
123         @Override
124         public final String getTitle () {
125                 return this.title;
126         }
127
128         /**
129          * Title of product
130          * @param title the title to set
131          */
132         @Override
133         public final void setTitle (final String title) {
134                 this.title = title;
135         }
136
137         /**
138          * Compares two categories with each other
139          *
140          * @param product Product comparator
141          * @return Comparison value
142          */
143         @Override
144         public int compareTo (final Product product) {
145                 // Trace message
146                 this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product));
147                 
148                 // category should not be null
149                 if (product == null) {
150                         throw new NullPointerException("product is null");
151                 }
152
153                 // Debug message
154                 this.getLogger().debug(MessageFormat.format("this.id={0},product.id={1}", this.getId(), product.getId()));
155
156                 // Is the id the same?
157                 if (Objects.equals(this.getId(), product.getId())) {
158                         // Same id, means same category
159                         return 0;
160                 } else if (this.getId() > product.getId()) {
161                         // This id is larger than compared to
162                         return -1;
163                 }
164
165                 // The other id is larger
166                 return 1;
167         }
168
169         @Override
170         public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
171                 // Trace message
172                 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
173
174                 // Call super method
175                 Object value = this.getValueInStoreableFromColumn(this, "BaseProduct", columnName);
176
177                 // Trace message
178                 this.getLogger().trace("value=" + value + " - EXIT!");
179
180                 // Return value
181                 return value;
182         }
183
184         @Override
185         public void setValueFromColumn (final String columnName, final String value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
186                 // Trace message
187                 this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value));
188
189                 // Call super method
190                 this.setValueInStoreableFromColumn(this, "BaseProduct", columnName, value);
191
192                 // Trace message
193                 this.getLogger().trace("EXIT!");
194         }
195 }