From: Roland Haeder Date: Thu, 15 Oct 2015 11:56:03 +0000 (+0200) Subject: use static, then it will remain there X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7376e919b83a467742eebb50c63deac6643cb28d;p=addressbook-lib.git use static, then it will remain there Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java index ddd1ef7..17f76a7 100644 --- a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java +++ b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java @@ -54,15 +54,7 @@ public class UserIdValidator extends BaseLongValidator implements Validator { /** * Cached user status */ - private final ConcurrentMap cachedStatus; - - /** - * Default constructor - */ - public UserIdValidator () { - // Init map - this.cachedStatus = new ConcurrentHashMap<>(0); - } + private static final ConcurrentMap cachedStatus = new ConcurrentHashMap<>(0); @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { @@ -82,15 +74,15 @@ public class UserIdValidator extends BaseLongValidator implements Validator { Boolean ifUserExists = false; // Is a map entry there? - if (this.cachedStatus.containsKey(userId)) { + if (UserIdValidator.cachedStatus.containsKey(userId)) { // Get from cache - ifUserExists = this.cachedStatus.get(userId); + ifUserExists = UserIdValidator.cachedStatus.get(userId); } else { // Get status ifUserExists = this.userBean.ifUserIdExists(userId); // Add to cache - this.cachedStatus.put(userId, ifUserExists); + UserIdValidator.cachedStatus.put(userId, ifUserExists); } // Is the address book id valid? @@ -128,6 +120,6 @@ public class UserIdValidator extends BaseLongValidator implements Validator { User registeredUser = event.getUser(); // Update cache - this.cachedStatus.put(registeredUser.getUserId(), Boolean.TRUE); + UserIdValidator.cachedStatus.put(registeredUser.getUserId(), Boolean.TRUE); } }