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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @Override
  26. public boolean passesFilter(Object itemId, Item item)
  27. throws UnsupportedOperationException {
  28. Object value = item.getItemProperty(getPropertyId()).getValue();
  29. if (value instanceof Comparable) {
  30. Comparable cval = (Comparable) value;
  31. return cval.compareTo(getStartValue()) >= 0
  32. && cval.compareTo(getEndValue()) <= 0;
  33. }
  34. return false;
  35. }
  36. @Override
  37. public boolean appliesToProperty(Object propertyId) {
  38. return getPropertyId() != null && getPropertyId().equals(propertyId);
  39. }
  40. @Override
  41. public int hashCode() {
  42. return getPropertyId().hashCode() + getStartValue().hashCode()
  43. + getEndValue().hashCode();
  44. }
  45. @Override
  46. public boolean equals(Object obj) {
  47. // Only objects of the same class can be equal
  48. if (!getClass().equals(obj.getClass())) {
  49. return false;
  50. }
  51. final Between o = (Between) obj;
  52. // Checks the properties one by one
  53. boolean propertyIdEqual = (null != getPropertyId()) ? getPropertyId()
  54. .equals(o.getPropertyId()) : null == o.getPropertyId();
  55. boolean startValueEqual = (null != getStartValue()) ? getStartValue()
  56. .equals(o.getStartValue()) : null == o.getStartValue();
  57. boolean endValueEqual = (null != getEndValue()) ? getEndValue().equals(
  58. o.getEndValue()) : null == o.getEndValue();
  59. return propertyIdEqual && startValueEqual && endValueEqual;
  60. }
  61. }