View Javadoc

1   /***
2    * OrderComparisonOperator.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 sort context to
35   * test the order of two values. As a subclass of the ComparisonOperator
36   * enumeration, values of this class are also registered as elements of the
37   * ComparisonOperator enumeration.
38   * 
39   * @author $Author: dbregeon $
40   * @version $Revision: 1.3 $
41   */
42  public class OrderComparisonOperator extends ComparisonOperator {
43  	static final long serialVersionUID = 727691661331138205L;
44  
45  	/***
46  	 * The OrderComparisonOperator instances by their name.
47  	 */
48  	private static final Hashtable fromName = new Hashtable();
49  
50  	/***
51  	 * The name for the ' <' enumeration value.
52  	 */
53  	public static final String S_LESSER_THAN = "<";
54  
55  	/***
56  	 * The ' <' enumeration value.
57  	 */
58  	public static final OrderComparisonOperator LESSER_THAN = new OrderComparisonOperator(
59  			S_LESSER_THAN);
60  
61  	/***
62  	 * The name for the ' <=' enumeration value.
63  	 */
64  	public static final String S_LESSER_THAN_EQUAL = "<=";
65  
66  	/***
67  	 * The ' <=' enumeration value.
68  	 */
69  	public static final OrderComparisonOperator LESSER_THAN_EQUAL = new OrderComparisonOperator(
70  			S_LESSER_THAN_EQUAL);
71  
72  	/***
73  	 * The name for the '=' enumeration value.
74  	 */
75  	public static final String S_EQUAL = "=";
76  
77  	/***
78  	 * The '=' enumeration value.
79  	 */
80  	public static final OrderComparisonOperator EQUAL = new OrderComparisonOperator(
81  			S_EQUAL);
82  
83  	/***
84  	 * The name for the '!=' enumeration value.
85  	 */
86  	public static final String S_NOT_EQUAL = "!=";
87  
88  	/***
89  	 * The '!=' enumeration value.
90  	 */
91  	public static final OrderComparisonOperator NOT_EQUAL = new OrderComparisonOperator(
92  			S_NOT_EQUAL);
93  
94  	/***
95  	 * The name for the '>=' enumeration value.
96  	 */
97  	public static final String S_GREATER_THAN_EQUAL = ">=";
98  
99  	/***
100 	 * The '>=' enumeration value.
101 	 */
102 	public static final OrderComparisonOperator GREATER_THAN_EQUAL = new OrderComparisonOperator(
103 			S_GREATER_THAN_EQUAL);
104 
105 	/***
106 	 * The name for the '>' enumeration value.
107 	 */
108 	public static final String S_GREATER_THAN = ">";
109 
110 	/***
111 	 * The '>' enumeration value.
112 	 */
113 	public static final OrderComparisonOperator GREATER_THAN = new OrderComparisonOperator(
114 			S_GREATER_THAN);
115 
116 	/***
117 	 * Creates new OrderComparisonOperator
118 	 * 
119 	 * @param name
120 	 *            the name of this enumerated value. It cannot be null.
121 	 * @throws InvalidParameterException
122 	 *             if the parameter is null.
123 	 */
124 	protected OrderComparisonOperator(String name)
125 			throws InvalidParameterException {
126 		super(name);
127 		addAsComparisonOperator(this);
128 	}
129 
130 	/***
131 	 * This method is for internal use only.
132 	 * 
133 	 * @return the Hashtable that links the enumerated values names with the
134 	 *         actual enumerated value.
135 	 */
136 	protected Hashtable getFromName() {
137 		return fromName;
138 	}
139 
140 	/***
141 	 * This method retrieves an OrderComparisonOperator instance from its name.
142 	 * 
143 	 * @param name
144 	 *            the name of the OrderComparisonOperator instance.
145 	 * @return the OrderComparisonOperator that has this name. Null if no value
146 	 *         corresponding to this name was found.
147 	 */
148 	public static OrderComparisonOperator getOrderComparisonOperator(
149 			final String name) {
150 		OrderComparisonOperator result = null;
151 		if (name != null) {
152 			result = (OrderComparisonOperator) fromName.get(name);
153 		}
154 		return result;
155 	}
156 
157 	/***
158 	 * This methods gives the instances of this class.
159 	 * 
160 	 * @return all the instances of this class.
161 	 */
162 	public static OrderComparisonOperator[] getOrderComparisonOperators() {
163 		return (OrderComparisonOperator[]) fromName.values().toArray(
164 				new OrderComparisonOperator[0]);
165 	}
166 
167 	/***
168 	 * This method enables to retrieve all the possible values of an Enumeration
169 	 * class.
170 	 * 
171 	 * @return the values for this class.
172 	 */
173 	public static Enumeration[] getValues() {
174 		return getOrderComparisonOperators();
175 	}
176 }