KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > util > strainer > NotFilter


1 /*
2  * $Id: NotFilter.java,v 1.2 2006/05/21 05:14:23 cburkey Exp $
3  */

4 package com.openedit.util.strainer;
5
6 /**
7  * This class implements the inverse of its sub-filter.
8  *
9  * @author Eric Galluzzo
10  */

11 public class NotFilter implements DecoratorFilter
12 {
13     protected Filter fieldFilter = null;
14
15     /**
16      * This constructor should only be used for JavaBean-style creation.
17      */

18     public NotFilter()
19     {
20     }
21
22     /**
23      * Create a filter that inverts the given sub-filter.
24      *
25      * @param inFilter The filter to invert
26      */

27     public NotFilter(Filter inFilter)
28     {
29         fieldFilter = inFilter;
30     }
31
32     /**
33      * Retrieve this filter's sub-filter.
34      *
35      * @return This filter's sub-filter
36      */

37     public Filter getFilter()
38     {
39         return fieldFilter;
40     }
41
42     /* (non-Javadoc)
43      * @see com.openedit.util.strainer.Filter#getFilters()
44      */

45     public Filter[] getFilters()
46     {
47         Filter[] array = new Filter[1];
48         array[0] = fieldFilter;
49         return array;
50     }
51
52     /**
53      * Set this filter's sub-filter.
54      *
55      * @param newFilter The new filter
56      */

57     public void setFilter(Filter newFilter)
58     {
59         fieldFilter = newFilter;
60     }
61
62     /**
63      * Determine whether the given object passes this filter by returning the
64      * opposite of its sub-filter.
65      *
66      * @param inObj The object to check
67      *
68      * @return <code>true</code> if the object passes, <code>false</code>
69      * otherwise.
70      *
71      * @exception FilterException
72      * If some error occurs while filtering
73      * @exception ClassCastException
74      * If the given object is not of the expected type
75      */

76     public boolean passes(Object JavaDoc inObj) throws FilterException, ClassCastException JavaDoc
77     {
78         if ( fieldFilter == null)
79         {
80             return false;
81         }
82         return !fieldFilter.passes(inObj);
83     }
84
85     /* (non-Javadoc)
86      * @see com.openedit.util.strainer.Filter#accept(com.openedit.util.strainer.FilterVisitor)
87      */

88     public void accept(FilterVisitor inFilterVisitor) throws FilterException
89     {
90         if (inFilterVisitor instanceof NotFilterVisitor)
91         {
92             ((NotFilterVisitor) inFilterVisitor).visitNotFilter(this);
93         }
94     }
95
96     /* (non-Javadoc)
97      * @see java.lang.Object#toString()
98      */

99     public String JavaDoc toString()
100     {
101         return "not (" + getFilter().toString() + ")";
102     }
103 }
104
Popular Tags