1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.mail.search;
  6. import javax.mail.Message;
  7. /**
  8. * This class implements the logical NEGATION operator.
  9. *
  10. * @author Bill Shannon
  11. * @author John Mani
  12. */
  13. public final class NotTerm extends SearchTerm {
  14. /**
  15. * The search term to negate.
  16. *
  17. * @serial
  18. */
  19. protected SearchTerm term;
  20. public NotTerm(SearchTerm t) {
  21. term = t;
  22. }
  23. /**
  24. * Return the term to negate.
  25. */
  26. public SearchTerm getTerm() {
  27. return term;
  28. }
  29. /* The NOT operation */
  30. public boolean match(Message msg) {
  31. return !term.match(msg);
  32. }
  33. /**
  34. * Equality comparison.
  35. */
  36. public boolean equals(Object obj) {
  37. if (!(obj instanceof NotTerm))
  38. return false;
  39. NotTerm nt = (NotTerm)obj;
  40. return nt.term.equals(this.term);
  41. }
  42. /**
  43. * Compute a hashCode for this object.
  44. */
  45. public int hashCode() {
  46. return term.hashCode() << 1;
  47. }
  48. }