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.compexpr;
16:
17: import java.util.ArrayList;
18: import java.util.Iterator;
19: import java.util.List;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22: import org.araneaframework.backend.list.memorybased.ComparatorExpression;
23: import org.araneaframework.backend.list.memorybased.ExpressionEvaluationException;
24: import org.araneaframework.backend.list.memorybased.expression.VariableResolver;
25:
26: public class MultiComparatorExpression implements
27: CompositeComparatorExpression {
28:
29: private static final long serialVersionUID = 1L;
30:
31: private static final Log log = LogFactory
32: .getLog(MultiComparatorExpression.class);
33:
34: protected List children = new ArrayList();
35:
36: public ComparatorExpression add(ComparatorExpression expression) {
37: this .children.add(expression);
38: return this ;
39: }
40:
41: public ComparatorExpression[] getChildren() {
42: return (ComparatorExpression[]) this .children
43: .toArray(new ComparatorExpression[this .children.size()]);
44: }
45:
46: public int compare(VariableResolver resolver1,
47: VariableResolver resolver2)
48: throws ExpressionEvaluationException {
49: if (this .children.size() == 0) {
50: return 0;
51: }
52:
53: int result = 0;
54: for (Iterator i = this .children.iterator(); i.hasNext();) {
55: ComparatorExpression expr = (ComparatorExpression) i.next();
56: result = expr.compare(resolver1, resolver2);
57: if (result == 0) {
58: return 0;
59: }
60: }
61: return result;
62: }
63: }
|