1 21 22 27 28 package javax.mail.search; 29 30 import javax.mail.*; 31 32 38 public final class FlagTerm extends SearchTerm { 39 40 48 protected boolean set; 49 50 55 protected Flags flags; 56 57 private static final long serialVersionUID = -142991500302030647L; 58 59 65 public FlagTerm(Flags flags, boolean set) { 66 this.flags = flags; 67 this.set = set; 68 } 69 70 73 public Flags getFlags() { 74 return (Flags)flags.clone(); 75 } 76 77 80 public boolean getTestSet() { 81 return set; 82 } 83 84 90 public boolean match(Message msg) { 91 92 try { 93 Flags f = msg.getFlags(); 94 if (set) { if (f.contains(flags)) 96 return true; 97 else 98 return false; 99 } 100 101 104 Flags.Flag[] sf = flags.getSystemFlags(); 106 107 for (int i = 0; i < sf.length; i++) { 109 if (f.contains(sf[i])) 110 return false; 112 } 113 114 String [] s = flags.getUserFlags(); 115 116 for (int i = 0; i < s.length; i++) { 118 if (f.contains(s[i])) 119 return false; 121 } 122 123 return true; 124 125 } catch (Exception e) { 126 return false; 127 } 128 } 129 130 133 public boolean equals(Object obj) { 134 if (!(obj instanceof FlagTerm )) 135 return false; 136 FlagTerm ft = (FlagTerm )obj; 137 return ft.set == this.set && ft.flags.equals(this.flags); 138 } 139 140 143 public int hashCode() { 144 return set ? flags.hashCode() : ~flags.hashCode(); 145 } 146 } 147 | Popular Tags |