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.

Not.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /**
  8. * Negating filter that accepts the items rejected by another filter.
  9. *
  10. * This filter directly supports in-memory filtering when the negated filter
  11. * does so.
  12. *
  13. * @since 6.6
  14. */
  15. public final class Not implements Filter {
  16. private final Filter filter;
  17. /**
  18. * Constructs a filter that negates a filter.
  19. *
  20. * @param filter
  21. * {@link Filter} to negate, not-null
  22. */
  23. public Not(Filter filter) {
  24. this.filter = filter;
  25. }
  26. /**
  27. * Returns the negated filter.
  28. *
  29. * @return Filter
  30. */
  31. public Filter getFilter() {
  32. return filter;
  33. }
  34. public boolean passesFilter(Object itemId, Item item)
  35. throws UnsupportedOperationException {
  36. return !filter.passesFilter(itemId, item);
  37. }
  38. /**
  39. * Returns true if a change in the named property may affect the filtering
  40. * result. Return value is the same as {@link #appliesToProperty(Object)}
  41. * for the negated filter.
  42. *
  43. * @return boolean
  44. */
  45. public boolean appliesToProperty(Object propertyId) {
  46. return filter.appliesToProperty(propertyId);
  47. }
  48. @Override
  49. public boolean equals(Object obj) {
  50. if (obj == null || !getClass().equals(obj.getClass())) {
  51. return false;
  52. }
  53. return filter.equals(((Not) obj).getFilter());
  54. }
  55. @Override
  56. public int hashCode() {
  57. return filter.hashCode();
  58. }
  59. }