Author: scolebourne Date: Fri Dec 29 09:04:00 2006 New Revision: 491050 URL: http://svn.apache.org/viewvc?view=rev&rev=491050 Log: LANG-291 - Move min/max methods above inner class, add javadoc and format
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ObjectUtils.java Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ObjectUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ObjectUtils.java?view=diff&rev=491050&r1=491049&r2=491050 ============================================================================== --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ObjectUtils.java (original) +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ObjectUtils.java Fri Dec 29 09:04:00 2006 @@ -237,6 +237,50 @@ return obj == null ? nullStr : obj.toString(); } + // Min/Max + //----------------------------------------------------------------------- + /** + * Null safe comparison of Comparables. + * + * @param c1 the first comparable, may be null + * @param c2 the second comparable, may be null + * @return + * <ul> + * <li>If both objects are non-null and unequal, the lesser object. + * <li>If both objects are non-null and equal, c1. + * <li>If one of the comparables is null, the non-null object. + * <li>If both the comparables are null, null is returned. + * </ul> + */ + public static Object min(Comparable c1, Comparable c2) { + if (c1 != null && c2 != null) { + return c1.compareTo(c2) < 1 ? c1 : c2; + } else { + return c1 != null ? c1 : c2; + } + } + + /** + * Null safe comparison of Comparables. + * + * @param c1 the first comparable, may be null + * @param c2 the second comparable, may be null + * @return + * <ul> + * <li>If both objects are non-null and unequal, the greater object. + * <li>If both objects are non-null and equal, c1. + * <li>If one of the comparables is null, the non-null object. + * <li>If both the comparables are null, null is returned. + * </ul> + */ + public static Object max(Comparable c1, Comparable c2) { + if (c1 != null && c2 != null) { + return c1.compareTo(c2) >= 0 ? c1 : c2; + } else { + return c1 != null ? c1 : c2; + } + } + // Null //----------------------------------------------------------------------- /** @@ -277,52 +321,5 @@ return ObjectUtils.NULL; } } - - - /** - * Null safe comparison of Comparables. - * - * @param c1 - * @param c2 - * @return - * <ul> - * <li>If both objects are non-null and unequal, the lesser object. - * <li>If both objects are non-null and equal, c1. - * <li>If one of the comparables is null, the non-null object. - * <li>If both the comparables are null, null is returned. - * </ul> - */ - public static Object min( Comparable c1, Comparable c2 ) { - if ( c1 != null && c2 != null ) { - return c1.compareTo( c2 ) < 1 ? c1 : c2; - } - else { - return c1 != null ? c1 : c2; - } - } - - /** - * Null safe comparison of Comparables. - * - * @param c1 - * @param c2 - * @return - * <ul> - * <li>If both objects are non-null and unequal, the greater object. - * <li>If both objects are non-null and equal, c1. - * <li>If one of the comparables is null, the non-null object. - * <li>If both the comparables are null, null is returned. - * </ul> - */ - public static Object max( Comparable c1, Comparable c2 ) { - if ( c1 != null && c2 != null ) { - return c1.compareTo( c2 ) >= 0 ? c1 : c2; - } - else { - return c1 != null ? c1 : c2; - } - } - - - + } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]