From: Roland Häder Date: Sat, 25 Apr 2020 16:21:18 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=aa24756877f05fffcc2fedb6a15bb4291b89c320;p=jproduct-core.git Continued: - added utilities method copyCategoryData() Signed-off-by: Roland Häder --- 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 */