01: /* Comparables.java
02:
03: {{IS_NOTE
04:
05: Purpose:
06: Description:
07: History:
08: 2001/11/23, Henri Chen: Created.
09:
10: }}IS_NOTE
11:
12: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19:
20: package org.zkoss.lang;
21:
22: /**
23: * Utilities regarding Comparable type objects.
24: *
25: * @author henrichen
26: */
27: public final class Comparables {
28: /**
29: * Given two comparables, return the minimum of the two.
30: * Note that the two Comparable must be with compatible type, or a
31: * ClassCastException might be thrown.
32: */
33: public static final Comparable min(Comparable a, Comparable b) {
34: return (a.compareTo(b) < 0) ? a : b;
35: }
36:
37: /**
38: * Given two comparables, return the maximum of the two.
39: * Note that the two Comparable must be with compatible type, or a
40: * ClassCastException might be thrown.
41: */
42: public static final Comparable max(Comparable a, Comparable b) {
43: return (a.compareTo(b) < 0) ? b : a;
44: }
45: }
|