View Javadoc

1   /***
2    * StringComparisonOperator.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2002 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.filters;
27  
28  import java.security.InvalidParameterException;
29  import java.util.Hashtable;
30  
31  import org.jcreme.enumerations.Enumeration;
32  
33  /***
34   * This enumeration contains the operators that can be used in a string
35   * manipulation context to test the relation of two strings. As a subclass of
36   * the ComparisonOperator enumeration, values of this class are also registered
37   * as elements of the ComparisonOperator enumeration.
38   * 
39   * @author $Author: dbregeon $
40   * @version $Revision: 1.3 $
41   */
42  public class StringComparisonOperator extends ComparisonOperator {
43  	static final long serialVersionUID = -8575968610082456202L;
44  
45  	/***
46  	 * The StringComparisonOperator instances by their name.
47  	 */
48  	private static final Hashtable fromName = new Hashtable();
49  
50  	/***
51  	 * The name for the 'LIKE' enumeration value.
52  	 */
53  	public static final String S_LIKE = "LIKE";
54  
55  	/***
56  	 * The 'LIKE' enumeration value.
57  	 */
58  	public static final StringComparisonOperator LIKE = new StringComparisonOperator(
59  			S_LIKE);
60  
61  	/***
62  	 * The name for the 'NOT LIKE' enumeration value.
63  	 */
64  	public static final String S_NOT_LIKE = "NOT LIKE";
65  
66  	/***
67  	 * The 'NOT LIKE' enumeration value.
68  	 */
69  	public static final StringComparisonOperator NOT_LIKE = new StringComparisonOperator(
70  			S_NOT_LIKE);
71  
72  	/***
73  	 * Creates new StringComparisonOperator
74  	 * 
75  	 * @param name
76  	 *            the name of this enumerated value. It cannot be null.
77  	 * @throws InvalidParameterException
78  	 *             if the parameter is null.
79  	 */
80  	protected StringComparisonOperator(String name)
81  			throws InvalidParameterException {
82  		super(name);
83  		addAsComparisonOperator(this);
84  	}
85  
86  	/***
87  	 * This method is for internal use only.
88  	 * 
89  	 * @return the Hashtable that links the enumerated values names with the
90  	 *         actual enumerated value.
91  	 */
92  	protected Hashtable getFromName() {
93  		return fromName;
94  	}
95  
96  	/***
97  	 * This method retrieves an StringComparisonOperator instance from its name.
98  	 * 
99  	 * @param name
100 	 *            the name of the StringComparisonOperator instance.
101 	 * @return the StringComparisonOperator that has this name. Null if no value
102 	 *         corresponding to this name was found.
103 	 */
104 	public static StringComparisonOperator getStringComparisonOperator(
105 			final String name) {
106 		StringComparisonOperator result = null;
107 		if (name != null) {
108 			result = (StringComparisonOperator) fromName.get(name);
109 		}
110 		return result;
111 	}
112 
113 	/***
114 	 * This methods gives the instances of this class.
115 	 * 
116 	 * @return all the instances of this class.
117 	 */
118 	public static StringComparisonOperator[] getStringComparisonOperators() {
119 		return (StringComparisonOperator[]) fromName.values().toArray(
120 				new StringComparisonOperator[0]);
121 	}
122 
123 	/***
124 	 * This method enables to retrieve all the possible values of an Enumeration
125 	 * class.
126 	 * 
127 	 * @return the values for this class.
128 	 */
129 	public static Enumeration[] getValues() {
130 		return getStringComparisonOperators();
131 	}
132 }