]> git.mxchange.org Git - jbonuscard-lib.git/commitdiff
Only a set is needed, if only found users are added. this way, the EJB gets more...
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 12:03:49 +0000 (14:03 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 12:03:49 +0000 (14:03 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/addressbook/validator/user/UserIdValidator.java

index 17f76a7e809bfba5ee67f6984ce2bd594846b405..943c0b34d55a717084102bce56823fd12e429a10 100644 (file)
@@ -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<Long, Boolean> cachedStatus = new ConcurrentHashMap<>(0);
+       private static final Set<Long> 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());
        }
 }