Representation of flags that may be associated with a message.
Flags can either be system flags, defined by the
inner class,
or user-defined flags defined by a String. The system flags represent those expected
to be provided by most folder systems; user-defined flags allow for additional flags
on a per-provider basis.
This class is Serializable but compatibility is not guaranteed across releases.
| Method from javax.mail.Flags Detail: |
public void add(Flags.Flag flag) {
system_flags |= flag.mask;
}
|
public void add(Flags flags) {
system_flags |= flags.system_flags;
user_flags.putAll(flags.user_flags);
}
Set all system and user flags from the supplied Flags.
Question: do we need to check compatibility of USER flags? |
public void add(String name) {
user_flags.put(name.toLowerCase(), name);
}
Set a user flag.
Question: should this fail if the USER system flag is not set? |
public Object clone() {
return new Flags(this);
}
Return a copy of this instance. |
public boolean contains(Flags.Flag flag) {
return (system_flags & flag.mask) != 0;
}
See if the supplied system flags are set |
public boolean contains(Flags flags) {
return ((system_flags & flags.system_flags) == flags.system_flags)
&& user_flags.keySet().containsAll(flags.user_flags.keySet());
}
See if all of the supplied Flags are set |
public boolean contains(String name) {
return user_flags.containsKey(name.toLowerCase());
}
See if the supplied user flag is set |
public boolean equals(Object other) {
if (other == this) return true;
if (other instanceof Flags == false) return false;
final Flags flags = (Flags) other;
return system_flags == flags.system_flags && user_flags.keySet().equals(flags.user_flags.keySet());
}
Equality is defined as true if the other object is a instanceof Flags with the
same system and user flags set (using a case-insensitive name comparison for user flags). |
public Flags.Flag[] getSystemFlags() {
// assumption: it is quicker to calculate the size than it is to reallocate the array
int size = 0;
if ((system_flags & Flag.ANSWERED.mask) != 0) size += 1;
if ((system_flags & Flag.DELETED.mask) != 0) size += 1;
if ((system_flags & Flag.DRAFT.mask) != 0) size += 1;
if ((system_flags & Flag.FLAGGED.mask) != 0) size += 1;
if ((system_flags & Flag.RECENT.mask) != 0) size += 1;
if ((system_flags & Flag.SEEN.mask) != 0) size += 1;
if ((system_flags & Flag.USER.mask) != 0) size += 1;
Flag[] result = new Flag[size];
if ((system_flags & Flag.USER.mask) != 0) result[--size] = Flag.USER;
if ((system_flags & Flag.SEEN.mask) != 0) result[--size] = Flag.SEEN;
if ((system_flags & Flag.RECENT.mask) != 0) result[--size] = Flag.RECENT;
if ((system_flags & Flag.FLAGGED.mask) != 0) result[--size] = Flag.FLAGGED;
if ((system_flags & Flag.DRAFT.mask) != 0) result[--size] = Flag.DRAFT;
if ((system_flags & Flag.DELETED.mask) != 0) result[--size] = Flag.DELETED;
if ((system_flags & Flag.ANSWERED.mask) != 0) result[--size] = Flag.ANSWERED;
return result;
}
Return a list of Flags containing the system flags that have been set |
public String[] getUserFlags() {
return (String[]) user_flags.values().toArray(new String[user_flags.values().size()]);
}
Return a list of user flags that have been set |
public int hashCode() {
return system_flags ^ user_flags.keySet().hashCode();
}
Calculate a hashCode for this instance |
public void remove(Flags.Flag flag) {
system_flags &= ~flag.mask;
}
Unset the supplied system flag.
Question: what happens if we unset the USER flags and user flags are set? |
public void remove(Flags flags) {
system_flags &= ~flags.system_flags;
user_flags.keySet().removeAll(flags.user_flags.keySet());
}
Unset all flags from the supplied instance. |
public void remove(String name) {
user_flags.remove(name.toLowerCase());
}
Unset the supplied user flag. |