org.scijava.util
Class MiscUtils

java.lang.Object
  extended by org.scijava.util.MiscUtils

public final class MiscUtils
extends Object

Miscellaneous utility methods. Every project needs a class like this, right?

Author:
Curtis Rueden

Method Summary
static
<T extends Comparable<? super T>>
int
compare(T o1, T o2)
          Compares two comparable objects, even if one or both of them are null.
static
<T extends Comparable<? super T>>
int
compare(T o1, T o2, boolean heavyNulls)
          Compares two comparable objects, even if one or both of them are null.
static boolean equal(Object o1, Object o2)
          Compares two objects for equality, even if one or both of them are null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compare

public static <T extends Comparable<? super T>> int compare(T o1,
                                                            T o2)
Compares two comparable objects, even if one or both of them are null.

By convention, nulls are considered less than non-nulls (and will hence will appear first on sorted lists).

Parameters:
o1 - The first object to compare.
o2 - The second object to compare.
Returns:
The result of o1.compareTo(o2) unless one or both of them is null, in which case nulls are considered less than non-null objects.

compare

public static <T extends Comparable<? super T>> int compare(T o1,
                                                            T o2,
                                                            boolean heavyNulls)
Compares two comparable objects, even if one or both of them are null.

Parameters:
o1 - The first object to compare.
o2 - The second object to compare.
heavyNulls - If true, nulls will be treated as greater than non-nulls, and hence "sink to the bottom" of e.g. sorted lists.
Returns:
The result of o1.compareTo(o2) unless one or both of them is null, in which case the null strategy defined by the heavyNulls flag is used, to define nulls as either less than, or greater than, non-null objects.

equal

public static boolean equal(Object o1,
                            Object o2)
Compares two objects for equality, even if one or both of them are null.

Parameters:
o1 - The first object to compare.
o2 - The second object to compare.
Returns:
True if the two objects are both null, or both are non-null and o1.equals(o2) holds.


Copyright © 2009–2014 SciJava. All rights reserved.