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.Role; 64 65 76 public class RoleSet implements Serializable 77 { 78 79 private TreeSet set; 80 81 84 public RoleSet() 85 { 86 set = new TreeSet (); 87 } 88 89 97 public RoleSet(Collection roles) 98 { 99 this(); 100 add(roles); 101 } 102 103 110 public boolean add(Role role) 111 { 112 return set.add((Object ) role); 113 } 114 115 124 public boolean add(Collection roles) 125 { 126 return set.addAll(roles); 127 } 128 129 137 public boolean add(RoleSet roleSet) 138 { 139 return set.addAll(roleSet.set); 140 } 141 142 149 public boolean remove(Role role) 150 { 151 return set.remove((Object ) role); 152 } 153 154 157 public void clear() 158 { 159 set.clear(); 160 } 161 162 169 public boolean contains(Role role) 170 { 171 return set.contains((Object ) role); 172 } 173 174 182 public boolean contains(String roleName) 183 { 184 Iterator iter = set.iterator(); 185 while (iter.hasNext()) 186 { 187 Role role = (Role) iter.next(); 188 if (roleName != null && 189 roleName.equals(role.getName())) 190 { 191 return true; 192 } 193 } 194 return false; 195 } 196 197 205 public Role getRole(String roleName) 206 { 207 Iterator iter = set.iterator(); 208 while (iter.hasNext()) 209 { 210 Role role = (Role) iter.next(); 211 if (roleName != null && 212 roleName.equals(role.getName())) 213 { 214 return role; 215 } 216 } 217 return null; 218 } 219 220 225 public Role [] getRolesArray() 226 { 227 return (Role []) set.toArray(new Role[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 255 public String toString() 256 { 257 StringBuffer sbuf = new StringBuffer (12 * size()); 258 Iterator i = set.iterator(); 259 while (i.hasNext()) 260 { 261 sbuf.append(((Role) i.next()).getName()) 262 .append(", "); 263 } 264 return sbuf.toString(); 265 } 266 } 267 | Popular Tags |