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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. @Override
  30. public boolean passesFilter(Object itemId, Item item)
  31. throws UnsupportedFilterException {
  32. for (Filter filter : getFilters()) {
  33. if (filter.passesFilter(itemId, item)) {
  34. return true;
  35. }
  36. }
  37. return false;
  38. }
  39. /**
  40. * Returns true if a change in the named property may affect the filtering
  41. * result. If some of the sub-filters are not in-memory filters, true is
  42. * returned.
  43. *
  44. * By default, all sub-filters are iterated to check if any of them applies.
  45. * If there are no sub-filters, true is returned as an empty Or rejects all
  46. * items.
  47. */
  48. @Override
  49. public boolean appliesToProperty(Object propertyId) {
  50. if (getFilters().isEmpty()) {
  51. // empty Or filters out everything
  52. return true;
  53. } else {
  54. return super.appliesToProperty(propertyId);
  55. }
  56. }
  57. }