Removed DOCUMENT ME comments that were generated and applied source code
[utils] / security / src / main / java / org / wamblee / usermgt / InMemoryUserSet.java
1 /*
2  * Copyright 2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.usermgt;
17
18 import org.wamblee.security.encryption.MessageDigester;
19
20 import java.util.Set;
21 import java.util.TreeSet;
22
23 /**
24  * In-memory user set.
25  * 
26  * @author Erik Brakkee
27  */
28 public class InMemoryUserSet extends AbstractUserSet {
29     /**
30      * Users. All users in this set have their password validator and encoder
31      * set.
32      */
33     private Set<User> users;
34
35     /**
36      * Constructs an empty user set.
37      */
38     public InMemoryUserSet(NameValidator aPasswordValidator,
39         MessageDigester aPasswordEncoder) {
40         super(aPasswordValidator, aPasswordEncoder);
41         users = new TreeSet<User>();
42     }
43
44     /*
45      * (non-Javadoc)
46      * 
47      * @see org.wamblee.usermgt.UserSet#userModified(org.wamblee.usermgt.User)
48      */
49     public void userModified(User aUser) {
50         users.remove(aUser);
51         setPasswordInfo(aUser);
52         users.add(aUser);
53     }
54
55     /*
56      * (non-Javadoc)
57      * 
58      * @see org.wamblee.usermgt.UserSet#find(java.lang.String)
59      */
60     public User find(String aName) {
61         for (User user : users) {
62             if (user.getName().equals(aName)) {
63                 return new User(user);
64             }
65         }
66
67         return null;
68     }
69
70     /*
71      * (non-Javadoc)
72      * 
73      * @see org.wamblee.usermgt.UserSet#add(org.wamblee.usermgt.User)
74      */
75     public boolean add(User aUser) {
76         setPasswordInfo(aUser);
77
78         return users.add(aUser);
79     }
80
81     /*
82      * (non-Javadoc)
83      * 
84      * @see org.wamblee.usermgt.UserSet#contains(org.wamblee.usermgt.User)
85      */
86     public boolean contains(User aUser) {
87         return users.contains(aUser);
88     }
89
90     /*
91      * (non-Javadoc)
92      * 
93      * @see org.wamblee.usermgt.UserSet#remove(org.wamblee.usermgt.User)
94      */
95     public boolean remove(User aUser) {
96         return users.remove(aUser);
97     }
98
99     /*
100      * (non-Javadoc)
101      * 
102      * @see org.wamblee.usermgt.UserSet#list()
103      */
104     public Set<User> list() {
105         Set<User> list = new TreeSet<User>();
106
107         for (User user : users) {
108             list.add(new User(user));
109         }
110
111         return list;
112     }
113
114     /*
115      * (non-Javadoc)
116      * 
117      * @see org.wamblee.usermgt.UserSet#list(org.wamblee.usermgt.Group)
118      */
119     public Set<User> list(Group aGroup) {
120         Set<User> result = new TreeSet<User>();
121
122         for (User user : users) {
123             if (user.getGroups().contains(aGroup)) {
124                 result.add(new User(user));
125             }
126         }
127
128         return result;
129     }
130
131     /*
132      * (non-Javadoc)
133      * 
134      * @see org.wamblee.usermgt.UserSet#size()
135      */
136     public int size() {
137         return users.size();
138     }
139 }