?? flags.java
字號:
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. *//* * @(#)Flags.java 1.22 07/05/14 */package javax.mail;import java.io.Serializable;import java.util.*;/** * The Flags class represents the set of flags on a Message. Flags * are composed of predefined system flags, and user defined flags. <p> * * A System flag is represented by the <code>Flags.Flag</code> * inner class. A User defined flag is represented as a String. * User flags are case-independent. <p> * * 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 * <code>getPermanentFlags</code> method on a Folder returns a Flags * object that holds all the flags that are supported by that folder * implementation. <p> * * 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. <p> * * <strong>Warning:</strong> * Serialized objects of this class may not be compatible with future * JavaMail API releases. The current serialization support is * appropriate for short term storage. <p> * * The below code sample illustrates how to set, examine and get the * flags for a message. <p> * <pre> * * 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"); * ...... * ...... * } * </pre> * <p> * * @see Folder#getPermanentFlags * @author John Mani * @author Bill Shannon */public class Flags implements Cloneable, Serializable { private int system_flags = 0; private Hashtable user_flags = null; private final static int ANSWERED_BIT = 0x01; private final static int DELETED_BIT = 0x02; private final static int DRAFT_BIT = 0x04; private final static int FLAGGED_BIT = 0x08; private final static int RECENT_BIT = 0x10; private final static int SEEN_BIT = 0x20; private final static int USER_BIT = 0x80000000; private static final long serialVersionUID = 6243590407214169028L; /** * This inner class represents an individual system flag. A set * of standard system flag objects are predefined here. */ public static final class Flag { /** * This message has been answered. This flag is set by clients * to indicate that this message has been answered to. */ public static final Flag ANSWERED = new Flag(ANSWERED_BIT); /** * This message is marked deleted. Clients set this flag to * mark a message as deleted. The expunge operation on a folder * removes all messages in that folder that are marked for deletion. */ public static final Flag DELETED = new Flag(DELETED_BIT); /** * This message is a draft. This flag is set by clients * to indicate that the message is a draft message. */ public static final Flag DRAFT = new Flag(DRAFT_BIT); /** * This message is flagged. No semantic is defined for this flag. * Clients alter this flag. */ public static final Flag FLAGGED = new Flag(FLAGGED_BIT); /** * This message is recent. Folder implementations set this flag * to indicate that this message is new to this folder, that is, * it has arrived since the last time this folder was opened. <p> * * Clients cannot alter this flag. */ public static final Flag RECENT = new Flag(RECENT_BIT); /** * This message is seen. This flag is implicitly set by the * implementation when the this Message's content is returned * to the client in some form. The <code>getInputStream</code> * and <code>getContent</code> methods on Message cause this * flag to be set. <p> * * Clients can alter this flag. */ public static final Flag SEEN = new Flag(SEEN_BIT); /** * A special flag that indicates that this folder supports * user defined flags. <p> * * The implementation sets this flag. Clients cannot alter * this flag but can use it to determine if a folder supports * user defined flags by using * <code>folder.getPermanentFlags().contains(Flags.Flag.USER)</code>. */ public static final Flag USER = new Flag(USER_BIT); // flags are stored as bits for efficiency private int bit; private Flag(int bit) { this.bit = bit; } } /** * Construct an empty Flags object. */ public Flags() { } /** * Construct a Flags object initialized with the given flags. * * @param flags the flags for initialization */ 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 system flag. * * @param flag the flag for initialization */ public Flags(Flag flag) { this.system_flags |= flag.bit; } /** * Construct a Flags object initialized with the given user flag. * * @param flag the flag for initialization */ public Flags(String flag) { user_flags = new Hashtable(1); user_flags.put(flag.toLowerCase(Locale.ENGLISH), flag); } /** * Add the specified system flag to this Flags object. * * @param flag the flag to add */ public void add(Flag flag) { system_flags |= flag.bit; } /** * Add the specified user flag to this Flags object. * * @param flag the flag to add */ public void add(String flag) { if (user_flags == null) user_flags = new Hashtable(1); user_flags.put(flag.toLowerCase(Locale.ENGLISH), flag); } /** * Add all the flags in the given Flags object to this * Flags object. * * @param f 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)); } } } /** * Remove the specified system flag from this Flags object. * * @param flag the flag to be removed */ public void remove(Flag flag) { system_flags &= ~flag.bit; } /** * Remove the specified user flag from this Flags object. * * @param flag the flag to be removed */ public void remove(String flag) { if (user_flags != null) user_flags.remove(flag.toLowerCase(Locale.ENGLISH)); } /** * Remove all flags in the given Flags object from this * Flags object. * * @param f the flag to be removed */ 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());
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -