From 29b38b325196603a8e65d702c92aff31d1eb1e9e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 15 Oct 2015 14:03:49 +0200 Subject: [PATCH] =?utf8?q?Only=20a=20set=20is=20needed,=20if=20only=20foun?= =?utf8?q?d=20users=20are=20added.=20this=20way,=20the=20EJB=20gets=20more?= =?utf8?q?=20calls=20on=20invalid=20numbers,=20but=20else=20the=20Map=20wo?= =?utf8?q?uld=20be=20flooded=20with=20junk=20entries.=20Again=20blue=20or?= =?utf8?q?=20red=20pill=20...=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../validator/user/UserIdValidator.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java index 17f76a7..943c0b3 100644 --- a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java +++ b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java @@ -17,8 +17,8 @@ package org.mxchange.addressbook.validator.user; import java.text.MessageFormat; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +import java.util.Set; +import java.util.TreeSet; import javax.ejb.EJB; import javax.enterprise.event.Observes; import javax.faces.application.FacesMessage; @@ -54,7 +54,7 @@ public class UserIdValidator extends BaseLongValidator implements Validator { /** * Cached user status */ - private static final ConcurrentMap cachedStatus = new ConcurrentHashMap<>(0); + private static final Set cachedStatus = new TreeSet<>(); @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { @@ -74,23 +74,23 @@ public class UserIdValidator extends BaseLongValidator implements Validator { Boolean ifUserExists = false; // Is a map entry there? - if (UserIdValidator.cachedStatus.containsKey(userId)) { + if (UserIdValidator.cachedStatus.contains(userId)) { // Get from cache - ifUserExists = UserIdValidator.cachedStatus.get(userId); + ifUserExists = Boolean.TRUE; } else { // Get status ifUserExists = this.userBean.ifUserIdExists(userId); - - // Add to cache - UserIdValidator.cachedStatus.put(userId, ifUserExists); } - // Is the address book id valid? + // Is the user id valid? if (!ifUserExists) { // Is not valid throw new ValidatorException(new FacesMessage(MessageFormat.format("No user found with id {0}. Please check your link.", userId))); //NOI18N } + // Add to cache if valid + UserIdValidator.cachedStatus.add(userId); + // Trace message //this.getLogger().logTrace("validate: EXIT!"); //NOI18N } @@ -120,6 +120,6 @@ public class UserIdValidator extends BaseLongValidator implements Validator { User registeredUser = event.getUser(); // Update cache - UserIdValidator.cachedStatus.put(registeredUser.getUserId(), Boolean.TRUE); + UserIdValidator.cachedStatus.add(registeredUser.getUserId()); } } -- 2.39.5