1 package org.apache.turbine.util.security; 2 3 18 19 import java.io.Serializable ; 20 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.Set ; 25 import java.util.TreeMap ; 26 27 import org.apache.commons.lang.StringUtils; 28 29 42 public abstract class SecuritySet 43 implements Serializable 44 { 45 46 protected Map nameMap = null; 47 48 49 protected Map idMap = null; 50 51 54 public SecuritySet() 55 { 56 nameMap = new TreeMap (); 57 idMap = new TreeMap (); 58 } 59 60 66 public Set getSet() 67 { 68 return new HashSet (nameMap.values()); 69 } 70 71 77 public Set getNames() 78 { 79 return nameMap.keySet(); 80 } 81 82 88 public Set getIds() 89 { 90 return idMap.keySet(); 91 } 92 93 96 public void clear() 97 { 98 nameMap.clear(); 99 idMap.clear(); 100 } 101 102 111 public boolean contains(String groupName) 112 { 113 return containsName(groupName); 114 } 115 116 124 public boolean containsName(String name) 125 { 126 return (StringUtils.isNotEmpty(name)) ? nameMap.containsKey(name) : false; 127 } 128 129 137 public boolean containsId(int id) 138 { 139 return (id == 0) ? false: idMap.containsKey(new Integer (id)); 140 } 141 142 147 public Iterator iterator() 148 { 149 return nameMap.values().iterator(); 150 } 151 152 155 public Iterator elements() 156 { 157 return iterator(); 158 } 159 160 165 public int size() 166 { 167 return nameMap.size(); 168 } 169 170 175 public String toString() 176 { 177 StringBuffer sbuf = new StringBuffer (12 * size()); 178 for(Iterator it = nameMap.keySet().iterator(); it.hasNext(); ) 179 { 180 sbuf.append((String ) it.next()); 181 182 if(it.hasNext()) 183 { 184 sbuf.append(", "); 185 } 186 } 187 return sbuf.toString(); 188 } 189 } 190 191 | Popular Tags |