1 package org.apache.turbine.util.security; 2 3 18 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 22 import org.apache.commons.lang.StringUtils; 23 24 import org.apache.turbine.om.security.Group; 25 26 38 public class GroupSet 39 extends SecuritySet 40 { 41 44 public GroupSet() 45 { 46 super(); 47 } 48 49 57 public GroupSet(Collection groups) 58 { 59 super(); 60 add(groups); 61 } 62 63 70 public boolean add(Group group) 71 { 72 boolean res = contains(group); 73 nameMap.put(group.getName(), group); 74 idMap.put(group.getIdAsObj(), group); 75 return res; 76 } 77 78 86 public boolean add(Collection groups) 87 { 88 boolean res = false; 89 for (Iterator it = groups.iterator(); it.hasNext();) 90 { 91 Group g = (Group) it.next(); 92 res |= add(g); 93 } 94 return res; 95 } 96 97 105 public boolean add(GroupSet groupSet) 106 { 107 boolean res = false; 108 for( Iterator it = groupSet.iterator(); it.hasNext();) 109 { 110 Group g = (Group) it.next(); 111 res |= add(g); 112 } 113 return res; 114 } 115 116 123 public boolean remove(Group group) 124 { 125 boolean res = contains(group); 126 nameMap.remove(group.getName()); 127 idMap.remove(group.getIdAsObj()); 128 return res; 129 } 130 131 138 public boolean contains(Group group) 139 { 140 return nameMap.containsValue((Object ) group); 141 } 142 143 152 public Group getGroup(String groupName) 153 { 154 return getGroupByName(groupName); 155 } 156 157 165 public Group getGroupByName(String groupName) 166 { 167 return (StringUtils.isNotEmpty(groupName)) 168 ? (Group) nameMap.get(groupName) : null; 169 } 170 171 179 public Group getGroupById(int groupId) 180 { 181 return (groupId != 0) 182 ? (Group) idMap.get(new Integer (groupId)) : null; 183 } 184 185 190 public Group[] getGroupsArray() 191 { 192 return (Group[]) getSet().toArray(new Group[0]); 193 } 194 195 201 public String toString() 202 { 203 StringBuffer sb = new StringBuffer (); 204 sb.append("GroupSet: "); 205 206 for(Iterator it = iterator(); it.hasNext();) 207 { 208 Group g = (Group) it.next(); 209 sb.append('['); 210 sb.append(g.getName()); 211 sb.append(" -> "); 212 sb.append(g.getIdAsObj()); 213 sb.append(']'); 214 if (it.hasNext()) 215 { 216 sb.append(", "); 217 } 218 } 219 220 return sb.toString(); 221 } 222 } 223 | Popular Tags |