2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jshopcore.model.category;
19 import java.util.Objects;
22 * A general product category class
24 * @author Roland Haeder<roland@mxchange.org>
26 public abstract class BaseCategory implements Category, Comparable<Category> {
30 private static final long serialVersionUID = 38_472_937_685_901L;
33 * Id number of category
35 private Long categoryId;
38 * Parent category categoryId
40 private Long parentId;
48 * Constructor which accepts all database fields
50 * @param categoryId Id number of database record
51 * @param title Category title
52 * @param parentId Parent categoryId
54 protected BaseCategory (final Long categoryId, final String title, final Long parentId) {
56 this.categoryId = categoryId;
58 this.parentId = parentId;
64 protected BaseCategory () {
68 * Compares two categories with each other
70 * @param category Category comparator
71 * @return Comparison value
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
80 // Is the categoryId the same?
81 if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
82 // Same categoryId, means same category
84 } else if (this.getCategoryId() > category.getCategoryId()) {
85 // This categoryId is larger than compared to
89 // The other categoryId is larger
94 * Id number of category
96 * @return the categoryId
99 public Long getCategoryId () {
100 return this.categoryId;
104 * Id number of category
106 * @param categoryId the categoryId to set
109 public void setCategoryId (final Long categoryId) {
110 this.categoryId = categoryId;
114 * Parent category categoryId
116 * @return the parentId
119 public Long getParentId () {
120 return this.parentId;
124 * Parent category categoryId
126 * @param parentId the parentId to set
129 public void setParentId (final Long parentId) {
130 this.parentId = parentId;
139 public String getTitle () {
146 * @param title the title to set
149 public void setTitle (final String title) {