1 36 package org.columba.ristretto.message; 37 38 import java.io.IOException ; 39 import java.io.ObjectInputStream ; 40 import java.io.ObjectOutputStream ; 41 42 48 public class Flags implements Saveable, Cloneable { 49 50 51 54 public static final short ANSWERED = 0x0001; 55 58 public static final short DRAFT = 0x0004; 59 62 public static final short FLAGGED = 0x0008; 63 66 public static final short RECENT = 0x0010; 67 70 public static final short SEEN = 0x0020; 71 74 public static final short DELETED = 0x0040; 75 76 private short flags; 77 78 81 public Flags() { 82 flags = 0; 83 } 84 85 90 public Flags(short flags) { 91 this.flags = flags; 92 } 93 94 100 public Flags(ObjectInputStream in) throws IOException { 101 load(in); 102 } 103 104 110 public boolean get(short mask) { 111 return (flags & mask) > 0; 112 } 113 114 120 public void set(short mask, boolean value) { 121 if (value) { 122 set(mask); 123 } else { 124 clear(mask); 125 } 126 } 127 128 133 public void set(short mask) { 134 flags |= mask; 135 } 136 137 142 public void clear(short mask) { 143 flags &= 0x0ffffffff ^ mask; 144 } 145 146 151 public void toggle(short mask) { 152 flags ^= mask; 153 } 154 155 158 public boolean getSeen() { 159 return get(SEEN); 160 } 161 162 165 public boolean getRecent() { 166 return get(RECENT); 167 } 168 169 172 public boolean getAnswered() { 173 return get(ANSWERED); 174 } 175 176 179 public boolean getFlagged() { 180 return get(FLAGGED); 181 } 182 183 186 public boolean getDeleted() { 187 return get(DELETED); 188 } 189 190 193 public boolean getDraft() { 194 return get(DRAFT); 195 } 196 197 202 public void setSeen(boolean b) { 203 if (b) { 204 set(SEEN); 205 } else { 206 clear(SEEN); 207 } 208 } 209 210 215 public void setRecent(boolean b) { 216 if (b) { 217 set(RECENT); 218 } else { 219 clear(RECENT); 220 } 221 } 222 223 228 public void setAnswered(boolean b) { 229 if (b) { 230 set(ANSWERED); 231 } else { 232 clear(ANSWERED); 233 } 234 } 235 236 241 public void setFlagged(boolean b) { 242 if (b) { 243 set(FLAGGED); 244 } else { 245 clear(FLAGGED); 246 } 247 } 248 249 254 public void setDeleted(boolean b) { 255 if (b) { 256 set(DELETED); 257 } else { 258 clear(DELETED); 259 } 260 } 261 262 267 public void setDraft(boolean b) { 268 if (b) { 269 set(DRAFT); 270 } else { 271 clear(DRAFT); 272 } 273 } 274 275 278 public void load(ObjectInputStream in) throws IOException { 279 flags = in.readShort(); 280 } 281 282 285 public void save(ObjectOutputStream out) throws IOException { 286 out.writeShort(flags); 287 } 288 289 290 public Object clone() { 291 Flags clone; 292 try { 293 clone = (Flags) super.clone(); 294 clone.flags = flags; 295 return clone; 296 } catch (CloneNotSupportedException e) { 297 throw new RuntimeException (e); 298 } 299 } 300 301 304 public short getFlags() { 305 return flags; 306 } 307 308 311 public void setFlags(short s) { 312 flags = s; 313 } 314 315 316 public boolean equals(Object obj) { 317 boolean isEqual = false; 318 if ((obj != null) && (obj instanceof Flags)) { 319 Flags other = (Flags) obj; 320 isEqual = (flags == other.flags); 321 } 322 return isEqual; 323 } 324 325 326 public int hashCode() { 327 return flags; 328 } 329 330 331 public String toString() { 332 StringBuffer buffer = new StringBuffer (); 333 buffer.append("Flags[answered="); 334 buffer.append(getAnswered()); 335 buffer.append(", draft="); 336 buffer.append(getDraft()); 337 buffer.append(", expunged="); 338 buffer.append(getDeleted()); 339 buffer.append(", flagged="); 340 buffer.append(getFlagged()); 341 buffer.append(", recent="); 342 buffer.append(getRecent()); 343 buffer.append(", seen="); 344 buffer.append(getSeen()); 345 buffer.append("]"); 346 return buffer.toString(); 347 } 348 } 349 | Popular Tags |