From 718e3d3a53da783918ed440916b13149bfbb984c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 5 Nov 2022 08:07:03 +0100 Subject: [PATCH] Continued: - also compare primary keys --- .../mxchange/jproduct/model/category/ProductCategory.java | 8 +++++--- .../mxchange/jproduct/model/product/GenericProduct.java | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/mxchange/jproduct/model/category/ProductCategory.java b/src/org/mxchange/jproduct/model/category/ProductCategory.java index 418b6ec..643aeb3 100644 --- a/src/org/mxchange/jproduct/model/category/ProductCategory.java +++ b/src/org/mxchange/jproduct/model/category/ProductCategory.java @@ -151,8 +151,10 @@ public class ProductCategory implements Category { final int comparators[] = { // First check parent category CategoryUtils.compare(this.getParentCategory(), category.getParentCategory()), - // ... last is i18n key as it is unique - StringUtils.compare(this.getCategoryI18nKey(), category.getCategoryI18nKey()) + // ... i18n key as it is unique + StringUtils.compare(this.getCategoryI18nKey(), category.getCategoryI18nKey()), + // ... primary key + Long.compare(this.getCategoryId(), category.getCategoryId()) }; // Check all values @@ -256,9 +258,9 @@ public class ProductCategory implements Category { int hash = 7; hash = 13 * hash + Objects.hashCode(this.getCategoryI18nKey()); - hash = 13 * hash + Objects.hashCode(this.getCategoryId()); hash = 13 * hash + Objects.hashCode(this.getCategoryShownInStatistics()); hash = 13 * hash + Objects.hashCode(this.getParentCategory()); + hash = 13 * hash + Objects.hashCode(this.getCategoryId()); return hash; } diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index 84a7294..5642d8e 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -294,7 +294,9 @@ public class GenericProduct implements Product { // Init comparators final int comparators[] = { - // First check product number + // First compare id numbers + Long.compare(this.getProductId(), product.getProductId()), + // ... next product number SafeNumberUtils.compare(this.getProductNumber(), product.getProductNumber()), // ... bar-code number StringUtils.compare(this.getProductBarCodeNumber(), product.getProductBarCodeNumber()), -- 2.39.5