01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package java.lang;
19:
20: /**
21: * This interface should be implemented by all classes which wish to define a
22: * <em>natural ordering</em> of their instances. The ordering rule must be
23: * transitive and invertible (i.e. the sign of the result of x.compareTo(y) must
24: * equal the negation of the sign of the result of y.compareTo(x) for all x and
25: * y).
26: * <p>
27: * In addition, it is desirable (but not required) that when the result of
28: * x.compareTo(y) is zero (and only then) the result of x.equals(y) should be
29: * true.
30: */
31: public interface Comparable<T> {
32:
33: /**
34: * Answers an integer indicating the relative positions of the receiver and
35: * the argument in the natural order of elements of the receiver's class.
36: *
37: *
38: * @return int which should be <0 if the receiver should sort before the
39: * argument, 0 if the receiver should sort in the same position as
40: * the argument, and >0 if the receiver should sort after the
41: * argument.
42: * @param another
43: * Object an object to compare the receiver to
44: * @throws ClassCastException
45: * if the argument can not be converted into something
46: * comparable with the receiver.
47: */
48: int compareTo(T another);
49: }
|