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.
17 package org.wamblee.usermgt;
20 import java.util.TreeSet;
23 * In-memory group set implementation.
25 * @author Erik Brakkee
27 public class InMemoryGroupSet implements GroupSet {
32 private Set<Group> _groups;
35 * Constructs an empty group set.
37 public InMemoryGroupSet() {
38 _groups = new TreeSet<Group>();
42 * @see org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group)
44 public void groupModified(Group aGroup) {
45 _groups.remove(aGroup);
50 * @see org.wamblee.usermgt.GroupSet#find(java.lang.String)
52 public Group find(String aName) {
53 for (Group group: _groups) {
54 if ( group.getName().equals(aName)) {
55 return new Group(group);
62 * @see org.wamblee.usermgt.GroupSet#contains(org.wamblee.usermgt.Group)
64 public boolean contains(Group aGroup) {
65 return _groups.contains(aGroup);
69 * @see org.wamblee.usermgt.GroupSet#add(org.wamblee.usermgt.Group)
71 public boolean add(Group aGroup) {
72 return _groups.add(aGroup);
76 * @see org.wamblee.usermgt.GroupSet#remove(org.wamblee.usermgt.Group)
78 public boolean remove(Group aGroup) {
79 return _groups.remove(aGroup);
83 * @see org.wamblee.usermgt.GroupSet#list()
85 public Set<Group> list() {
86 Set<Group> list = new TreeSet<Group>();
87 for (Group group: _groups) {
88 list.add(new Group(group));
94 * @see org.wamblee.usermgt.GroupSet#size()
97 return _groups.size();