From aa24756877f05fffcc2fedb6a15bb4291b89c320 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 25 Apr 2020 18:21:18 +0200 Subject: [PATCH] Continued: - added utilities method copyCategoryData() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jproduct/model/category/Categories.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/org/mxchange/jproduct/model/category/Categories.java b/src/org/mxchange/jproduct/model/category/Categories.java index 1eb1f63..272c846 100644 --- a/src/org/mxchange/jproduct/model/category/Categories.java +++ b/src/org/mxchange/jproduct/model/category/Categories.java @@ -57,6 +57,33 @@ public class Categories implements Serializable { return category1.compareTo(category2); } + /** + * Copies all data from source category to target category + *

+ * @param sourceCategory Source category instance + * @param targetCategory Target category instance + */ + public static void copyCategoryData (final Category sourceCategory, final Category targetCategory) { + // Category should be valid + if (null == sourceCategory) { + // Throw NPE + throw new NullPointerException("sourceCategory is null"); //NOI18N + } else if (null == targetCategory) { + // Throw NPE + throw new NullPointerException("targetCategory is null"); //NOI18N + } else if (Objects.equals(sourceCategory, targetCategory)) { + // Is exactly the same! + throw new IllegalArgumentException("sourcerCategory and targetCategory are the same."); //NOI18N + } + + // Copy all: + targetCategory.setCategoryEntryCreated(sourceCategory.getCategoryEntryCreated()); + targetCategory.setCategoryEntryUpdated(sourceCategory.getCategoryEntryUpdated()); + targetCategory.setCategoryI18nKey(sourceCategory.getCategoryI18nKey()); + targetCategory.setCategoryId(sourceCategory.getCategoryId()); + targetCategory.setCategoryShownInStatistics(sourceCategory.getCategoryShownInStatistics()); + } + /** * Utility classes should have no instances */ -- 2.39.5