1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.expression;
18
19 /*** <p><code>ConstantExpression</code> represents a constant expression.</p>
20 *
21 * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
22 *
23 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
24 * @version $Revision: 438373 $
25 */
26 public class ConstantExpression implements Expression {
27
28 /*** The value of this expression */
29 private Object value;
30
31 /*** Base constructor
32 */
33 public ConstantExpression() {
34 }
35
36 /***
37 * Convenience constructor sets <code>value</code> property.
38 * @param value the Object which is the constant value for this expression
39 */
40 public ConstantExpression(Object value) {
41 this.value = value;
42 }
43
44 /***
45 * Evaluate expression against given context.
46 *
47 * @param context evaluate expression against this context
48 * @return current value of <code>value</code> property
49 */
50 public Object evaluate(Context context) {
51 return value;
52 }
53
54 /***
55 * Do nothing
56 * @see org.apache.commons.betwixt.expression.Expression
57 */
58 public void update(Context context, String newValue) {
59
60 }
61
62 /***
63 * Gets the constant value of this expression
64 * @return this expression's constant value
65 */
66 public Object getValue() {
67 return value;
68 }
69
70 /***
71 * Sets the constant value of this expression
72 * @param value the constant value for this expression
73 */
74 public void setValue(Object value) {
75 this.value = value;
76 }
77
78 /***
79 * Returns something useful for logging
80 * @return something useful for logging
81 */
82 public String toString() {
83 return "ConstantExpression [value=" + value + "]";
84 }
85 }