KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > sps > common > FindFilter


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.sps.common;
20
21 import java.util.Vector JavaDoc;
22
23 import sync4j.syncclient.sps.common.*;
24
25
26 /**
27  * This interface implements methods
28  * about search filter in database
29  *
30  * @author Fabio Maggi @ Funambol
31  *
32  * $Id: FindFilter.java,v 1.3 2005/01/19 11:18:36 fabius Exp $
33  **/

34
35 public class FindFilter extends RecordFilter {
36
37
38     // ------------------------------------------------------------ Private data
39

40     private DataStore dataStore = null ;
41     private Vector JavaDoc valueToFind = null ;
42
43     private boolean include = false ;
44     private boolean caseSensitive = false ;
45
46     //------------------------------------------------------------- Constructors
47

48     /**
49      * @param dataStore dataStore name
50      * @param valueToFind vector contains fields value to find
51      * @param include <code>true</code> valueToFind fields contains in record fields,
52                       <code>false</code> valueToFind fields equals record fields
53
54      * @param caseSensitive <code>true</code> case sensitive find,
55      * <code>false</code> match case find
56      *
57      */

58
59     public FindFilter (DataStore dataStore, Vector JavaDoc valueToFind, boolean include, boolean caseSensitive) {
60
61         this.dataStore = dataStore ;
62         this.valueToFind = valueToFind ;
63         this.include = include ;
64         this.caseSensitive = caseSensitive ;
65
66     }
67
68     //----------------------------------------------------------- Public methods
69

70     /**
71      * This method is about to check
72      * is record about criteria in dataStore
73      * @param record to check
74      * @return <code>true</code> if the record is accept about criteria
75      * <code>false</code> if the record is not accept about criteria
76      */

77     public boolean accept (Record record) {
78
79         boolean test = false ;
80         String JavaDoc valueR = null ;
81         String JavaDoc valueF = null ;
82
83         for (int i=0, l = this.valueToFind.size(); i < l; i++) {
84
85             valueR = record.getString(i);
86
87             valueF = (String JavaDoc) this.valueToFind.elementAt(i);
88
89             if(include && caseSensitive && valueF.length() > 0
90                 && (valueR.toUpperCase().indexOf(valueF.toUpperCase()) != -1)) {
91
92                 test = true;
93
94                 break;
95
96             } else if(!include && caseSensitive && valueF.length() > 0
97                 && valueR.toUpperCase().equals(valueF.toUpperCase())) {
98
99                 test = true;
100
101                 break;
102
103             } else if(!include && !caseSensitive && valueF.length() > 0
104                 && valueR.equals(valueF)) {
105
106                 test = true;
107
108                 break;
109
110             } if(include && !caseSensitive && valueF.length() > 0
111                 && (valueR.indexOf(valueF) != -1)) {
112
113                 test = true;
114
115                 break;
116
117             }
118
119         }
120
121         return test;
122
123     }
124
125 }
Popular Tags