ch.bind.philib.lang
public abstract class CompareUtil extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
CompareUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T> int |
compare(Comparable<T> a,
T b)
A null-safe compare helper.
|
static int |
diff(boolean a,
boolean b)
Helper for compareTo implementations.
Boolean version which considers false < true |
static int |
diff(byte a,
byte b)
Helper for compareTo implementations.
Byte version which masks the input values so that an unsigned comparison is performed. |
static int |
diff(char a,
char b)
Helper for compareTo implementations.
|
static int |
diff(double a,
double b)
Helper for compareTo implementations.
|
static int |
diff(float a,
float b)
Helper for compareTo implementations.
|
static int |
diff(int a,
int b)
Helper for compareTo implementations.
|
static int |
diff(long a,
long b)
Helper for compareTo implementations.
|
static int |
diff(short a,
short b)
Helper for compareTo implementations.
|
static boolean |
equals(Object a,
Object b)
A null-safe equality helper.
|
static int |
normalize(int diff)
Helper for compareTo implementations.
|
static int |
normalize(long diff)
Helper for compareTo implementations.
|
public static boolean equals(Object a, Object b)
input return value ------------------------------------ a == b => true a == null, b != null => false a != null, b == null => false otherwise => a.equals(b)
a - -b - -public static <T> int compare(Comparable<T> a, T b)
input return value ------------------------------------ a == b => 0 a == null, b != null => -1 a != null, b == null => 1 otherwise => a.compareTo(b)
a - -b - -public static int normalize(int diff)
diff - the value which shall be normalizedpublic static int normalize(long diff)
diff - the value which shall be normalizedpublic static int diff(boolean a,
boolean b)
false < true
a b ----------------------- true true => 0 true false => 1 false false => 0 false true => -1
a - -b - -public static int diff(byte a,
byte b)
Masks -128 -> 127 => 0 -> 255
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -public static int diff(char a,
char b)
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -public static int diff(short a,
short b)
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -public static int diff(int a,
int b)
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -public static int diff(long a,
long b)
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -public static int diff(float a,
float b)
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -public static int diff(double a,
double b)
Maps { a<b, a==b, a>b } => { -1, 0, 1 }
a - -b - -Copyright © 2014. All Rights Reserved.