]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jshopcore/model/category/BaseCategory.java
Updated jcoreee.jar
[jproduct-core.git] / src / org / mxchange / jshopcore / model / category / BaseCategory.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.category;
18
19 import java.util.Objects;
20
21 /**
22  * A general product category class
23  *
24  * @author Roland Haeder
25  */
26 public abstract class BaseCategory implements Category, Comparable<Category> {
27         /**
28          * Serial number
29          */
30         private static final long serialVersionUID = 38_472_937_685_901L;
31
32         /**
33          * Id number of category
34          */
35         private Long categoryId;
36
37         /**
38          * Parent category categoryId
39          */
40         private Long parentId;
41
42         /**
43          * Title of category
44          */
45         private String title;
46
47         /**
48          * Constructor which accepts all database fields
49          *
50          * @param categoryId Id number of database record
51          * @param title Category title
52          * @param parentId Parent categoryId
53          */
54         protected BaseCategory (final Long categoryId, final String title, final Long parentId) {
55                 // Set all here
56                 this.categoryId = categoryId;
57                 this.title = title;
58                 this.parentId = parentId;
59         }
60
61         /**
62          * Default constructor
63          */
64         protected BaseCategory () {
65         }
66
67         /**
68          * Compares two categories with each other
69          *
70          * @param category Category comparator
71          * @return Comparison value
72          */
73         @Override
74         public int compareTo (final Category category) {
75                 // category should not be null
76                 if (null == category) {
77                         throw new NullPointerException("category is null"); //NOI18N
78                 }
79
80                 // Is the categoryId the same?
81                 if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
82                         // Same categoryId, means same category
83                         return 0;
84                 } else if (this.getCategoryId() > category.getCategoryId()) {
85                         // This categoryId is larger than compared to
86                         return -1;
87                 }
88
89                 // The other categoryId is larger
90                 return 1;
91         }
92
93         /**
94          * Id number of category
95          *
96          * @return the categoryId
97          */
98         @Override
99         public Long getCategoryId () {
100                 return this.categoryId;
101         }
102
103         /**
104          * Id number of category
105          *
106          * @param categoryId the categoryId to set
107          */
108         @Override
109         public void setCategoryId (final Long categoryId) {
110                 this.categoryId = categoryId;
111         }
112
113         /**
114          * Parent category categoryId
115          *
116          * @return the parentId
117          */
118         @Override
119         public Long getParentId () {
120                 return this.parentId;
121         }
122
123         /**
124          * Parent category categoryId
125          *
126          * @param parentId the parentId to set
127          */
128         @Override
129         public void setParentId (final Long parentId) {
130                 this.parentId = parentId;
131         }
132
133         /**
134          * Title of category
135          *
136          * @return the title
137          */
138         @Override
139         public String getTitle () {
140                 return this.title;
141         }
142
143         /**
144          * Title of category
145          *
146          * @param title the title to set
147          */
148         @Override
149         public void setTitle (final String title) {
150                 this.title = title;
151         }
152 }