diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-03-16 12:45:32 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-03-16 12:45:32 +0000 |
commit | af6cd8310496185b2fe212c60ab85148adba1c7b (patch) | |
tree | d58c6345532df9980f16468f69d4755702b7bca7 /src/com/vaadin/data/util | |
parent | 07a7077cb9e7bdfe34534d03aaa50a11fd7d15f0 (diff) | |
download | vaadin-framework-af6cd8310496185b2fe212c60ab85148adba1c7b.tar.gz vaadin-framework-af6cd8310496185b2fe212c60ab85148adba1c7b.zip |
#6286 Container filtering improvements: IsNull filter
svn changeset:17812/svn branch:6.6
Diffstat (limited to 'src/com/vaadin/data/util')
-rw-r--r-- | src/com/vaadin/data/util/filter/IsNull.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/com/vaadin/data/util/filter/IsNull.java b/src/com/vaadin/data/util/filter/IsNull.java new file mode 100644 index 0000000000..5d8528c736 --- /dev/null +++ b/src/com/vaadin/data/util/filter/IsNull.java @@ -0,0 +1,68 @@ +package com.vaadin.data.util.filter; + +import com.vaadin.data.Container.Filter; +import com.vaadin.data.Item; +import com.vaadin.data.Property; + +/** + * Simple container filter checking whether an item property value is null. + * + * This filter also directly supports in-memory filtering. + * + * @since 6.6 + */ +public final class IsNull implements Filter { + + private final Object propertyId; + + /** + * Constructor for a filter that compares the value of an item property with + * null. + * + * For in-memory filtering, a simple == check is performed. For other + * containers, the comparison implementation is container dependent but + * should correspond to the in-memory null check. + * + * @param propertyId + * the identifier (not null) of the property whose value to check + */ + public IsNull(Object propertyId) { + this.propertyId = propertyId; + } + + public boolean passesFilter(Object itemId, Item item) + throws UnsupportedOperationException { + final Property p = item.getItemProperty(getPropertyId()); + if (null == p) { + return false; + } + return null == p.getValue(); + } + + public boolean appliesToProperty(Object propertyId) { + return this.propertyId == propertyId; + } + + @Override + public boolean equals(Object obj) { + // Only objects of the same class can be equal + if (!getClass().equals(obj.getClass())) { + return false; + } + final IsNull o = (IsNull) obj; + + // Checks the properties one by one + return (null != getPropertyId()) ? getPropertyId().equals( + o.getPropertyId()) : null == o.getPropertyId(); + } + + @Override + public int hashCode() { + return (null != getPropertyId() ? getPropertyId().hashCode() : 0); + } + + public Object getPropertyId() { + return propertyId; + } + +} |