KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > sps > jdbc > 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.jdbc;
20
21 import sync4j.syncclient.sps.common.*;
22
23 import java.util.Vector JavaDoc;
24
25 /**
26  * This interface implements methods
27  * about search filter in database
28  *
29  * @author Fabio Maggi @ Funambol
30  *
31  * $Id: FindFilter.java,v 1.3 2005/01/19 11:18:37 fabius Exp $
32  **/

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

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

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

55     public FindFilter (DataStore dataStore, Vector JavaDoc valueToFind, boolean include, boolean caseSensitive) {
56
57         this.dataStore = dataStore ;
58         this.valueToFind = valueToFind ;
59         this.include = include ;
60         this.caseSensitive = caseSensitive ;
61     }
62
63     //----------------------------------------------------------- Public methods
64

65     /**
66      * This method is about to check
67      * is record about criteria in dataStore
68      * @param record to check
69      * @return <code>true</code> if the record is accept about criteria
70      * <code>false</code> if the record is not accept about criteria
71      */

72     public boolean accept (Record record) {
73
74         boolean test = false;
75
76         String JavaDoc valueR = null;
77         String JavaDoc valueF = null;
78
79
80         for (int i=0, l = this.valueToFind.size(); i < l; i++) {
81
82             valueR = record.getString(i);
83             valueF = (String JavaDoc) this.valueToFind.elementAt(i);
84
85             if(include && caseSensitive && valueF.length() > 0
86                 && (valueR.toUpperCase().indexOf(valueF.toUpperCase()) != -1)) {
87                 test = true;
88                 break;
89             } else if(!include && caseSensitive && valueF.length() > 0
90                 && valueR.toUpperCase().equals(valueF.toUpperCase())) {
91                 test = true;
92                 break;
93             } else if(!include && !caseSensitive && valueF.length() > 0
94                 && valueR.equals(valueF)) {
95                 test = true;
96                 break;
97             } if(include && !caseSensitive && valueF.length() > 0
98                 && (valueR.indexOf(valueF) != -1)) {
99                 test = true;
100                 break;
101             }
102
103         }
104
105         return test;
106
107     }
108
109 }
Popular Tags