/*
 * Copyright (c) 2006-2009 Philipp Meinen <philipp@bind.ch>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software
 * is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
 * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package ch.bind.philib.data;

public final class CompareUtil {

	private CompareUtil() {
	}

	public static final boolean equality(final Object o1, final Object o2) {
		if (o1 == null) {
			return (o2 == null);
		} else {
			if (o2 == null) {
				return false;
			} else {
				return o1.equals(o2);
			}
		}
	}

	public static final <T> int compare(final Comparable<T> o1, final T o2) {
		if (o1 == null) {
			if (o2 == null) {
				return 0; // equal
			} else {
				return -1; // o1 < o2
			}
		} else {
			if (o2 == null) {
				return 1; // o1 > o2
			} else {
				return o1.compareTo(o2);
			}
		}
	}
}

@@ -1311,31 +1311,27 @@
 %09%09if (o1 == 
-null) %7B
+o2)
 %0A%09%09%09return (
@@ -1329,19 +1329,30 @@
 %09return 
+true;%0A%09%09if 
 (o
-2
+1
  == null
@@ -1352,16 +1352,68 @@
 == null)
+ %7B%0A%09%09%09// o2 is not null -%3E not equal%0A%09%09%09return false
 ;%0A%09%09%7D el
@@ -1598,25 +1598,33 @@
  == 
-null) %7B%0A%09
+o2)%0A%09%09%09return 0;%0A
 %09%09if (o
-2
+1
  == 
@@ -1638,41 +1638,26 @@
 %0A%09%09%09
-%09return 0; // equal%0A%09%09%09%7D else %7B%0A%09
+// o2 is not null%0A
 %09%09%09r
@@ -1677,21 +1677,16 @@
 o1 %3C o2%0A
-%09%09%09%7D%0A
 %09%09%7D else

improve the comparison utility methods by using an early reference comparsion