diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-03-14 10:27:31 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-03-14 10:27:31 +0000 |
commit | 42787665b1d4d0fc59a8c3c0b875dbbe021e73ab (patch) | |
tree | e1b0a38440ce52bcbe36a644c885b0c79b76b566 /src | |
parent | fe2e938d2d14b7906f7c7317115c5bf31b49e973 (diff) | |
download | vaadin-framework-42787665b1d4d0fc59a8c3c0b875dbbe021e73ab.tar.gz vaadin-framework-42787665b1d4d0fc59a8c3c0b875dbbe021e73ab.zip |
#6286 Container filtering improvements: Not (negation) filter and unit test
svn changeset:17750/svn branch:6.6
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/data/util/filter/Not.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/com/vaadin/data/util/filter/Not.java b/src/com/vaadin/data/util/filter/Not.java new file mode 100644 index 0000000000..0e2ec4c55e --- /dev/null +++ b/src/com/vaadin/data/util/filter/Not.java @@ -0,0 +1,64 @@ +package com.vaadin.data.util.filter; + +import com.vaadin.data.Container.Filter; +import com.vaadin.data.Item; + +/** + * Negating filter that accepts the items rejected by another filter. + * + * This filter directly supports in-memory filtering when the negated filter + * does so. + * + * @since 6.6 + */ +public class Not implements Filter { + private final Filter filter; + + /** + * Constructs a filter that negates a filter. + * + * @param filter + * {@link Filter} to negate, not-null + */ + public Not(Filter filter) { + this.filter = filter; + } + + /** + * Returns the negated filter. + * + * @return Filter + */ + public Filter getFilter() { + return filter; + } + + public boolean passesFilter(Item item) throws UnsupportedOperationException { + return !filter.passesFilter(item); + } + + /** + * Returns true if a change in the named property may affect the filtering + * result. Return value is the same as {@link #appliesToProperty(Object)} + * for the negated filter. + * + * @return boolean + */ + public boolean appliesToProperty(Object propertyId) { + return filter.appliesToProperty(propertyId); + } + + @Override + public boolean equals(Object obj) { + if (obj == null || !getClass().equals(obj.getClass())) { + return false; + } + return filter.equals(((Not) obj).getFilter()); + } + + @Override + public int hashCode() { + return filter.hashCode(); + } + +} |