From 42787665b1d4d0fc59a8c3c0b875dbbe021e73ab Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Mon, 14 Mar 2011 10:27:31 +0000 Subject: #6286 Container filtering improvements: Not (negation) filter and unit test svn changeset:17750/svn branch:6.6 --- src/com/vaadin/data/util/filter/Not.java | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/com/vaadin/data/util/filter/Not.java (limited to 'src') 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(); + } + +} -- cgit v1.2.3