01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.backend.list.memorybased.expression.compare;
16:
17: import org.araneaframework.backend.list.memorybased.Expression;
18: import org.araneaframework.backend.list.memorybased.ExpressionEvaluationException;
19: import org.araneaframework.backend.list.memorybased.expression.CompositeExpression;
20: import org.araneaframework.backend.list.memorybased.expression.VariableResolver;
21:
22: public class EqualsExpression implements CompositeExpression {
23:
24: private static final long serialVersionUID = 1L;
25:
26: protected Expression expr1;
27:
28: protected Expression expr2;
29:
30: public EqualsExpression(Expression expr1, Expression expr2) {
31: if (expr1 == null || expr2 == null) {
32: throw new IllegalArgumentException(
33: "Operands must be provided");
34: }
35: this .expr1 = expr1;
36: this .expr2 = expr2;
37: }
38:
39: public Object evaluate(VariableResolver resolver)
40: throws ExpressionEvaluationException {
41: Object value1 = this .expr1.evaluate(resolver);
42: Object value2 = this .expr2.evaluate(resolver);
43: return (value1 == null ? value2 == null : value1.equals(value2)) ? Boolean.TRUE
44: : Boolean.FALSE;
45: }
46:
47: public Expression[] getChildren() {
48: return new Expression[] { this.expr1, this.expr2 };
49: }
50: }
|