You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Between.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.filter;
  5. import com.vaadin.data.Container.Filter;
  6. import com.vaadin.data.Item;
  7. public class Between implements Filter {
  8. private final Object propertyId;
  9. private final Comparable startValue;
  10. private final Comparable endValue;
  11. public Between(Object propertyId, Comparable startValue, Comparable endValue) {
  12. this.propertyId = propertyId;
  13. this.startValue = startValue;
  14. this.endValue = endValue;
  15. }
  16. public Object getPropertyId() {
  17. return propertyId;
  18. }
  19. public Comparable<?> getStartValue() {
  20. return startValue;
  21. }
  22. public Comparable<?> getEndValue() {
  23. return endValue;
  24. }
  25. public boolean passesFilter(Object itemId, Item item)
  26. throws UnsupportedOperationException {
  27. Object value = item.getItemProperty(getPropertyId()).getValue();
  28. if (value instanceof Comparable) {
  29. Comparable cval = (Comparable) value;
  30. return cval.compareTo(getStartValue()) >= 0
  31. && cval.compareTo(getEndValue()) <= 0;
  32. }
  33. return false;
  34. }
  35. public boolean appliesToProperty(Object propertyId) {
  36. return getPropertyId() != null && getPropertyId().equals(propertyId);
  37. }
  38. @Override
  39. public int hashCode() {
  40. return getPropertyId().hashCode() + getStartValue().hashCode()
  41. + getEndValue().hashCode();
  42. }
  43. @Override
  44. public boolean equals(Object obj) {
  45. // Only objects of the same class can be equal
  46. if (!getClass().equals(obj.getClass())) {
  47. return false;
  48. }
  49. final Between o = (Between) obj;
  50. // Checks the properties one by one
  51. boolean propertyIdEqual = (null != getPropertyId()) ? getPropertyId()
  52. .equals(o.getPropertyId()) : null == o.getPropertyId();
  53. boolean startValueEqual = (null != getStartValue()) ? getStartValue()
  54. .equals(o.getStartValue()) : null == o.getStartValue();
  55. boolean endValueEqual = (null != getEndValue()) ? getEndValue().equals(
  56. o.getEndValue()) : null == o.getEndValue();
  57. return propertyIdEqual && startValueEqual && endValueEqual;
  58. }
  59. }