org.hisp.dhis.util.Comparing Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dhis2-java-client Show documentation
Show all versions of dhis2-java-client Show documentation
DHIS 2 API client for Java.
package org.hisp.dhis.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* Generic utility class for null-safe comparison.
*/
@NoArgsConstructor( access = AccessLevel.PRIVATE )
public class Comparing
{
/**
* Compares two objects for order. Returns a negative integer, zero, or a
* positive integer if the first object is less than, equal to, or greater
* than the second object. Any of the objects can be null. A null value is
* considered to be less than a non-null value.
*
* @param
* @param a the first object.
* @param b the second object.
* @return an integer value.
*/
public static > int compareTo( T a, T b )
{
if ( a == b )
{
return 0;
}
return a != null ? b != null ? a.compareTo( b ) : 1 : -1;
}
/**
* Compares two objects for order. Returns a negative integer, zero, or a
* positive integer if the first object is less than, equal to, or greater
* than the second object. Any of the objects can be null. A null value is
* considered to be greater than a non-null value.
*
* @param
* @param a the first object.
* @param b the second object.
* @return an integer value.
*/
public static > int compareToNullLast( T a, T b )
{
if ( a == b )
{
return 0;
}
return a != null ? b != null ? a.compareTo( b ) : -1 : 1;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy