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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. import com.vaadin.data.Property;
  8. /**
  9. * Simple container filter checking whether an item property value is null.
  10. *
  11. * This filter also directly supports in-memory filtering.
  12. *
  13. * @since 6.6
  14. */
  15. public final class IsNull implements Filter {
  16. private final Object propertyId;
  17. /**
  18. * Constructor for a filter that compares the value of an item property with
  19. * null.
  20. *
  21. * For in-memory filtering, a simple == check is performed. For other
  22. * containers, the comparison implementation is container dependent but
  23. * should correspond to the in-memory null check.
  24. *
  25. * @param propertyId
  26. * the identifier (not null) of the property whose value to check
  27. */
  28. public IsNull(Object propertyId) {
  29. this.propertyId = propertyId;
  30. }
  31. @Override
  32. public boolean passesFilter(Object itemId, Item item)
  33. throws UnsupportedOperationException {
  34. final Property<?> p = item.getItemProperty(getPropertyId());
  35. if (null == p) {
  36. return false;
  37. }
  38. return null == p.getValue();
  39. }
  40. @Override
  41. public boolean appliesToProperty(Object propertyId) {
  42. return getPropertyId().equals(propertyId);
  43. }
  44. @Override
  45. public boolean equals(Object obj) {
  46. // Only objects of the same class can be equal
  47. if (!getClass().equals(obj.getClass())) {
  48. return false;
  49. }
  50. final IsNull o = (IsNull) obj;
  51. // Checks the properties one by one
  52. return (null != getPropertyId()) ? getPropertyId().equals(
  53. o.getPropertyId()) : null == o.getPropertyId();
  54. }
  55. @Override
  56. public int hashCode() {
  57. return (null != getPropertyId() ? getPropertyId().hashCode() : 0);
  58. }
  59. /**
  60. * Returns the property id of the property tested by the filter, not null
  61. * for valid filters.
  62. *
  63. * @return property id (not null)
  64. */
  65. public Object getPropertyId() {
  66. return propertyId;
  67. }
  68. }