KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > search > SearchModel


1 package com.ca.directory.jxplorer.search;
2
3 import java.io.*;
4 import java.util.*;
5 import java.util.logging.Logger JavaDoc;
6
7 import com.ca.commons.cbutil.*;
8 import com.ca.directory.jxplorer.*;
9
10 /**
11 * This class saves filters to and reads filters from the property file "search_filters.txt".
12 * A user specified title is appended to "JXFilter." to form the name the filter. For example
13 * "JXFilter.myFilter". Filters can be stored in this file as raw filters, for example
14 * "JXFilter.myFilter=(sn=f*)", or filters can be stored as groups of filters, for example
15 * "JXFilter.myNewFilter=!&JXFilter.myFilterJXFilter.myOtherFilter". In the last example you
16 * may notice the "!&" symbols at the beinging of the value. These tell us what joins the filters
17 * and if the filter has a 'not'. Possible combinations are: '!&', '!|', '&', '|' or nothing if there
18 * is only one filter.
19 * <p>
20 * This class also allows the saving of text filters (ones that the user types or pastes into the text
21 * filter tab). These differ from the prior two in that they may not follow the same syntax rules and
22 * therefore may not be able to be loaded into the build and/or join tabs. These types of filters are
23 * saved with the 'JXTextFilter' prefix.
24 */

