+libs.commons-lang3.classpath=\
+ ${base}/commons-lang3/commons-lang3-3.7.jar
+libs.commons-lang3.displayName=Commons Lang3 3.7
+libs.commons-lang3.javadoc=\
+ https://commons.apache.org/proper/commons-lang/javadocs/api-release/
libs.CopyLibs.classpath=\
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
endorsed.classpath=
excludes=
file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar
+file.reference.jcore-utils.jar=lib/jcore-utils.jar
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${file.reference.jcontacts-business-core.jar}:\
+ ${file.reference.jcore-utils.jar}:\
+ ${libs.commons-lang3.classpath}:\
${libs.javaee-api-7.0.classpath}
# Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
${build.test.classes.dir}
source.encoding=UTF-8
source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/
+source.reference.jcore-utils.jar=../jcore-utils/src/
src.dir=src
test.src.dir=test
--- /dev/null
+/*
+ * Copyright (C) 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.category;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * An utilities class for product categories
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Categories implements Serializable {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 157_687_661_634_901L;
+
+ /**
+ * Compares both Category instances. This method returns -1 if second
+ * instance is null.
+ * <p>
+ * @param category1 Category instance 1
+ * @param category2 Category instance 2
+ * <p>
+ * @return Comparison value
+ */
+ public static int compare (final Category category1, final Category category2) {
+ // Check euqality, then at least first must be given
+ if (Objects.equals(category1, category2)) {
+ // Both are same
+ return 0;
+ } else if (null == category1) {
+ // First is null
+ return -1;
+ } else if (null == category2) {
+ // Second is null
+ return 1;
+ }
+
+ // Invoke compareTo() method
+ return category1.compareTo(category2);
+ }
+
+ /**
+ * Utility classes should have no instances
+ */
+ private Categories () {
+ // Private constructor
+ }
+
+}
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Category extends Serializable {
+public interface Category extends Comparable<Category>, Serializable {
/**
* Getter for created timestamp
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.mxchange.jcoreutils.Comparables;
/**
* A product category
public ProductCategory () {
}
+ @Override
+ public int compareTo (final Category category) {
+ // Check parameter on null-reference and equality to this
+ if (null == category) {
+ // Should not happen
+ throw new NullPointerException("category is null"); //NOI18N
+ } else if (category.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparators
+ final int comparators[] = {
+ // First check parent category
+ Categories.compare(this.getParentCategory(), category.getParentCategory()),
+ // ... last is i18n key as it is unique
+ this.getCategoryI18nKey().compareTo(category.getCategoryI18nKey())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
@Override
public boolean equals (final Object object) {
if (this == object) {
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.commons.lang3.StringUtils;
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicDataUtils;
import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jcoreutils.SafeNumberUtils;
+import org.mxchange.jproduct.model.category.Categories;
import org.mxchange.jproduct.model.category.Category;
import org.mxchange.jproduct.model.category.ProductCategory;
import org.mxchange.jproduct.model.product.agegroup.AgeGroup;
* @throws IllegalArgumentException If a parameter is empty (string) or out
* of bounds
*/
- public GenericProduct (final String productI18nKey, final BigDecimal productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability, final BigDecimal productUnitAmount , final String productUnitI18nKey) {
+ public GenericProduct (final String productI18nKey, final BigDecimal productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability, final BigDecimal productUnitAmount, final String productUnitI18nKey) {
// Call other constructor first
this();
this.productUnitI18nKey = productUnitI18nKey;
}
+ @Override
+ public int compareTo (final Product product) {
+ // Check parameter on null-reference and equality to this
+ if (null == product) {
+ // Should not happen
+ throw new NullPointerException("product is null"); //NOI18N
+ } else if (product.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparators
+ final int comparators[] = {
+ // First check product number
+ SafeNumberUtils.compare(this.getProductNumber(), product.getProductNumber()),
+ // ... size
+ StringUtils.compare(this.getProductSize(), product.getProductSize()),
+ // ... then i18n key
+ this.getProductI18nKey().compareTo(product.getProductI18nKey()),
+ // ... gross price
+ this.getProductGrossPrice().compareTo(product.getProductGrossPrice()),
+ // ... net price
+ SafeNumberUtils.compare(this.getProductNetPrice(), product.getProductNetPrice()),
+ // ... tax rate
+ SafeNumberUtils.compare(this.getProductTaxRate(), product.getProductTaxRate()),
+ // ... unit amount
+ this.getProductUnitAmount().compareTo(product.getProductUnitAmount()),
+ // ... currency code
+ this.getProductCurrencyCode().compareTo(product.getProductCurrencyCode()),
+ // ... manufacturer
+ BasicDataUtils.compare(this.getProductManufacturer(), product.getProductManufacturer()),
+ // ... category
+ Categories.compare(this.getProductCategory(), product.getProductCategory())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
@Override
public boolean equals (final Object object) {
if (this == object) {
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Product extends Serializable {
+public interface Product extends Comparable<Product>, Serializable {
/**
* Getter for created timestamp
--- /dev/null
+/*
+ * Copyright (C) 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.product;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * An utilities class for generic products
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Products implements Serializable {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 157_687_661_634_902L;
+
+ /**
+ * Compares both Product instances. This method returns -1 if second
+ * instance is null.
+ * <p>
+ * @param product1 Product instance 1
+ * @param product2 Product instance 2
+ * <p>
+ * @return Comparison value
+ */
+ public static int compare (final Product product1, final Product product2) {
+ // Check euqality, then at least first must be given
+ if (Objects.equals(product1, product2)) {
+ // Both are same
+ return 0;
+ } else if (null == product1) {
+ // First is null
+ return -1;
+ } else if (null == product2) {
+ // Second is null
+ return 1;
+ }
+
+ // Invoke compareTo() method
+ return product1.compareTo(product2);
+ }
+
+ /**
+ * Utility classes should have no instances
+ */
+ private Products () {
+ // Private constructor
+ }
+
+}