View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.filter;
22  
23  /***
24   * TODO Add docs
25   * Created on 04.12.2004
26   *
27   * Contributing Author(s):
28   *
29   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
30   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
31   *
32   * @author vlads
33   * @version $Revision: 1.6 $ ($Author: vlads $) $Date: 2004/12/08 19:37:26 $
34   */
35  public abstract class MatchFilter implements Filter {
36  	
37  	public final static int MATCH_EXCLUDE = -1;
38  	public final static int MATCH_NO = 0;
39  	public final static int MATCH_YES = 1;
40  	public final static int MATCH_EXACT = 2;
41  	
42  	/***
43  	 * conditional compilation 
44  	 * set to false to allow compiler to identify and eliminate
45    	 * unreachable code
46  	 */
47  	protected static final boolean debug = false;
48  	
49  	/***
50  	 * a name use for debuging complex lists.
51  	 */
52  	public String name = "n/a";
53  	
54  	public abstract int matchState(Object obj);
55  	
56  	public int notMatch(int state) {
57  		if (state >= MATCH_YES) {
58  			return MATCH_EXCLUDE;
59  		} else {
60  			return MATCH_YES;
61  		}
62  	}
63  	
64  	public int b2Match(boolean isMatch) {
65          if (isMatch) {
66              return MATCH_YES;
67          } else {
68              return MATCH_NO;
69          }
70      }
71  	
72  	public boolean isMatch(int state) {
73  		if (state > MATCH_NO) {
74  			return true;
75  		} else {
76  			return false;
77  		}
78  	}
79  	
80  	public abstract void debug();
81  	
82  	public String match2String(int state) {
83  		switch(state) {
84  			case MATCH_EXCLUDE: return "MATCH_EXCLUDE";
85  			case MATCH_NO: return "MATCH_NO";
86  			case MATCH_YES: return "MATCH_YES";
87  			case MATCH_EXACT: return "MATCH_EXACT";
88  			default:
89  				return "MATCH_??" + state;
90  						
91  		}
92  	}
93  }