25 public class SearchModel
26 {
27     public static ReturnAttributesDisplay rat =null;
28
29     protected Properties properties;
30     protected String JavaDoc localDir; //TE: the local directory where the property file is located.
31
protected ArrayList dependantFilters = new ArrayList();
32     protected ArrayList tempList = new ArrayList();
33     protected String JavaDoc searchFilterConfig; //CB: the name of the property file to save to.
34

35     static final String JavaDoc SEARCH_FILTER_FILENAME = "search_filters.txt"; //TE: the property file.
36
static final String JavaDoc NAME = "JXFilter."; //TE: the filter name prefix e.g. 'JXFilter.name'.\
37
static final String JavaDoc TEXTNAME = "JXTextFilter."; //TE: the filter name prefix e.g. 'JXTextFilter.name'.
38

39
40    /**
41     * A flag used to indicate build filters for example '(cn=f*)'.
42     */

43     public static final int BUILDFILTER = 1;
44     
45    /**
46     * A flag used to indicate all filters, not including 'JX' prefix.
47     */

48     public static final int ALLFILTERS = 2;
49     
50    /**
51     * A flag used to indicate join filters for example
52     * 'JXFilter.myFilter=!|JXFilter.aFilter1JXFilter.aFilter2'.
53     */

54     public static final int JOINFILTER = 3;
55     
56    /**
57     * A flag used to indicate text filters for example
58     * 'JXTextFilter.myFilter=(cn=f*)'.
59     */

60     public static final int TEXTFILTER = 4;
61     
62    /**
63     * A flag used to indicate all filters, including 'JX' prefix.
64     */

65     public static final int FULLNAMES = 5;
66
67    /**
68     * A flag used to indicate build and join filters only.
69     */

70     public static final int BUILDJOIN = 6;
71         
72    /**
73     * Name used to save the base DN in the property file.
74     */

75     public static final String JavaDoc BASEDN = "baseDN";
76     
77    /**
78     * Name used to save the return attribute list name in the property file.
79     */

80     public static final String JavaDoc RETATTRS = "retAttrs";
81     
82    /**
83     * Name used to save the search level in the property file.
84     */

85     public static final String JavaDoc SEARCHLEVEL = "searchLevel";
86     
87    /**
88     * Name used to save the state of the find alias check box in the property file.
89     */

90     public static final String JavaDoc FIND = "find";
91     
92    /**
93     * Name used to save the state of the find alias check box in the property file.
94     */

95     public static final String JavaDoc SEARCH = "search";
96
97     private static Logger JavaDoc log = Logger.getLogger(SearchModel.class.getName());
98
99
100    /**
101     * Constructor that sets up the property file.
102     */

103     public SearchModel()
104     {
105         properties = new Properties();
106
107         searchFilterConfig = CBUtility.getPropertyConfigPath(SEARCH_FILTER_FILENAME);
108
109         if (new File(searchFilterConfig).exists()==false) { log.info("no search filter config file found at: " + searchFilterConfig); return;}
110
111         properties = CBUtility.readPropertyFile(searchFilterConfig);
112
113         if (properties.size()==0) { log.info("Initialising config file: " + searchFilterConfig); return;}
114     }
115
116    /**
117     * Opens the Return Attributes Dialog.
118     * @param jx JXplorer (main frame).
119     * @param attrNames the names of the return attributes.
120     * @param ds the DataSource being used.
121     */

122     public void openRetAttrDisplay(JXplorer jx, String JavaDoc[] attrNames, DataSource ds)
123     {
124         rat = new ReturnAttributesDisplay(jx, attrNames);
125         rat.registerDataSource(ds);
126     }
127
128    /**
129     * Returns all of the filters in the property file "search_filters.txt".
130     * @return all of the filters in the property file "search_filters.txt".
131     */

132     protected Enumeration getAllFilters()
133     {
134         properties = CBUtility.readPropertyFile(searchFilterConfig);
135         return properties.propertyNames();
136     }
137
138    /**
139     * Returns an array list of the names from the property file (search_filters.txt) depending on the integer that is
140     * supplied as a parameter.
141     * @param type one of JOINFILTER, ALLFILTERS, BUILDFILTER, TEXTFILTER, FULLNAMES.
142     * @return the list of filter names.
143     */

144     public ArrayList getFilterNames(int type)
145     {
146         Enumeration list = getAllFilters();
147         ArrayList loadList = new ArrayList();
148         
149         while (list.hasMoreElements())
150         {
151             String JavaDoc temp = list.nextElement().toString();
152             
153             switch (type)
154             {
155                 case BUILDFILTER : { if (properties.get(temp).toString().startsWith("(") && temp.startsWith(NAME)) loadList.add(temp.substring(temp.indexOf(NAME)+9)); break; } //TE: get raw filter names.
156
case ALLFILTERS : { if (temp.startsWith(NAME)) loadList.add(temp.substring(temp.indexOf(NAME)+9)); else if (temp.startsWith(TEXTNAME)) loadList.add(temp.substring(temp.indexOf(NAME)+14)); break; } //TE: get all filter names, not including prefix.
157
case JOINFILTER : { if (!properties.get(temp).toString().startsWith("(") && temp.startsWith(NAME)) loadList.add(temp.substring(temp.indexOf(NAME)+9)); break; } //TE: get joined filter names.
158
case TEXTFILTER : { if (temp.startsWith(TEXTNAME)) loadList.add(temp.substring(temp.indexOf(NAME)+14)); break; }
159                 case FULLNAMES : { if(temp.startsWith(NAME) || temp.startsWith(TEXTNAME)) loadList.add(temp); break; } //TE: get all filter names, including prefix.
160
case BUILDJOIN : { if (temp.startsWith(NAME)) loadList.add(temp.substring(temp.indexOf(NAME)+9)); break; } //TE: get all build and join filters.
161
default: loadList.add("");
162             }
163         }
164         return loadList;
165     }
166
167    /**
168     * Returns the value from the property file of a given key. If the filter name prefix 'JXFilter.' isn't supplied with
169     * the name of the filter, it is inserted.
170     * @param name the key of the value that is being returned (can be either 'JXFilter.myFilter' or 'myFilter').
171     * @return the value of the key i.e. the filter.
172     */

173     public String JavaDoc getFilter(String JavaDoc name)
174     {
175         if(name.startsWith("JXFilter."))
176             return properties.getProperty(name); //TE: filter name prefix has been supplied.
177
else
178             return properties.getProperty(NAME+name); //TE: inserts the filter name prefix 'JXFilter'.
179
}
180
181    /**
182     * Returns the value from the property file of a given text filter.
183     * @param name the key of the value that is being returned (e.g. 'myFilter').
184     * @return the value of the key i.e. the filter.
185     */

186         public String JavaDoc getTextFilter(String JavaDoc name)
187     {
188         return properties.getProperty(TEXTNAME+name); //TE: inserts the filter name prefix 'JXTextFilter'.
189
}
190
191    /**
192     * Returns the LDAP filter for a given filter name. It expects the filter name prefix 'JXFilter.' or
193     * 'JXTextFilter' is included in the name of the filter.
194     * @param name the key of the value that is being returned (can be either 'JXFilter.myFilter' or 'JXTextFilter').
195     * @return the LDAP filter.
196     */

197     public String JavaDoc getLDAPFilter(String JavaDoc name)
198     {
199 // if(name.startsWith("!"))
200
// name = name.substring(1);
201
// if(name.startsWith("&"))
202
// name = name.substring(1);
203
// else if(name.startsWith("|"))
204
// name = name.substring(1); //TE: ???? why did I need this???
205

206         ArrayList list = getFilterNames(BUILDFILTER);
207
208         if (list.contains(name.substring(9)))
209             return properties.getProperty(name); //TE: is a raw filter.
210

211         list.clear();
212         
213         list = getFilterNames(JOINFILTER);
214
215         if (list.contains(name.substring(9)))
216             return getJoinFilter(properties.getProperty(name)); //TE: is a join filter.
217

218         list.clear();
219         
220         list = getFilterNames(TEXTFILTER);
221                             
222         return properties.getProperty(name); //TE: is a text filter.
223
}
224
225    /**
226     * Counts the number of times a substring occurs within a string.
227     * @param string the string that is getting checked for the occurence of a substring.
228     * @param substring the substring that is being checked for.
229     * @return the number of times the substring occurs within the string.
230     */

231     protected int getOccurences(String JavaDoc string, String JavaDoc substring)
232     {
233         int pos = -1;
234         int count = 0;
235         
236         while ((pos = string.indexOf(substring, pos+1))!=-1)
237             count++;
238  
239         return count;
240     }
241     
242    /**
243     * Returns an array list of the names of the filters that make up the supplied filter
244     * for example, 'aFilter1' & 'aFilter2' from '!|JXFilter.aFilter1JXFilter.aFilter2'.
245     * @param filter the filter value that we want to extract the subfilter names from for example,
246     * '!|JXFilter.aFilter1JXFilter.aFilter2'.
247     * @return the list of the subfilter names.
248     */

249     protected ArrayList getJoinFilterNames(String JavaDoc filter)
250     {
251         ArrayList list = new ArrayList();
252         String JavaDoc names;
253
254         int num = getOccurences(filter, "JXFilter");
255         
256         for(int i=0; i<num; i++)
257         {
258             try
259             {
260                 names = filter.substring(filter.indexOf(NAME)+9); //TE: make a substring of the filter from after the first '.' to the end of the filter for example 'aFilter1JXFilter.aFilter2'.
261
names = names.substring(0, names.indexOf(NAME)); //TE: make a substring of the name up to the first occurance of 'JXFilter.' for example 'aFilter1'.
262
}
263                 
264             catch(Exception JavaDoc e)
265             {
266                 names = filter.substring(filter.indexOf(NAME)+9); //TE: XXXXXX arr... there must have been a reason for this??
267
}
268             filter = filter.substring(filter.indexOf(names)+ names.length()); //TE: make a substring of the filter from the end of the last name.
269

270             list.add(names);
271         }
272     
273         return list;
274     }
275
276    /**
277     * Returns the raw filter of a filter that is created using the Join method.
278     * For example (!(&(cn=f*)(sn=f*)(|(cn=f*)(sn=f*)))).
279     * @param filter the filter value for example: '&JXFilter.myFilter1JXFilter.myFilter2'.
280     * @return the raw filter as a string for example: (!(&(cn=f*)(sn=f*)(|(cn=f*)(sn=f*)))).
281     */

282     protected String JavaDoc getJoinFilter(String JavaDoc filter)
283     {
284         StringBuffer JavaDoc buffy = new StringBuffer JavaDoc();
285         
286         getOperator(buffy, filter);
287
288         return buffy.toString();
289     }
290     
291    /**
292     * Takes a filter value for example '&JXFilter.myFilter1JXFilter.myFilter2' and appends the operator
293     * to the string buffer. In this example '&'. Other possible values are '!&', '!|'. '|' or nothing.
294     * Removes these values from the filter string then appends the value or raw filter for example '(cn=f*)'
295     * of each subfilter to the buffer.
296     * <br>The only filters that should use this method are filters that are NOT raw i.e filters that are a
297     * conbination of filters.<br>
298     * @param buffy the string buffer which is used to append the filter parts.
299     * @param filter e.g. '&JXFilter.myFilter1JXFilter.myFilter2'.
300     */

301     public void getOperator(StringBuffer JavaDoc buffy, String JavaDoc filter)
302     {
303         if (filter==null) { log.warning("Unexpected error in processing a search filter: no filter supplied."); return;}
304      
305         int count = 0; //TE: keeps count of the number of ')' to be appended at the end.
306
if (filter.startsWith("!"))
307         {
308             buffy.append("(!"); //TE: append '(!'.
309
count++;
310             filter = filter.substring(1); //TE: remove ! from beginning of filter.
311
}
312
313         if (filter.startsWith("&"))
314         {
315             buffy.append("(&"); //TE: append '(&'.
316
count++;
317             filter = filter.substring(1); //TE: remove & from beginning of filter.
318
}
319         else if (filter.startsWith("|"))
320         {
321             buffy.append("(|"); //TE: append '(|'.
322
count++;
323             filter = filter.substring(1); //TE: remove | from beginning of filter.
324
}
325
326         ArrayList list = getJoinFilterNames(filter); //TE: get the filter names in this filter.
327

328         String JavaDoc[] names = (String JavaDoc[])list.toArray(new String JavaDoc[list.size()]); //TE: convert the list array to a string array.
329

330         for (int i=0; i<names.length; i++)
331         {
332             String JavaDoc name = names[i];
333             getValue(buffy, name); //TE: get the filter value for each subfilter e.g, (cn=f*).
334
}
335
336         for(int i=0; i<count; i++)
337             buffy.append(")"); //TE: append ')'.
338
}
339
340    /**
341     * If a filter value is raw e.g. (cn=f*) this method appends the value to the string buffer other wise
342     * it calls the getOperator() method again in a recursive manner until the raw filter is reached.
343     * @param buffy the string buffer which is used to append the filter parts.
344     * @param filter e.g. 'JXFilter.myFilter1'.
345     */

346     protected void getValue(StringBuffer JavaDoc buffy, String JavaDoc filter)
347     {
348         ArrayList list = getFilterNames(BUILDFILTER);
349       
350         if (list.contains(filter)) //TE: if the filter is raw e.g. (cn=f*) append it to the buffer otherwise iterate the process.
351
{
352             buffy.append(getFilter(filter));
353         }
354         else
355         {
356             getOperator(buffy, getFilter(filter));
357         }
358     }
359
360    /**
361     * Returns true if the property file (search_filter.txt) contains the supplied
362     * filter.
363     * @param name the name of the filter for example, 'myfilter'. The method provides the filter
364     * name prefix 'JXFilter.'.
365     * @return true if the property file contains the filter, false otherwise.
366     */

367     protected boolean exists(String JavaDoc name)
368     {
369         if(properties.containsKey(NAME+name)) //TE: check if the filter (JXFilter.blah) name already exists, if so return true.
370
return true;
371         else if(properties.containsKey(TEXTNAME+name)) //TE: check if the filter (JXTextFilter.blah) name already exists, if so return true.
372
return true;
373         
374         return false;
375     }
376
377    /**
378     * Returns true if the given filter is a text filter by checking the property
379     * file for 'JXTextFilter+name'.
380     * @param name the name of the filter without the 'JXTextFilter' prefix.
381     * @return true if the filter is a text filter, false otherwise.
382     */

383     protected boolean isTextFilter(String JavaDoc name)
384     {
385         if(properties.containsKey(TEXTNAME+name))
386             return true;
387             
388         return false;
389     }
390
391    /**
392     * Saves a filter to the property file 'search_filter.txt'. The name of the filter is added to the filter name prefix
393     * 'JXFilter.' e.g. 'JXFilter.myFilter1'. Saves either a raw filter e.g. 'JXFilter.myFilter1=(cn=f*)' or a combination of
394     * filters e.g.'JXFilter.myFilter1=&JXFilter.myFilter2JXFilter.myFilter3'
395     * @param name the name of the filter e.g. 'myFilter'. The filter name prefix is added to this before saving.
396     * The saved name should look like: 'JXFilter.myFilter".
397     * @param filter the value that is being saved e.g. (cn=f*) or '&JXFilter.myFilter2JXFilter.myFilter3'.
398     */

399     protected void saveFilter(String JavaDoc name, String JavaDoc filter)
400     {
401         properties.setProperty(NAME+name, filter);
402         CBUtility.writePropertyFile(searchFilterConfig, properties, "");
403     }
404
405    /**
406     * Saves a text filter to the property file 'search_filter.txt'. The name of the filter is added to the filter name prefix
407     * 'JXTextFilter.' e.g. 'JXFilter.myFilter1=(cn=f*)'.
408     * @param name the name of the filter e.g. 'myFilter'. The filter name prefix is added to this before saving.
409     * The saved name should look like: 'JXTextFilter.myFilter".
410     * @param filter the value that is being saved e.g. (cn=f*).
411     */

412     protected void saveTextFilter(String JavaDoc name, String JavaDoc filter)
413     {
414         properties.setProperty(TEXTNAME+name, filter);
415         CBUtility.writePropertyFile(searchFilterConfig, properties, "");
416     }
417
418    /**
419     * Saves the given value to the property file with the name of the filter
420     * and the type of item as the key (e.g. name.baseDN=whatever).
421     * @param name the name of the filter (without the JXFilter prefix).
422     * @param type of value being saved (baseDN, retAttrs).
423     * @param value
424     */

425     protected void saveValue(String JavaDoc name, String JavaDoc type, String JavaDoc value)
426     {
427         properties.setProperty(name+"."+type, value);
428         CBUtility.writePropertyFile(searchFilterConfig, properties, "");
429     }
430
431    /**
432     * Saves the search level to the property file ('search_filters.txt') as name.searchLevel.
433     * @param name the name of the filter (without the JXFilter prefix).
434     * @param searchLevel the search level that the user wants saved with the filter.
435     */

436     protected void saveSearchLevel(String JavaDoc name, int searchLevel)
437     {
438         properties.setProperty(name+"."+SEARCHLEVEL, Integer.toString(searchLevel));
439         CBUtility.writePropertyFile(searchFilterConfig, properties, "");
440     }
441     
442    /**
443     * Saves the search level to the property file ('search_filters.txt') as name.searchLevel.
444     * @param name the name of the filter (without the JXFilter prefix).
445     * @param aliasType the type of alias handling ('finding' etc.).
446     */

447     protected void saveAlias(String JavaDoc name, String JavaDoc aliasType, boolean state)
448     {
449         if(state)
450             properties.setProperty(name+"."+aliasType, "true");
451         else
452             properties.setProperty(name+"."+aliasType, "false");
453                 
454         CBUtility.writePropertyFile(searchFilterConfig, properties, "");
455     }
456     
457    /**
458     * Returns the value associated with the key from the property file.
459     * This does a pure look up regardless of filter prefixes like JXFilter.
460     * @param key the key which we want the value returned (this is the actual
461     * key that we will use to look in the property file i.e. no modification
462     * is done to it.
463     * @return the value that the key stores (null if not present).
464     */

465     public String JavaDoc getValue(String JavaDoc key)
466     {
467         if(properties.containsKey(key))
468             return properties.getProperty(key);
469         
470         return null;
471     }
472
473    /**
474     * Checks if the property file contains the value. If it does it gets the
475     * key for that value and checks if the key contains 'retAttrs'. If it does
476     * the entry is removed from the property file.
477     * @param value the value that we are looking in the property file for in order to delete its entry.
478     */

479     protected void removeRetAttrs(String JavaDoc value)
480     {
481         if(properties.containsValue(value))
482         {
483             Enumeration en = properties.propertyNames();
484             while (en.hasMoreElements())
485             {
486                 String JavaDoc temp = (en.nextElement()).toString();
487                 if (temp.indexOf(RETATTRS)>-1)
488                 {
489                     if(((properties.get(temp)).toString()).equalsIgnoreCase(value))
490                         properties.remove(temp);
491                 }
492             }
493
494             CBUtility.writePropertyFile(searchFilterConfig, properties, "");
495         }
496     }
497
498    /**
499     * Removes an array of filters from the property file search_filters.txt.
500     * @param filterNames the array of filters names (keys) to be removed (deleted).
501     */

502     protected void removeFilters(String JavaDoc[] filterNames)
503     {
504         for(int i=0;i<filterNames.length;i++)
505         {
506             removeFilter(filterNames[i]);
507         }
508     }
509
510    /**
511     * Removes a filter from the property file search_filters.txt.
512     * @param filterName the filter name (key) to be removed (deleted). Expects the filter prefix.
513     */

514     protected void removeFilter(String JavaDoc filterName)
515     {
516         properties.remove(filterName);
517
518         String JavaDoc name = filterName.startsWith(NAME)? filterName.substring(9) : filterName.substring(13);
519
520         Enumeration en = properties.propertyNames();
521         while (en.hasMoreElements())
522         {
523             String JavaDoc temp = (en.nextElement()).toString();
524             if(temp.startsWith(name))
525                 properties.remove(temp);
526         }
527         
528         CBUtility.writePropertyFile(searchFilterConfig, properties, "");
529     }
530
531    /**
532     * Returns an Array List of filters that depend on the filter that the user is trying to delete,
533     * and any filters that depend on those filters and so on.
534     * @param filterName the name of the filter that the user wants to delete.
535     * @return the list of all dependand filters (filters that use this filter directly or indirectly).
536     */

537     protected ArrayList getDependants(Object JavaDoc filterName)
538     {
539         dependantFilters.clear(); //TE: clear the global Array Lists.
540
tempList.clear();
541         
542         if (!dependantFilters.contains(filterName)) //TE: make sure the filter being deleted is added to the list.
543
dependantFilters.add(NAME+filterName);
544         getDependantFilters(NAME+filterName);
545         
546         return dependantFilters;
547     }
548     
549    /**
550     * This method tries to determine if there are any filters that use the filter that is supplied
551     * as a parameter. The filters are constructed in a way that any one filter can be used by any
552     * other filters to make new filters. Therefore deleting a filter can have a cascading effect of
553     * rendering other filters useless.
554     * <p>
555     * This method searches all of the values from the property file 'search_filter.txt', to see if any
556     * contain the filter name. If so the name of that filter (or the key) is saved in an Array List.
557     * The process is repeated for each one of these saved keys.</p>
558     * <p>
559     * NOTE: Text filters don't have dependant filters.
560     * @param filterName the name of the filter that is being checked for dependant filters.
561     */

562     protected void getDependantFilters(Object JavaDoc filterName)
563     { //TE: key=value.
564
Collection col = properties.values(); //TE: get all the values from the property file.
565
Object JavaDoc[] allValues = col.toArray(); //TE: make them usable.
566

567         for(int i=0;i<allValues.length;i++)
568         {
569             if (allValues[i].toString().indexOf(filterName.toString())>-1)
570             {
571                 String JavaDoc temp = getKeyForValue(allValues[i].toString()); //TE: get the key for the value.
572

573                 if (!temp.equalsIgnoreCase(""))
574                 {
575                     if (!dependantFilters.contains(temp)) //TE: add this to the list of filters that need to be deleted. && !dependantFilters.contains(temp)) //TE: add this to the list of filters that need to be deleted.
576
{
577                         dependantFilters.add(temp);
578                         tempList.add(temp);
579                         getDependantFilters(temp); //TE: check this filter for any dependant filters.
580
}
581                 }
582             }
583         }
584     }
585     
586    /**
587     * Gets an enumeration of keys from the property list where the search filters are stored,
588     * then puts these keys into a string array. It then extracts the value of each of these keys
589     * from the property file until it finds one that matches the supplied value. In short, this
590     * method returns the key of the value supplied.
591     * @param value the value whose key we want returned.
592     * @return the key of the supplied value (returns and empty string if no key is found).
593     */

594     protected String JavaDoc getKeyForValue(String JavaDoc value)
595     {
596         String JavaDoc[] allKeys = new String JavaDoc[properties.size()];
597         Enumeration en = properties.propertyNames();
598         int counter =0;
599         
600         while (en.hasMoreElements())
601         {
602             allKeys[counter]= (en.nextElement()).toString(); //TE: get all of the values from the enumeration and store them in the string array.
603
counter++;
604         }
605                 
606         for(int i=0;i<allKeys.length;i++)
607         {
608             if(properties.getProperty(allKeys[i]).equalsIgnoreCase(value) && !tempList.contains(allKeys[i])) //TE: find which key has the supplied value and return it.
609
return allKeys[i];
610         }
611             
612         return "";
613     }
614
615    /**
616     * This Comparator compares two case ignore Strings.
617     * @author Trudi.
618     */

619     public static class StringComparator implements Comparator
620     {
621        /**
622         * This Comparator compares two case ignore Strings.
623         * @param o1 one of the two items to be compared.
624         * @param o2 the other of the items to be compared.
625         * @return the result of the compare (0 if the strings of o1 & o2 are equal, -1 if o1 < o2, 1 if o1 > o2).
626         *
627         */

628         public int compare(Object JavaDoc o1, Object JavaDoc o2)
629         {
630             return ((String JavaDoc)o1).compareToIgnoreCase((String JavaDoc)o2);
631         }
632     }
633 }
Popular Tags