001 /*
002 * Copyright 2010 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package com.hs.mail.imap.message.search;
017
018 import javax.mail.Flags;
019 import javax.mail.Flags.Flag;
020
021 /**
022 * This class implements search-criteria for Message Flag.
023 *
024 * @author Won Chul Doh
025 * @since Jan 30, 2010
026 *
027 */
028 public final class FlagKey extends SearchKey {
029
030 /**
031 * Indicates whether to test for the presence or absence of the specified
032 * Flag. If <code>true</code>, then test whether the specified flag is
033 * present, else test whether the specified flag is absent.
034 */
035 protected boolean set;
036
037 /**
038 * Flag object containing the flag to test.
039 */
040 protected Flags.Flag flag;
041
042 public FlagKey(Flag flag, boolean set) {
043 this.flag = flag;
044 this.set = set;
045 }
046
047 public Flags.Flag getFlag() {
048 return flag;
049 }
050
051 public boolean isSet() {
052 return set;
053 }
054
055 public boolean equals(Object obj) {
056 if (!(obj instanceof FlagKey))
057 return false;
058 FlagKey fk = (FlagKey) obj;
059 return fk.set == this.set && fk.flag.equals(this.flag);
060 }
061
062 public int hashCode() {
063 return set ? flag.hashCode() : ~flag.hashCode();
064 }
065
066 @Override
067 public boolean isComposite() {
068 return false;
069 }
070
071 }