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 Created on 04.12.2004
25 *
26 * Contributing Author(s):
27 *
28 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital
29 * implementation) Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital
30 * implementation)
31 *
32 * @author vlads
33 * @version $Revision: 3 $ ($Author: vlads $) $Date: 2006-11-19 16:52:09 -0500
34 * (Sun, 19 Nov 2006) $
35 */
36 public abstract class MatchFilter implements Filter {
37
38 public final static int MATCH_EXCLUDE = -2;
39
40 public final static int MATCH_NO = -1;
41
42 // when filte disable the result would depen on oth items in the list.
43 public final static int MATCH_DONT_KNOW = 0;
44
45 public final static int MATCH_YES = 1;
46
47 public final static int MATCH_EXACT = 2;
48
49 /**
50 * conditional compilation set to false to allow compiler to identify and
51 * eliminate unreachable code
52 */
53 protected static final boolean debug = false;
54
55 /**
56 * a name use for debuging complex lists.
57 */
58 public String name = "n/a";
59
60 public abstract int matchState(Object obj);
61
62 public int notMatch(int state) {
63 if (state >= MATCH_YES) {
64 return MATCH_EXCLUDE;
65 } else {
66 return MATCH_YES;
67 }
68 }
69
70 public int b2Match(boolean isMatch) {
71 if (isMatch) {
72 return MATCH_YES;
73 } else {
74 return MATCH_NO;
75 }
76 }
77
78 public boolean isMatch(int state) {
79 if (state >= MATCH_YES) {
80 return true;
81 } else {
82 return false;
83 }
84 }
85
86 public abstract void debug();
87
88 public String match2String(int state) {
89 switch (state) {
90 case MATCH_EXCLUDE:
91 return "MATCH_EXCLUDE";
92 case MATCH_NO:
93 return "MATCH_NO";
94 case MATCH_DONT_KNOW:
95 return "MATCH_DONT_KNOW";
96 case MATCH_YES:
97 return "MATCH_YES";
98 case MATCH_EXACT:
99 return "MATCH_EXACT";
100 default:
101 return "MATCH_??" + state;
102
103 }
104 }
105 }