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 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.data.util.filter;
  17. import com.vaadin.data.Container.Filter;
  18. import com.vaadin.data.Item;
  19. /**
  20. * Negating filter that accepts the items rejected by another filter.
  21. *
  22. * This filter directly supports in-memory filtering when the negated filter
  23. * does so.
  24. *
  25. * @since 6.6
  26. */
  27. public final class Not implements Filter {
  28. private final Filter filter;
  29. /**
  30. * Constructs a filter that negates a filter.
  31. *
  32. * @param filter
  33. * {@link Filter} to negate, not-null
  34. */
  35. public Not(Filter filter) {
  36. this.filter = filter;
  37. }
  38. /**
  39. * Returns the negated filter.
  40. *
  41. * @return Filter
  42. */
  43. public Filter getFilter() {
  44. return filter;
  45. }
  46. @Override
  47. public boolean passesFilter(Object itemId, Item item)
  48. throws UnsupportedOperationException {
  49. return !filter.passesFilter(itemId, item);
  50. }
  51. /**
  52. * Returns true if a change in the named property may affect the filtering
  53. * result. Return value is the same as {@link #appliesToProperty(Object)}
  54. * for the negated filter.
  55. *
  56. * @return boolean
  57. */
  58. @Override
  59. public boolean appliesToProperty(Object propertyId) {
  60. return filter.appliesToProperty(propertyId);
  61. }
  62. @Override
  63. public boolean equals(Object obj) {
  64. if (obj == null || !getClass().equals(obj.getClass())) {
  65. return false;
  66. }
  67. return filter.equals(((Not) obj).getFilter());
  68. }
  69. @Override
  70. public int hashCode() {
  71. return filter.hashCode();
  72. }
  73. }