1 21 22 27 28 package com.sun.mail.imap; 29 30 import java.util.*; 31 32 62 63 public class Rights implements Cloneable { 64 65 private boolean[] rights = new boolean[128]; 67 71 public static final class Right { 72 private static Right[] cache = new Right[128]; 73 74 78 public static final Right LOOKUP = getInstance('l'); 79 80 84 public static final Right READ = getInstance('r'); 85 86 89 public static final Right KEEP_SEEN = getInstance('s'); 90 91 94 public static final Right WRITE = getInstance('w'); 95 96 99 public static final Right INSERT = getInstance('i'); 100 101 105 public static final Right POST = getInstance('p'); 106 107 111 public static final Right CREATE = getInstance('c'); 112 113 116 public static final Right DELETE = getInstance('d'); 117 118 121 public static final Right ADMINISTER = getInstance('a'); 122 123 char right; 125 128 private Right(char right) { 129 if ((int)right >= 128) 130 throw new IllegalArgumentException ("Right must be ASCII"); 131 this.right = right; 132 } 133 134 138 public static synchronized Right getInstance(char right) { 139 if ((int)right >= 128) 140 throw new IllegalArgumentException ("Right must be ASCII"); 141 if (cache[(int)right] == null) 142 cache[(int)right] = new Right(right); 143 return cache[(int)right]; 144 } 145 146 public String toString() { 147 return String.valueOf(right); 148 } 149 } 150 151 152 155 public Rights() { } 156 157 162 public Rights(Rights rights) { 163 System.arraycopy(rights.rights, 0, this.rights, 0, this.rights.length); 164 } 165 166 171 public Rights(String rights) { 172 for (int i = 0; i < rights.length(); i++) 173 add(Right.getInstance(rights.charAt(i))); 174 } 175 176 181 public Rights(Right right) { 182 this.rights[(int)right.right] = true; 183 } 184 185 190 public void add(Right right) { 191 this.rights[(int)right.right] = true; 192 } 193 194 200 public void add(Rights rights) { 201 for (int i = 0; i < rights.rights.length; i++) 202 if (rights.rights[i]) 203 this.rights[i] = true; 204 } 205 206 211 public void remove(Right right) { 212 this.rights[(int)right.right] = false; 213 } 214 215 221 public void remove(Rights rights) { 222 for (int i = 0; i < rights.rights.length; i++) 223 if (rights.rights[i]) 224 this.rights[i] = false; 225 } 226 227 232 public boolean contains(Right right) { 233 return this.rights[(int)right.right]; 234 } 235 236 243 public boolean contains(Rights rights) { 244 for (int i = 0; i < rights.rights.length; i++) 245 if (rights.rights[i] && !this.rights[i]) 246 return false; 247 248 return true; 250 } 251 252 257 public boolean equals(Object obj) { 258 if (!(obj instanceof Rights)) 259 return false; 260 261 Rights rights = (Rights)obj; 262 263 for (int i = 0; i < rights.rights.length; i++) 264 if (rights.rights[i] != this.rights[i]) 265 return false; 266 267 return true; 268 } 269 270 275 public int hashCode() { 276 int hash = 0; 277 for (int i = 0; i < this.rights.length; i++) 278 if (this.rights[i]) 279 hash++; 280 return hash; 281 } 282 283 289 public Right[] getRights() { 290 Vector v = new Vector(); 291 for (int i = 0; i < this.rights.length; i++) 292 if (this.rights[i]) 293 v.addElement(Right.getInstance((char)i)); 294 Right[] rights = new Right[v.size()]; 295 v.copyInto(rights); 296 return rights; 297 } 298 299 302 public Object clone() { 303 return new Rights(this); 304 } 305 306 public String toString() { 307 StringBuffer sb = new StringBuffer (); 308 for (int i = 0; i < this.rights.length; i++) 309 if (this.rights[i]) 310 sb.append((char)i); 311 return sb.toString(); 312 } 313 314 439 } 440 | Popular Tags |