KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > search > SubjectTerm


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)SubjectTerm.java 1.8 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.search;
29
30 import javax.mail.Message JavaDoc;
31
32 /**
33  * This class implements comparisons for the Message Subject header.
34  * The comparison is case-insensitive.
35  *
36  * @author Bill Shannon
37  * @author John Mani
38  */

39 public final class SubjectTerm extends StringTerm JavaDoc {
40
41     private static final long serialVersionUID = 7481568618055573432L;
42
43     /**
44      * Constructor.
45      *
46      * @param pattern the pattern to search for
47      */

48     public SubjectTerm(String JavaDoc pattern) {
49     // Note: comparison is case-insensitive
50
super(pattern);
51     }
52
53     /**
54      * The match method.
55      *
56      * @param msg the pattern match is applied to this Message's
57      * subject header
58      * @return true if the pattern match succeeds, otherwise false
59      */

60     public boolean match(Message JavaDoc msg) {
61     String JavaDoc subj;
62
63     try {
64         subj = msg.getSubject();
65     } catch (Exception JavaDoc e) {
66         return false;
67     }
68
69     if (subj == null)
70         return false;
71
72     return super.match(subj);
73     }
74
75     /**
76      * Equality comparison.
77      */

78     public boolean equals(Object JavaDoc obj) {
79     if (!(obj instanceof SubjectTerm JavaDoc))
80         return false;
81     return super.equals(obj);
82     }
83 }
84
Popular Tags