From 407ca888cedd6476fef3be0f8220430b15230106 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Tue, 12 May 2020 05:58:08 +0200
Subject: [PATCH] Please cherry-pick: - cache can be updated from the
 uniqueAddFoo() method
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder <roland@mxchange.org>
---
 .../list/JobsBranchOfficeListWebViewBean.java         |  9 +++++----
 .../list/JobsDepartmentListWebViewBean.java           | 11 +++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/java/org/mxchange/jjobs/beans/business/branchoffice/list/JobsBranchOfficeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/business/branchoffice/list/JobsBranchOfficeListWebViewBean.java
index 543474ce..cb4fd04a 100644
--- a/src/java/org/mxchange/jjobs/beans/business/branchoffice/list/JobsBranchOfficeListWebViewBean.java
+++ b/src/java/org/mxchange/jjobs/beans/business/branchoffice/list/JobsBranchOfficeListWebViewBean.java
@@ -112,8 +112,7 @@ public class JobsBranchOfficeListWebViewBean extends BaseJobsBean implements Job
 			throw new IllegalArgumentException(MessageFormat.format("event.addedBranchOffice .branchId={0} is not valid", event.getAddedBranchOffice().getBranchId())); //NOI18N
 		}
 
-		// Add instance to cache
-		this.branchOfficeCache.put(event.getAddedBranchOffice().getBranchId(), event.getAddedBranchOffice());
+		// Uniquely add branch office
 		this.uniqueAddBranchOffice(event.getAddedBranchOffice());
 	}
 
@@ -139,8 +138,7 @@ public class JobsBranchOfficeListWebViewBean extends BaseJobsBean implements Job
 			throw new IllegalArgumentException(MessageFormat.format("event.updatedBranchOffice .branchId={0} is not valid", event.getUpdatedBranchOffice().getBranchId())); //NOI18N
 		}
 
-		// Add instance to cache
-		this.branchOfficeCache.put(event.getUpdatedBranchOffice().getBranchId(), event.getUpdatedBranchOffice());
+		// Uniquely update branch office
 		this.uniqueAddBranchOffice(event.getUpdatedBranchOffice());
 	}
 
@@ -275,6 +273,9 @@ public class JobsBranchOfficeListWebViewBean extends BaseJobsBean implements Job
 	 * @param branchOffice Branch office being added
 	 */
 	private void uniqueAddBranchOffice (final BranchOffice branchOffice) {
+		// Add instance to cache
+		this.branchOfficeCache.put(branchOffice.getBranchId(), branchOffice);
+
 		// Get iterator
 		final Iterator<BranchOffice> iterator = this.getAllBranchOffices().iterator();
 
diff --git a/src/java/org/mxchange/jjobs/beans/business/department/list/JobsDepartmentListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/business/department/list/JobsDepartmentListWebViewBean.java
index 5c7dc8f6..116e672f 100644
--- a/src/java/org/mxchange/jjobs/beans/business/department/list/JobsDepartmentListWebViewBean.java
+++ b/src/java/org/mxchange/jjobs/beans/business/department/list/JobsDepartmentListWebViewBean.java
@@ -113,8 +113,7 @@ public class JobsDepartmentListWebViewBean extends BaseJobsBean implements JobsD
 			throw new IllegalArgumentException(MessageFormat.format("event.addedDepartment.branchId={0} is not valid", event.getAddedDepartment().getDepartmentId())); //NOI18N
 		}
 
-		// Add instance to cache
-		this.departmentCache.put(event.getAddedDepartment().getDepartmentId(), event.getAddedDepartment());
+		// Uniquely add department
 		this.uniqueAddDepartment(event.getAddedDepartment());
 	}
 
@@ -140,9 +139,6 @@ public class JobsDepartmentListWebViewBean extends BaseJobsBean implements JobsD
 			throw new IllegalArgumentException(MessageFormat.format("event.updatedDepartment.branchId={0} is not valid", event.getUpdatedDepartment().getDepartmentId())); //NOI18N
 		}
 
-		// Add instance to cache
-		this.departmentCache.put(event.getUpdatedDepartment().getDepartmentId(), event.getUpdatedDepartment());
-
 		// Uniquely add (update) instance
 		this.uniqueAddDepartment(event.getUpdatedDepartment());
 	}
@@ -268,11 +264,14 @@ public class JobsDepartmentListWebViewBean extends BaseJobsBean implements JobsD
 	}
 
 	/**
-	 * Uniquely adds given department instance to full list
+	 * Uniquely adds given department instance to full list and updates cache.
 	 * <p>
 	 * @param department Department being uniquely added
 	 */
 	private void uniqueAddDepartment (final Department department) {
+		// Add instance to cache
+		this.departmentCache.put(department.getDepartmentId(), department);
+
 		// Get iterator
 		final Iterator<Department> iterator = this.getAllDepartments().iterator();
 
-- 
2.39.5