1 21 22 27 28 package javax.mail.search; 29 30 import javax.mail.Message ; 31 import javax.mail.Address ; 32 33 43 44 public final class RecipientStringTerm extends AddressStringTerm { 45 46 51 private Message.RecipientType type; 52 53 private static final long serialVersionUID = -8293562089611618849L; 54 55 61 public RecipientStringTerm(Message.RecipientType type, String pattern) { 62 super(pattern); 63 this.type = type; 64 } 65 66 69 public Message.RecipientType getRecipientType() { 70 return type; 71 } 72 73 81 public boolean match(Message msg) { 82 Address [] recipients; 83 84 try { 85 recipients = msg.getRecipients(type); 86 } catch (Exception e) { 87 return false; 88 } 89 90 if (recipients == null) 91 return false; 92 93 for (int i=0; i < recipients.length; i++) 94 if (super.match(recipients[i])) 95 return true; 96 return false; 97 } 98 99 102 public boolean equals(Object obj) { 103 if (!(obj instanceof RecipientStringTerm )) 104 return false; 105 RecipientStringTerm rst = (RecipientStringTerm )obj; 106 return rst.type.equals(this.type) && super.equals(obj); 107 } 108 109 112 public int hashCode() { 113 return type.hashCode() + super.hashCode(); 114 } 115 } 116 | Popular Tags |