From: Roland Haeder Date: Thu, 15 Oct 2015 12:03:49 +0000 (+0200) Subject: Only a set is needed, if only found users are added. this way, the EJB gets more... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=29b38b325196603a8e65d702c92aff31d1eb1e9e;p=jbonuscard-lib.git Only a set is needed, if only found users are added. this way, the EJB gets more calls on invalid numbers, but else the Map would be flooded with junk entries. Again blue or red pill ... 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 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()); } }