1 /***
2 * ComparisonOperator.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 handles the comparison operators that may be used in
35 * Filters. This class is subclassed to reflect the specialization of the
36 * operators (on Double, Date, ...).
37 *
38 * @author $Author: dbregeon $
39 * @version $Revision: 1.3 $
40 */
41 public class ComparisonOperator extends Enumeration {
42 static final long serialVersionUID = 9181399589148627958L;
43
44 /***
45 * The ComparisonOperator instances by their name.
46 */
47 private static final Hashtable fromName = new Hashtable();
48
49 /***
50 * Creates new ComparisonOperator
51 *
52 * @param name
53 * the name of this enumerated value. It cannot be null.
54 * @throws InvalidParameterException
55 * if nam is null.
56 */
57 protected ComparisonOperator(String name) throws InvalidParameterException {
58
59 super(name);
60 }
61
62 /***
63 * This convenience method should be used by subclasses to register their
64 * own elements as elements of the ComparisonOperator enumeration.
65 *
66 * @param cmp
67 * a ComparisonOperator to put in this Enumeration.
68 */
69 protected void addAsComparisonOperator(final ComparisonOperator cmp) {
70 if (get(cmp.getName()) == null) {
71
72 fromName.put(getName(), this);
73 }
74 }
75
76 /***
77 * This method is for internal use only.
78 *
79 * @return the Hashtable that links the enumerated values names with the
80 * actual enumerated value.
81 */
82 protected Hashtable getFromName() {
83 return fromName;
84 }
85
86 /***
87 * This method retrieves a ComparisonOperator instance from its name.
88 *
89 * @param name
90 * the name of the ComparisonOperator instance.
91 * @return the ComparisonOperator that has this name. Null if no value
92 * corresponding to this name was found.
93 */
94 public static ComparisonOperator get(final String name) {
95 ComparisonOperator result = null;
96 if (name != null) {
97 result = (ComparisonOperator) fromName.get(name);
98 }
99 return result;
100 }
101
102 /***
103 * This methods gives the instances of this class.
104 *
105 * @return all the instances of this class.
106 */
107 public static ComparisonOperator[] getComparisonOperators() {
108 return (ComparisonOperator[]) fromName.values().toArray(
109 new ComparisonOperator[0]);
110 }
111
112 /***
113 * This method enables to retrieve all the possible values of an Enumeration
114 * class.
115 *
116 * @return the values for this class.
117 */
118 public static Enumeration[] getValues() {
119 return getComparisonOperators();
120 }
121 }