source code formatting.
[utils] / security / src / main / java / org / wamblee / usermgt / InMemoryGroupSet.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 java.util.Set;
19 import java.util.TreeSet;
20
21
22 /**
23  * In-memory group set implementation.
24  *
25  * @author Erik Brakkee
26  */
27 public class InMemoryGroupSet implements GroupSet {
28     /**
29      * Groups.
30      */
31     private Set<Group> groups;
32
33 /**
34      * Constructs an empty group set. 
35      */
36     public InMemoryGroupSet() {
37         groups = new TreeSet<Group>();
38     }
39
40     /* (non-Javadoc)
41      * @see org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group)
42      */
43     /**
44      * DOCUMENT ME!
45      *
46      * @param aGroup DOCUMENT ME!
47      */
48     public void groupModified(Group aGroup) {
49         groups.remove(aGroup);
50         groups.add(aGroup);
51     }
52
53     /* (non-Javadoc)
54      * @see org.wamblee.usermgt.GroupSet#find(java.lang.String)
55      */
56     /**
57      * DOCUMENT ME!
58      *
59      * @param aName DOCUMENT ME!
60      *
61      * @return DOCUMENT ME!
62      */
63     public Group find(String aName) {
64         for (Group group : groups) {
65             if (group.getName().equals(aName)) {
66                 return new Group(group);
67             }
68         }
69
70         return null;
71     }
72
73     /* (non-Javadoc)
74      * @see org.wamblee.usermgt.GroupSet#contains(org.wamblee.usermgt.Group)
75      */
76     /**
77      * DOCUMENT ME!
78      *
79      * @param aGroup DOCUMENT ME!
80      *
81      * @return DOCUMENT ME!
82      */
83     public boolean contains(Group aGroup) {
84         return groups.contains(aGroup);
85     }
86
87     /* (non-Javadoc)
88      * @see org.wamblee.usermgt.GroupSet#add(org.wamblee.usermgt.Group)
89      */
90     /**
91      * DOCUMENT ME!
92      *
93      * @param aGroup DOCUMENT ME!
94      *
95      * @return DOCUMENT ME!
96      */
97     public boolean add(Group aGroup) {
98         return groups.add(aGroup);
99     }
100
101     /* (non-Javadoc)
102      * @see org.wamblee.usermgt.GroupSet#remove(org.wamblee.usermgt.Group)
103      */
104     /**
105      * DOCUMENT ME!
106      *
107      * @param aGroup DOCUMENT ME!
108      *
109      * @return DOCUMENT ME!
110      */
111     public boolean remove(Group aGroup) {
112         return groups.remove(aGroup);
113     }
114
115     /* (non-Javadoc)
116      * @see org.wamblee.usermgt.GroupSet#list()
117      */
118     /**
119      * DOCUMENT ME!
120      *
121      * @return DOCUMENT ME!
122      */
123     public Set<Group> list() {
124         Set<Group> list = new TreeSet<Group>();
125
126         for (Group group : groups) {
127             list.add(new Group(group));
128         }
129
130         return list;
131     }
132
133     /* (non-Javadoc)
134      * @see org.wamblee.usermgt.GroupSet#size()
135      */
136     /**
137      * DOCUMENT ME!
138      *
139      * @return DOCUMENT ME!
140      */
141     public int size() {
142         return groups.size();
143     }
144 }