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.

IsNull.java 2.7KB

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