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