View Javadoc
1   /*
2    * Copyright 2002-2013 the original author or authors.
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
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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   */
16  
17  package org.springframework.expression;
18  
19  /**
20   * Instances of a type comparator should be able to compare pairs of objects for equality.
21   * The specification of the return value is the same as for {@link java.lang.Comparable}.
22   *
23   * @author Andy Clement
24   * @since 3.0
25   * @see java.lang.Comparable
26   */
27  public interface TypeComparator {
28  
29  	/**
30  	 * Return {@code true} if the comparator can compare these two objects.
31  	 * @param firstObject the first object
32  	 * @param secondObject the second object
33  	 * @return {@code true} if the comparator can compare these objects
34  	 */
35  	boolean canCompare(Object firstObject, Object secondObject);
36  
37  	/**
38  	 * Compare two given objects.
39  	 * @param firstObject the first object
40  	 * @param secondObject the second object
41  	 * @return 0 if they are equal, <0 if the first is smaller than the second,
42  	 * or >0 if the first is larger than the second
43  	 * @throws EvaluationException if a problem occurs during comparison
44  	 * (or if they are not comparable in the first place)
45  	 */
46  	int compare(Object firstObject, Object secondObject) throws EvaluationException;
47  
48  }