1 /***
2 * Copyright 2003, 2004, 2005. CodeStreet LLC.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15 package com.codestreet.selector.parser;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 /***
21 * Class to represent <tt>immutable</tt> <tt>Bool</tt> literals.
22 *
23 * @author Jawaid Hakim.
24 */
25 final class LiteralBool implements IExpressionBool
26 {
27 /***
28 * Factory.
29 *
30 * @param literal
31 * Literal. Must be either <tt>true</tt>, or <tt>TRUE</tt>,
32 * or <tt>True</tt>, or <tt>false</tt>, or <tt>FALSE</tt>,
33 * or <tt<False</tt>.
34 * @return Instance.
35 * @throws java.lang.IllegalArgumentException
36 * Invalid literal.
37 */
38 public static synchronized LiteralBool valueOf(final String literal)
39 {
40 LiteralBool ret = (LiteralBool) idMap_.get(literal);
41 if (ret == null)
42 throw new IllegalArgumentException("Invalid literal: " + literal);
43 return ret;
44 }
45
46 /***
47 * Ctor.
48 *
49 * @param literal
50 * Literal.
51 */
52 private LiteralBool(final String literal)
53 {
54 literal_ = Boolean.valueOf(literal);
55 }
56
57 public Object eval(final Map identifiers)
58 {
59 return literal_;
60 }
61
62 public Object eval(final IValueProvider provider, final Object corr)
63 {
64 return literal_;
65 }
66
67 public String toString()
68 {
69 return literal_.toString();
70 }
71
72 private final Boolean literal_;
73
74 private static Map idMap_ = new HashMap();
75
76 static
77 {
78 LiteralBool literal = new LiteralBool("true");
79 idMap_.put("true", literal);
80 idMap_.put("TRUE", literal);
81 idMap_.put("True", literal);
82
83 literal = new LiteralBool("false");
84 idMap_.put("false", literal);
85 idMap_.put("FALSE", literal);
86 idMap_.put("False", literal);
87 }
88 }
This page was automatically generated by Maven