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.

Or.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. * A compound {@link Filter} that accepts an item if any of its filters accept
  9. * the item.
  10. *
  11. * If no filters are given, the filter should reject all items.
  12. *
  13. * This filter also directly supports in-memory filtering when all sub-filters
  14. * do so.
  15. *
  16. * @see And
  17. *
  18. * @since 6.6
  19. */
  20. public final class Or extends AbstractJunctionFilter {
  21. /**
  22. *
  23. * @param filters
  24. * filters of which the Or filter will be composed
  25. */
  26. public Or(Filter... filters) {
  27. super(filters);
  28. }
  29. public boolean passesFilter(Object itemId, Item item)
  30. throws UnsupportedFilterException {
  31. for (Filter filter : getFilters()) {
  32. if (filter.passesFilter(itemId, item)) {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. /**
  39. * Returns true if a change in the named property may affect the filtering
  40. * result. If some of the sub-filters are not in-memory filters, true is
  41. * returned.
  42. *
  43. * By default, all sub-filters are iterated to check if any of them applies.
  44. * If there are no sub-filters, true is returned as an empty Or rejects all
  45. * items.
  46. */
  47. @Override
  48. public boolean appliesToProperty(Object propertyId) {
  49. if (getFilters().isEmpty()) {
  50. // empty Or filters out everything
  51. return true;
  52. } else {
  53. return super.appliesToProperty(propertyId);
  54. }
  55. }
  56. }