javax.mail
public class: Flags [javadoc |
source]
java.lang.Object
javax.mail.Flags
All Implemented Interfaces:
Cloneable, Serializable
The Flags class represents the set of flags on a Message. Flags
are composed of predefined system flags, and user defined flags.
A System flag is represented by the Flags.Flag
inner class. A User defined flag is represented as a String.
User flags are case-independent.
A set of standard system flags are predefined. Most folder
implementations are expected to support these flags. Some
implementations may also support arbitrary user-defined flags. The
getPermanentFlags
method on a Folder returns a Flags
object that holds all the flags that are supported by that folder
implementation.
A Flags object is serializable so that (for example) the
use of Flags objects in search terms can be serialized
along with the search terms.
Warning:
Serialized objects of this class may not be compatible with future
JavaMail API releases. The current serialization support is
appropriate for short term storage.
The below code sample illustrates how to set, examine and get the
flags for a message.
Message m = folder.getMessage(1);
m.setFlag(Flags.Flag.DELETED, true); // set the DELETED flag
// Check if DELETED flag is set of this message
if (m.isSet(Flags.Flag.DELETED))
System.out.println("DELETED message");
// Examine ALL system flags for this message
Flags flags = m.getFlags();
Flags.Flag[] sf = flags.getSystemFlags();
for (int i = 0; i < sf.length; i++) {
if (sf[i] == Flags.Flag.DELETED)
System.out.println("DELETED message");
else if (sf[i] == Flags.Flag.SEEN)
System.out.println("SEEN message");
......
......
}
Also see:
- Folder#getPermanentFlags
- author:
John
- Mani
- author:
Bill
- Shannon
Nested Class Summary: |
---|
public static final class | Flags.Flag | This inner class represents an individual system flag. A set
of standard system flag objects are predefined here. |
Constructor: |
public Flags() {
}
Construct an empty Flags object. |
public Flags(Flags flags) {
this.system_flags = flags.system_flags;
if (flags.user_flags != null)
this.user_flags = (Hashtable)flags.user_flags.clone();
}
Construct a Flags object initialized with the given flags. Parameters:
flags - the flags for initialization
|
public Flags(Flag flag) {
this.system_flags |= flag.bit;
}
Construct a Flags object initialized with the given system flag. Parameters:
flag - the flag for initialization
|
public Flags(String flag) {
user_flags = new Hashtable(1);
user_flags.put(flag.toLowerCase(Locale.ENGLISH), flag);
}
Construct a Flags object initialized with the given user flag. Parameters:
flag - the flag for initialization
|
Method from javax.mail.Flags Summary: |
---|
add, add, add, clone, contains, contains, contains, equals, getSystemFlags, getUserFlags, hashCode, remove, remove, remove |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.mail.Flags Detail: |
public void add(Flag flag) {
system_flags |= flag.bit;
}
Add the specified system flag to this Flags object. |
public void add(String flag) {
if (user_flags == null)
user_flags = new Hashtable(1);
user_flags.put(flag.toLowerCase(Locale.ENGLISH), flag);
}
Add the specified user flag to this Flags object. |
public void add(Flags f) {
system_flags |= f.system_flags; // add system flags
if (f.user_flags != null) { // add user-defined flags
if (user_flags == null)
user_flags = new Hashtable(1);
Enumeration e = f.user_flags.keys();
while (e.hasMoreElements()) {
String s = (String)e.nextElement();
user_flags.put(s, f.user_flags.get(s));
}
}
}
Add all the flags in the given Flags object to this
Flags object. |
public Object clone() {
Flags f = null;
try {
f = (Flags)super.clone();
} catch (CloneNotSupportedException cex) {
// ignore, can't happen
}
if (this.user_flags != null && f != null)
f.user_flags = (Hashtable)this.user_flags.clone();
return f;
}
Returns a clone of this Flags object. |
public boolean contains(Flag flag) {
return (system_flags & flag.bit) != 0;
}
Check whether the specified system flag is present in this Flags object. |
public boolean contains(String flag) {
if (user_flags == null)
return false;
else
return user_flags.containsKey(flag.toLowerCase(Locale.ENGLISH));
}
Check whether the specified user flag is present in this Flags object. |
public boolean contains(Flags f) {
// Check system flags
if ((f.system_flags & system_flags) != f.system_flags)
return false;
// Check user flags
if (f.user_flags != null) {
if (user_flags == null)
return false;
Enumeration e = f.user_flags.keys();
while (e.hasMoreElements()) {
if (!user_flags.containsKey(e.nextElement()))
return false;
}
}
// If we've made it till here, return true
return true;
}
Check whether all the flags in the specified Flags object are
present in this Flags object. |
public boolean equals(Object obj) {
if (!(obj instanceof Flags))
return false;
Flags f = (Flags)obj;
// Check system flags
if (f.system_flags != this.system_flags)
return false;
// Check user flags
if (f.user_flags == null && this.user_flags == null)
return true;
if (f.user_flags != null && this.user_flags != null &&
f.user_flags.size() == this.user_flags.size()) {
Enumeration e = f.user_flags.keys();
while (e.hasMoreElements()) {
if (!this.user_flags.containsKey(e.nextElement()))
return false;
}
return true;
}
return false;
}
Check whether the two Flags objects are equal. |
public Flag[] getSystemFlags() {
Vector v = new Vector();
if ((system_flags & ANSWERED_BIT) != 0)
v.addElement(Flag.ANSWERED);
if ((system_flags & DELETED_BIT) != 0)
v.addElement(Flag.DELETED);
if ((system_flags & DRAFT_BIT) != 0)
v.addElement(Flag.DRAFT);
if ((system_flags & FLAGGED_BIT) != 0)
v.addElement(Flag.FLAGGED);
if ((system_flags & RECENT_BIT) != 0)
v.addElement(Flag.RECENT);
if ((system_flags & SEEN_BIT) != 0)
v.addElement(Flag.SEEN);
if ((system_flags & USER_BIT) != 0)
v.addElement(Flag.USER);
Flag[] f = new Flag[v.size()];
v.copyInto(f);
return f;
}
Return all the system flags in this Flags object. Returns
an array of size zero if no flags are set. |
public String[] getUserFlags() {
Vector v = new Vector();
if (user_flags != null) {
Enumeration e = user_flags.elements();
while (e.hasMoreElements())
v.addElement(e.nextElement());
}
String[] f = new String[v.size()];
v.copyInto(f);
return f;
}
Return all the user flags in this Flags object. Returns
an array of size zero if no flags are set. |
public int hashCode() {
int hash = system_flags;
if (user_flags != null) {
Enumeration e = user_flags.keys();
while (e.hasMoreElements())
hash += ((String)e.nextElement()).hashCode();
}
return hash;
}
Compute a hash code for this Flags object. |
public void remove(Flag flag) {
system_flags &= ~flag.bit;
}
Remove the specified system flag from this Flags object. |
public void remove(String flag) {
if (user_flags != null)
user_flags.remove(flag.toLowerCase(Locale.ENGLISH));
}
Remove the specified user flag from this Flags object. |
public void remove(Flags f) {
system_flags &= ~f.system_flags; // remove system flags
if (f.user_flags != null) {
if (user_flags == null)
return;
Enumeration e = f.user_flags.keys();
while (e.hasMoreElements())
user_flags.remove(e.nextElement());
}
}
Remove all flags in the given Flags object from this
Flags object. |