geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r126550 - geronimo/trunk/specs/javamail/src/java/javax/mail/search
Date Wed, 26 Jan 2005 22:27:45 GMT
Author: jboynes
Date: Wed Jan 26 14:27:45 2005
New Revision: 126550

URL: http://svn.apache.org/viewcvs?view=rev&rev=126550
Log:
cleanup on search terms
Modified:
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java
   geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/AddressTerm.java	Wed Jan 26 14:27:45
2005
@@ -20,29 +20,51 @@
 import javax.mail.Address;
 
 /**
+ * Term that compares two addresses.
+ *
  * @version $Rev$ $Date$
  */
 public abstract class AddressTerm extends SearchTerm {
+    /**
+     * The address.
+     */
     protected Address address;
 
+    /**
+     * Constructor taking the address for this term.
+     * @param address the address
+     */
     protected AddressTerm(Address address) {
         this.address = address;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && ((AddressTerm) other).address.equals(address);
-    }
-
+    /**
+     * Return the address of this term.
+     *
+     * @return the addre4ss
+     */
     public Address getAddress() {
         return address;
     }
 
-    public int hashCode() {
-        return super.hashCode() + address.hashCode();
-    }
-
+    /**
+     * Match to the supplied address.
+     *
+     * @param address the address to match with
+     * @return true if the addresses match
+     */
     protected boolean match(Address address) {
         return this.address.equals(address);
+    }
+
+    public boolean equals(Object other) {
+        if (this == other) return true;
+        if (other instanceof AddressTerm == false) return false;
+
+        return address.equals(((AddressTerm) other).address);
+    }
+
+    public int hashCode() {
+        return address.hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/AndTerm.java	Wed Jan 26 14:27:45
2005
@@ -21,38 +21,70 @@
 import javax.mail.Message;
 
 /**
+ * Term that implements a logical AND across terms.
+ *
  * @version $Rev$ $Date$
  */
 public final class AndTerm extends SearchTerm {
+    /**
+     * Terms to which the AND operator should be applied.
+     */
     protected SearchTerm[] terms;
 
+    /**
+     * Constructor for performing a binary AND.
+     *
+     * @param a the first term
+     * @param b the second ter,
+     */
     public AndTerm(SearchTerm a, SearchTerm b) {
         terms = new SearchTerm[]{a, b};
     }
 
+    /**
+     * Constructor for performing and AND across an arbitraty number of terms.
+     * @param terms the terms to AND together
+     */
     public AndTerm(SearchTerm[] terms) {
         this.terms = terms;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && Arrays.equals(terms, ((AndTerm) other).terms);
-    }
-
+    /**
+     * Return the terms.
+     * @return the terms
+     */
     public SearchTerm[] getTerms() {
         return terms;
     }
 
-    public int hashCode() {
-        return super.hashCode() + terms.length * 37;
-    }
-
+    /**
+     * Match by applying the terms, in order, to the Message and performing an AND operation
+     * to the result. Comparision will stop immediately if one of the terms returns false.
+     *
+     * @param message the Message to apply the terms to
+     * @return true if all terms match
+     */
     public boolean match(Message message) {
-        boolean result = true;
-        for (int i = 0; result && i < terms.length; i++) {
+        for (int i = 0; i < terms.length; i++) {
             SearchTerm term = terms[i];
-            result = term.match(message);
+            if (!term.match(message)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof AndTerm == false) return false;
+        return Arrays.equals(terms, ((AndTerm) other).terms);
+    }
+
+    public int hashCode() {
+        int hash = 0;
+        for (int i = 0; i < terms.length; i++) {
+            hash = hash * 37 + terms[i].hashCode();
         }
-        return result;
+        return hash;
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/BodyTerm.java	Wed Jan 26 14:27:45
2005
@@ -20,21 +20,46 @@
 import java.io.IOException;
 import javax.mail.Message;
 import javax.mail.MessagingException;
+import javax.mail.Part;
+import javax.mail.Multipart;
+import javax.mail.BodyPart;
 
 /**
+ * Term that matches on a message body. All {@link javax.mail.BodyPart parts} that have
+ * a MIME type of "text/*" are searched.
+ *
  * @version $Rev$ $Date$
  */
 public final class BodyTerm extends StringTerm {
-    public BodyTerm(String body) {
-        super(body);
+    public BodyTerm(String pattern) {
+        super(pattern);
     }
 
     public boolean match(Message message) {
         try {
-            return match((String) message.getContent());
+            return matchPart(message);
         } catch (IOException e) {
             return false;
         } catch (MessagingException e) {
+            return false;
+        }
+    }
+
+    private boolean matchPart(Part part) throws MessagingException, IOException {
+        if (part.isMimeType("multipart/*")) {
+            Multipart mp = (Multipart) part.getContent();
+            int count = mp.getCount();
+            for (int i=0; i < count; i++) {
+                BodyPart bp = mp.getBodyPart(i);
+                if (matchPart(bp)) {
+                    return true;
+                }
+            }
+            return false;
+        } else if (part.isMimeType("text/*")) {
+            String content = (String) part.getContent();
+            return super.match(content);
+        } else {
             return false;
         }
     }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/ComparisonTerm.java	Wed Jan 26
14:27:45 2005
@@ -18,46 +18,28 @@
 package javax.mail.search;
 
 /**
+ * Base for comparison terms.
+ *
  * @version $Rev$ $Date$
  */
 public abstract class ComparisonTerm extends SearchTerm {
-    // Constants from J2SE 1.4 API Doc (Constant Values)
-    public static final int EQ = 3;
-    public static final int GE = 6;
-    public static final int GT = 5;
     public static final int LE = 1;
     public static final int LT = 2;
+    public static final int EQ = 3;
     public static final int NE = 4;
+    public static final int GT = 5;
+    public static final int GE = 6;
+
     protected int comparison;
 
-    // Dozy idiots didn't provide a constructor with an int comparison argument
     public ComparisonTerm() {
     }
 
-    ComparisonTerm(int comparison) {
-        this.comparison = comparison;
-    }
-
-    boolean compare(int answer) {
-        if (answer == 0) {
-            return (comparison == EQ || comparison == LE || comparison == GE);
-        } else if (answer > 0) {
-            return (comparison == GE || comparison == GT || comparison == NE);
-        } else {
-            return (comparison == LE || comparison == LT || comparison == NE);
-        }
-    }
-
     public boolean equals(Object other) {
-        return super.equals(other)
-                && ((ComparisonTerm) other).comparison == comparison;
-    }
-
-    int getComparison() {
-        return comparison;
+        return super.equals(other);
     }
 
     public int hashCode() {
-        return super.hashCode() + comparison * 31;
+        return super.hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/DateTerm.java	Wed Jan 26 14:27:45
2005
@@ -26,30 +26,48 @@
     protected Date date;
 
     protected DateTerm(int comparison, Date date) {
-        super(comparison);
-        if (date == null) {
-            throw new IllegalArgumentException("Date cannot be null");
-        }
+        super();
+        this.comparison = comparison;
         this.date = date;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other) && ((DateTerm) other).date.equals(date);
+    public Date getDate() {
+        return date;
     }
 
     public int getComparison() {
-        return super.getComparison();
+        return comparison;
     }
 
-    public Date getDate() {
-        return date;
+    protected boolean match(Date match) {
+        long matchTime = match.getTime();
+        long mytime = date.getTime();
+        switch (comparison) {
+        case EQ:
+            return matchTime == mytime;
+        case NE:
+            return matchTime != mytime;
+        case LE:
+            return matchTime <= mytime;
+        case LT:
+            return matchTime < mytime;
+        case GT:
+            return matchTime > mytime;
+        case GE:
+            return matchTime >= mytime;
+        default:
+            return false;
+        }
     }
 
-    public int hashCode() {
-        return super.hashCode() + date.hashCode();
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof DateTerm == false) return false;
+        final DateTerm term = (DateTerm) other;
+        return this.comparison == term.comparison && this.date.equals(term.date);
     }
 
-    protected boolean match(Date match) {
-        return compare(date.compareTo(match));
+    public int hashCode() {
+        return date.hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/FlagTerm.java	Wed Jan 26 14:27:45
2005
@@ -22,23 +22,29 @@
 import javax.mail.MessagingException;
 
 /**
+ * Term for matching message {@link Flags}.
+ *
  * @version $Rev$ $Date$
  */
 public final class FlagTerm extends SearchTerm {
-    protected Flags flags;
+    /**
+     * If true, test that all flags are set; if false, test that all flags are clear.
+     */
     protected boolean set;
+    /**
+     * The flags to test.
+     */
+    protected Flags flags;
 
+    /**
+     * @param flags the flags to test
+     * @param set test for set or clear; {@link #set}
+     */
     public FlagTerm(Flags flags, boolean set) {
         this.set = set;
         this.flags = flags;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && ((FlagTerm) other).flags.equals(flags)
-                && ((FlagTerm) other).set == set;
-    }
-
     public Flags getFlags() {
         return flags;
     }
@@ -47,15 +53,42 @@
         return set;
     }
 
-    public int hashCode() {
-        return super.hashCode() + flags.hashCode() + (set ? 99 : 234);
-    }
-
     public boolean match(Message message) {
         try {
-            return message.getFlags().contains(flags) == set;
+            Flags msgFlags = message.getFlags();
+            if (set) {
+                return msgFlags.contains(flags);
+            } else {
+                // yuk - I wish we could get at the internal state of the Flags
+                Flags.Flag[] system = flags.getSystemFlags();
+                for (int i = 0; i < system.length; i++) {
+                    Flags.Flag flag = system[i];
+                    if (msgFlags.contains(flag)) {
+                        return false;
+                    }
+                }
+                String[] user = flags.getUserFlags();
+                for (int i = 0; i < user.length; i++) {
+                    String flag = user[i];
+                    if (msgFlags.contains(flag)) {
+                        return false;
+                    }
+                }
+                return true;
+            }
         } catch (MessagingException e) {
             return false;
         }
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof FlagTerm == false) return false;
+        final FlagTerm otherFlags = (FlagTerm) other;
+        return otherFlags.set == this.set && otherFlags.flags.equals(flags);
+    }
+
+    public int hashCode() {
+        return flags.hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromStringTerm.java	Wed Jan 26
14:27:45 2005
@@ -32,11 +32,12 @@
     public boolean match(Message message) {
         try {
             Address from[] = message.getFrom();
-            boolean result = false;
-            for (int i = 0; !result && i < from.length; i++) {
-                result = match(from[i]);
+            for (int i = 0; i < from.length; i++) {
+                if (match(from[i])){
+                    return true;
+                }
             }
-            return result;
+            return false;
         } catch (MessagingException e) {
             return false;
         }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/FromTerm.java	Wed Jan 26 14:27:45
2005
@@ -32,11 +32,12 @@
     public boolean match(Message message) {
         try {
             Address from[] = message.getFrom();
-            boolean result = false;
-            for (int i = 0; !result && i < from.length; i++) {
-                result = match(from[i]);
+            for (int i = 0; i < from.length; i++) {
+                if (match(from[i])) {
+                    return true;
+                }
             }
-            return result;
+            return false;
         } catch (MessagingException e) {
             return false;
         }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/HeaderTerm.java	Wed Jan 26 14:27:45
2005
@@ -31,34 +31,34 @@
         this.headerName = header;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && ((HeaderTerm) other).headerName.equals(headerName);
-    }
-
     public String getHeaderName() {
         return headerName;
     }
 
-    public int hashCode() {
-        return super.hashCode() + headerName.hashCode();
-    }
-
     public boolean match(Message message) {
         try {
             String values[] = message.getHeader(headerName);
-            if (values == null || values.length == 0) {
-                return false;
-            } else {
-                boolean result = false;
-                for (int i = 0; !result && i < values.length; i++) {
+            if (values != null) {
+                for (int i = 0; i < values.length; i++) {
                     String value = values[i];
-                    result = match(value);
+                    if (match(value)) {
+                        return true;
+                    }
                 }
-                return result;
             }
+            return false;
         } catch (MessagingException e) {
             return false;
         }
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof HeaderTerm == false) return false;
+        return headerName.equalsIgnoreCase(((HeaderTerm) other).headerName);
+    }
+
+    public int hashCode() {
+        return headerName.toLowerCase().hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/IntegerComparisonTerm.java	Wed
Jan 26 14:27:45 2005
@@ -18,34 +18,54 @@
 package javax.mail.search;
 
 /**
+ * A Term that provides comparisons for integers.
+ *
  * @version $Rev$ $Date$
  */
 public abstract class IntegerComparisonTerm extends ComparisonTerm {
     protected int number;
 
     protected IntegerComparisonTerm(int comparison, int number) {
-        super(comparison);
+        super();
+        this.comparison = comparison;
         this.number = number;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && ((IntegerComparisonTerm) other).number == number;
+    public int getNumber() {
+        return number;
     }
 
     public int getComparison() {
-        return super.getComparison();
+        return comparison;
     }
 
-    public int getNumber() {
-        return number;
+    protected boolean match(int match) {
+        switch (comparison) {
+        case EQ:
+            return match == number;
+        case NE:
+            return match != number;
+        case GT:
+            return match > number;
+        case GE:
+            return match >= number;
+        case LT:
+            return match < number;
+        case LE:
+            return match <= number;
+        default:
+            return false;
+        }
     }
 
-    public int hashCode() {
-        return super.hashCode() + number * 47;
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof IntegerComparisonTerm == false) return false;
+        final IntegerComparisonTerm term = (IntegerComparisonTerm) other;
+        return this.comparison == term.comparison && this.number == term.number;
     }
 
-    protected boolean match(int match) {
-        return compare(number - match);
+    public int hashCode() {
+        return number;
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageIDTerm.java	Wed Jan 26
14:27:45 2005
@@ -31,16 +31,15 @@
     public boolean match(Message message) {
         try {
             String values[] = message.getHeader("Message-ID");
-            if (values == null || values.length == 0) {
-                return false;
-            } else {
-                boolean result = false;
-                for (int i = 0; !result && i < values.length; i++) {
+            if (values != null) {
+                for (int i = 0; i < values.length; i++) {
                     String value = values[i];
-                    result = match(value);
+                    if (match(value)) {
+                        return true;
+                    }
                 }
-                return result;
             }
+            return false;
         } catch (MessagingException e) {
             return false;
         }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/MessageNumberTerm.java	Wed Jan
26 14:27:45 2005
@@ -30,4 +30,8 @@
     public boolean match(Message message) {
         return match(message.getMessageNumber());
     }
+
+    public boolean equals(Object other) {
+        return super.equals(other);
+    }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/NotTerm.java	Wed Jan 26 14:27:45
2005
@@ -20,6 +20,8 @@
 import javax.mail.Message;
 
 /**
+ * Term that implements a logical negation.
+ *
  * @version $Rev$ $Date$
  */
 public final class NotTerm extends SearchTerm {
@@ -29,19 +31,21 @@
         this.term = term;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other) && ((NotTerm) other).term.equals(term);
-    }
-
     public SearchTerm getTerm() {
         return term;
     }
 
-    public int hashCode() {
-        return super.hashCode() + term.hashCode();
-    }
-
     public boolean match(Message message) {
         return !term.match(message);
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof NotTerm == false) return false;
+        return term.equals(((NotTerm) other).term);
+    }
+
+    public int hashCode() {
+        return term.hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/OrTerm.java	Wed Jan 26 14:27:45
2005
@@ -34,25 +34,31 @@
         this.terms = terms;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && Arrays.equals(terms, ((OrTerm) other).terms);
-    }
-
     public SearchTerm[] getTerms() {
         return terms;
     }
 
-    public int hashCode() {
-        return super.hashCode() + terms.length * 37;
-    }
-
     public boolean match(Message message) {
-        boolean result = false;
-        for (int i = 0; (!result) && i < terms.length; i++) {
+        for (int i = 0; i < terms.length; i++) {
             SearchTerm term = terms[i];
-            result = term.match(message);
+            if (term.match(message)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof OrTerm == false) return false;
+        return Arrays.equals(terms, ((OrTerm) other).terms);
+    }
+
+    public int hashCode() {
+        int hash = 0;
+        for (int i = 0; i < terms.length; i++) {
+            hash = hash * 37 + terms[i].hashCode();
         }
-        return result;
+        return hash;
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientStringTerm.java	Wed
Jan 26 14:27:45 2005
@@ -25,36 +25,40 @@
  * @version $Rev$ $Date$
  */
 public final class RecipientStringTerm extends AddressStringTerm {
-    private Message.RecipientType _type;
+    private Message.RecipientType type;
 
     public RecipientStringTerm(Message.RecipientType type, String pattern) {
         super(pattern);
-        this._type = type;
-    }
-
-    public boolean equals(Object other) {
-        return super.equals(other)
-                && ((RecipientStringTerm) other)._type == _type;
+        this.type = type;
     }
 
     public Message.RecipientType getRecipientType() {
-        return _type;
-    }
-
-    public int hashCode() {
-        return super.hashCode() + _type.hashCode();
+        return type;
     }
 
     public boolean match(Message message) {
         try {
-            Address from[] = message.getFrom();
-            boolean result = false;
-            for (int i = 0; !result && i < from.length; i++) {
-                result = match(from[i]);
+            Address from[] = message.getRecipients(type);
+            for (int i = 0; i < from.length; i++) {
+                Address address = from[i];
+                if (match(address)) {
+                    return true;
+                }
             }
-            return result;
+            return false;
         } catch (MessagingException e) {
             return false;
         }
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof RecipientStringTerm == false) return false;
+        final RecipientStringTerm otherTerm = (RecipientStringTerm) other;
+        return this.pattern.equals(otherTerm.pattern) && this.type == otherTerm.type;
+    }
+
+    public int hashCode() {
+        return pattern.hashCode();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java?view=diff&rev=126550&p1=geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java&r1=126549&p2=geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java&r2=126550
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java	(original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/search/RecipientTerm.java	Wed Jan 26
14:27:45 2005
@@ -32,28 +32,34 @@
         this.type = type;
     }
 
-    public boolean equals(Object other) {
-        return super.equals(other) && ((RecipientTerm) other).type.equals(type);
-    }
-
     public Message.RecipientType getRecipientType() {
         return type;
     }
 
-    public int hashCode() {
-        return super.hashCode() + type.hashCode();
-    }
-
     public boolean match(Message message) {
         try {
             Address from[] = message.getRecipients(type);
-            boolean result = false;
-            for (int i = 0; !result && i < from.length; i++) {
-                result = match(from[i]);
+            for (int i = 0; i < from.length; i++) {
+                Address address = from[i];
+                if (match(address)) {
+                    return true;
+                }
             }
-            return result;
+            return false;
         } catch (MessagingException e) {
             return false;
         }
+    }
+
+    public boolean equals(Object other) {
+        if (this == other) return true;
+        if (other instanceof RecipientTerm == false) return false;
+
+        final RecipientTerm recipientTerm = (RecipientTerm) other;
+        return address.equals(recipientTerm.address) && type == recipientTerm.type;
+    }
+
+    public int hashCode() {
+        return address.hashCode();
     }
 }

Mime
View raw message