1 package org.apache.fulcrum.security.util; 2 3 56 57 import java.io.Serializable ; 58 59 import java.util.Collection ; 60 import java.util.Iterator ; 61 import java.util.TreeSet ; 62 63 import org.apache.fulcrum.security.entity.Group; 64 65 76 public class GroupSet implements Serializable 77 { 78 79 private TreeSet set; 80 81 84 public GroupSet() 85 { 86 set = new TreeSet (); 87 } 88 89 97 public GroupSet(Collection groups) 98 { 99 this(); 100 add(groups); 101 } 102 103 110 public boolean add(Group group) 111 { 112 return set.add((Object ) group); 113 } 114 115 124 public boolean add(Collection groups) 125 { 126 return set.addAll(groups); 127 } 128 129 137 public boolean add(GroupSet groupSet) 138 { 139 return set.addAll(groupSet.set); 140 } 141 142 149 public boolean remove(Group group) 150 { 151 return set.remove((Object ) group); 152 } 153 154 157 public void clear() 158 { 159 set.clear(); 160 } 161 162 169 public boolean contains(Group group) 170 { 171 return set.contains((Object ) group); 172 } 173 174 182 public boolean contains(String groupName) 183 { 184 Iterator iter = set.iterator(); 185 while (iter.hasNext()) 186 { 187 Group group = (Group) iter.next(); 188 if (groupName != null && 189 groupName.equals(group.getName())) 190 { 191 return true; 192 } 193 } 194 return false; 195 } 196 197 205 public Group getGroup(String groupName) 206 { 207 Iterator iter = set.iterator(); 208 while (iter.hasNext()) 209 { 210 Group group = (Group) iter.next(); 211 if (groupName != null && 212 groupName.equals(group.getName())) 213 { 214 return group; 215 } 216 } 217 return null; 218 } 219 220 225 public Group [] getGroupsArray() 226 { 227 return (Group []) set.toArray(new Group[0]); 228 } 229 230 235 public Iterator elements() 236 { 237 return set.iterator(); 238 } 239 240 245 public int size() 246 { 247 return set.size(); 248 } 249 } 250 | Popular Tags |