]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jshopcore/model/product/BaseProduct.java
Continued:
[jproduct-core.git] / src / org / mxchange / jshopcore / model / 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.jshopcore.model.product;
7
8 import java.text.MessageFormat;
9 import java.util.Objects;
10 import org.mxchange.jcoreee.BaseEeSystem;
11
12 /**
13  * A general product class
14  *
15  * @author Roland Haeder
16  */
17 public abstract class BaseProduct extends BaseEeSystem implements Product, Comparable<Product> {
18         /**
19          * Serial number
20          */
21         private static final long serialVersionUID = 48_379_575_267_451L;
22
23         /**
24          * Availability of product
25          */
26         private Boolean available;
27
28         /**
29          * Product category
30          */
31         private Long categoryId;
32
33         /**
34          * Id number of product item
35          */
36         private Long itemId;
37
38         /**
39          * Price of product
40          */
41         private Float price;
42
43         /**
44          * Title of product
45          */
46         private String title;
47
48         @Override
49         public int compareTo (final Product product) {
50                 // Trace message
51                 this.getLogger().logTrace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
52                 
53                 // category should not be null
54                 if (null == product) {
55                         throw new NullPointerException("product is null"); //NOI18N
56                 }
57                 
58                 // Debug message
59                 this.getLogger().logDebug(MessageFormat.format("this.id={0},product.id={1}", this.getItemId(), product.getItemId())); //NOI18N
60                 
61                 // Is the id the same?
62                 if (Objects.equals(this.getItemId(), product.getItemId())) {
63                         // Same id, means same category
64                         return 0;
65                 } else if (this.getItemId() > product.getItemId()) {
66                         // This id is larger than compared to
67                         return 1;
68                 }
69                 
70                 // The other id is larger
71                 return -1;
72         }
73
74         @Override
75         public Boolean getAvailable () {
76                 return this.available;
77         }
78
79         @Override
80         public void setAvailable (final Boolean available) {
81                 this.available = available;
82         }
83
84         @Override
85         public Long getCategoryId () {
86                 return this.categoryId;
87         }
88
89         @Override
90         public void setCategoryId (final Long categoryId) {
91                 this.categoryId = categoryId;
92         }
93
94         @Override
95         public Long getItemId () {
96                 return this.itemId;
97         }
98
99         @Override
100         public void setItemId (final Long itemId) {
101                 this.itemId = itemId;
102         }
103
104         @Override
105         public Float getPrice () {
106                 return this.price;
107         }
108
109         @Override
110         public void setPrice (final Float price) {
111                 this.price = price;
112         }
113
114         @Override
115         public String getTitle () {
116                 return this.title;
117         }
118
119         @Override
120         public void setTitle (final String title) {
121                 this.title = title;
122         }
123 }