2 * Copyright 2005-2010 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;
22 * In-memory group set implementation.
24 * @author Erik Brakkee
26 public class InMemoryGroupSet implements GroupSet {
30 private Set<Group> groups;
33 * Constructs an empty group set.
35 public InMemoryGroupSet() {
36 groups = new TreeSet<Group>();
43 * org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group)
45 public void groupModified(Group aGroup) {
46 groups.remove(aGroup);
53 * @see org.wamblee.usermgt.GroupSet#find(java.lang.String)
55 public Group find(String aName) {
56 for (Group group : groups) {
57 if (group.getName().equals(aName)) {
58 return new Group(group);
68 * @see org.wamblee.usermgt.GroupSet#contains(org.wamblee.usermgt.Group)
70 public boolean contains(Group aGroup) {
71 return groups.contains(aGroup);
77 * @see org.wamblee.usermgt.GroupSet#add(org.wamblee.usermgt.Group)
79 public boolean add(Group aGroup) {
80 return groups.add(aGroup);
86 * @see org.wamblee.usermgt.GroupSet#remove(org.wamblee.usermgt.Group)
88 public boolean remove(Group aGroup) {
89 return groups.remove(aGroup);
95 * @see org.wamblee.usermgt.GroupSet#list()
97 public Set<Group> list() {
98 Set<Group> list = new TreeSet<Group>();
100 for (Group group : groups) {
101 list.add(new Group(group));
110 * @see org.wamblee.usermgt.GroupSet#size()
113 return groups.size();