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.Comparator;
18: import org.araneaframework.backend.list.memorybased.ComparatorExpression;
19: import org.araneaframework.backend.list.memorybased.Variable;
20: import org.araneaframework.backend.list.memorybased.expression.VariableResolver;
21:
22: public class VariableComparatorExpression implements
23: ComparatorExpression, Variable {
24:
25: private static final long serialVersionUID = 1L;
26:
27: protected String name;
28:
29: protected Comparator comparator;
30:
31: public VariableComparatorExpression(String name,
32: Comparator comparator) {
33: if (name == null) {
34: throw new RuntimeException("Name must be provided");
35: }
36: if (comparator == null) {
37: throw new RuntimeException("Comparator must be provided");
38: }
39: this .name = name;
40: this .comparator = comparator;
41: }
42:
43: public String getName() {
44: return this .name;
45: }
46:
47: public Comparator getComparator() {
48: return this .comparator;
49: }
50:
51: public int compare(VariableResolver resolver1,
52: VariableResolver resolver2) {
53: Object value1 = resolver1.resolve(this );
54: Object value2 = resolver2.resolve(this );
55: int result = this.comparator.compare(value1, value2);
56: return result;
57: }
58: }
|