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 comparisons for Message sizes.
  9. *
  10. * @author Bill Shannon
  11. * @author John Mani
  12. */
  13. public final class SizeTerm extends IntegerComparisonTerm {
  14. /**
  15. * Constructor.
  16. *
  17. * @param comparison the Comparison type
  18. * @param size the size
  19. */
  20. public SizeTerm(int comparison, int size) {
  21. super(comparison, size);
  22. }
  23. /**
  24. * The match method.
  25. *
  26. * @param msg the size comparator is applied to this Message's size
  27. * @return true if the size is equal, otherwise false
  28. */
  29. public boolean match(Message msg) {
  30. int size;
  31. try {
  32. size = msg.getSize();
  33. } catch (Exception e) {
  34. return false;
  35. }
  36. if (size == -1)
  37. return false;
  38. return super.match(size);
  39. }
  40. /**
  41. * Equality comparison.
  42. */
  43. public boolean equals(Object obj) {
  44. if (!(obj instanceof SizeTerm))
  45. return false;
  46. return super.equals(obj);
  47. }
  48. }