/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.ajah.util.compare;

/**
 * Utility methods for comparisons.
 * 
 * @author <a href="http://efsavage.com">Eric F. Savage</a>, <a
 *         href="mailto:code@efsavage.com">code@efsavage.com</a>.
 */
public class CompareUtils {

	/**
	 * Compares two longs.
	 * 
	 * @param first
	 *            First value.
	 * @param second
	 *            Second value.
	 * @return -1 if first < second, 1 if first > second, 0 if equal.
	 */
	public static int compare(final long first, final long second) {
		if (first < second) {
			return -1;
		} else if (first > second) {
			return 1;
		}
		return 0;
	}

	/**
	 * Compares two objects, with null being considered lesser than not-null.
	 * 
	 * @param first
	 *            First value.
	 * @param second
	 *            Second value.
	 * @return -1 if first is null and second is not, 1 if first is not null and
	 *         second is, 0 if both are not-null.
	 * @throws IllegalArgumentException
	 *             If Both values are null, as this means it cannot be passed
	 *             along to a comparator even though they are "equal".
	 */
	public static int compareNulls(final Object first, final Object second) {
		if (first == null) {
			if (second == null) {
				throw new IllegalArgumentException("Both values are null");
			}
			return -1;
		}
		if (second == null) {
			return 1;
		}
		return 0;
	}

	/**
	 * Compares two doubles.
	 * 
	 * @param first
	 *            First value.
	 * @param second
	 *            Second value.
	 * @return -1 if first < second, 1 if first > second, 0 if equal.
	 */
	public static int compare(final double first, final double second) {
		if (first < second) {
			return -1;
		} else if (first > second) {
			return 1;
		}
		return 0;
	}

	public static int compare(final String first, final String second) {
		if (first == null) {
			if (second == null) {
				throw new IllegalArgumentException("Both values are null");
			}
			return -1;
		}
		if (second == null) {
			return 1;
		}
		return first.compareTo(second);
	}

}

@@ -2365,232 +2365,560 @@
 %7D%0A%0A%09
-public static int compare(final String first, final String second) %7B%0A%09%09if (first == null) %7B%0A%09%09%09if (second == null) %7B%0A%09%09%09%09throw new IllegalArgumentException(%22Both values are null%22);%0A%09%09%09%7D%0A%09%09%09return -1;%0A%09%09%7D%0A%09%09if (second == null
+/**%0A%09 * Compares two strings, checking for nulls first.%0A%09 * %0A%09 * @param first%0A%09 *            The first string, may be null.%0A%09 * @param second%0A%09 *            The second string, may be null.%0A%09 * @return The comparison of the two Strings.%0A%09 * @throws IllegalArgumentException%0A%09 *             If Both values are null, as this means it cannot be passed%0A%09 *             along to a comparator even though they are %22equal%22.%0A%09 */%0A%09public static int compare(final String first, final String second) %7B%0A%09%09int retVal = compareNulls(first, second);%0A%09%09if (retVal != 0
 ) %7B%0A
@@ -2919,33 +2919,38 @@
  0) %7B%0A%09%09%09return 
-1
+retVal
 ;%0A%09%09%7D%0A%09%09return f

Use compareNulls, add comments