KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > filters > NotFilter


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2003 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/NotFilter.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2005/02/13 22:45:47 $
10
// $Revision: 1.3 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.filters;
28
29 import org.htmlparser.Node;
30 import org.htmlparser.NodeFilter;
31
32 /**
33  * Accepts all nodes not acceptable to it's predicate filter.
34  */

35 public class NotFilter implements NodeFilter
36 {
37     /**
38      * The filter to gainsay.
39      */

40     protected NodeFilter mPredicate;
41
42     /**
43      * Creates a new instance of a NotFilter.
44      * With no predicates, this would always return <code>false</code>
45      * from {@link #accept}.
46      * @see #setPredicate
47      */

48     public NotFilter ()
49     {
50         setPredicate (null);
51     }
52
53     /**
54      * Creates a new instance of NotFilter that accepts nodes not acceptable to the predicate filter.
55      * @param predicate The filter to consult.
56      */

57     public NotFilter (NodeFilter predicate)
58     {
59         setPredicate (predicate);
60     }
61
62     /**
63      * Get the predicate used by this NotFilter.
64      * @return The predicate currently in use.
65      */

66     public NodeFilter getPredicate ()
67     {
68         return (mPredicate);
69     }
70     
71     /**
72      * Set the predicate for this NotFilter.
73      * @param predicate The predidcate to use in {@link #accept}.
74      */

75     public void setPredicate (NodeFilter predicate)
76     {
77         mPredicate = predicate;
78     }
79
80     //
81
// NodeFilter interface
82
//
83

84     /**
85      * Accept nodes that are not acceptable to the predicate filter.
86      * @param node The node to check.
87      */

88     public boolean accept (Node node)
89     {
90         return ((null != mPredicate) && !mPredicate.accept (node));
91     }
92 }
93
Popular Tags