2 * Copyright 2005 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.usermgt;
19 import java.util.TreeSet;
23 * In-memory group set implementation.
25 * @author Erik Brakkee
27 public class InMemoryGroupSet implements GroupSet {
31 private Set<Group> groups;
34 * Constructs an empty group set.
36 public InMemoryGroupSet() {
37 groups = new TreeSet<Group>();
41 * @see org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group)
46 * @param aGroup DOCUMENT ME!
48 public void groupModified(Group aGroup) {
49 groups.remove(aGroup);
54 * @see org.wamblee.usermgt.GroupSet#find(java.lang.String)
59 * @param aName DOCUMENT ME!
61 * @return DOCUMENT ME!
63 public Group find(String aName) {
64 for (Group group : groups) {
65 if (group.getName().equals(aName)) {
66 return new Group(group);
74 * @see org.wamblee.usermgt.GroupSet#contains(org.wamblee.usermgt.Group)
79 * @param aGroup DOCUMENT ME!
81 * @return DOCUMENT ME!
83 public boolean contains(Group aGroup) {
84 return groups.contains(aGroup);
88 * @see org.wamblee.usermgt.GroupSet#add(org.wamblee.usermgt.Group)
93 * @param aGroup DOCUMENT ME!
95 * @return DOCUMENT ME!
97 public boolean add(Group aGroup) {
98 return groups.add(aGroup);
102 * @see org.wamblee.usermgt.GroupSet#remove(org.wamblee.usermgt.Group)
107 * @param aGroup DOCUMENT ME!
109 * @return DOCUMENT ME!
111 public boolean remove(Group aGroup) {
112 return groups.remove(aGroup);
116 * @see org.wamblee.usermgt.GroupSet#list()
121 * @return DOCUMENT ME!
123 public Set<Group> list() {
124 Set<Group> list = new TreeSet<Group>();
126 for (Group group : groups) {
127 list.add(new Group(group));
134 * @see org.wamblee.usermgt.GroupSet#size()
139 * @return DOCUMENT ME!
142 return groups.size();