メモ
おもに null safe ( java 8で使わなくなる可能性高いなぁ)
import org.apache.commons.lang3.ObjectUtils;
public class Main {
public static void main(String[] args) {
String a = null;
String b = null;
String c = "null";
// 複数のオブジェクトで null ではない一番左の Object を取得する。
System.out.println(ObjectUtils.firstNonNull(a, b, c));
;
// null safe な object#hashCode
System.out.println(ObjectUtils.hashCode(c));
// null safe な object#hashCode ( 複数ハッシュ計算 )
System.out.println(ObjectUtils.hashCodeMulti(a, b, c));
// null safe な object#toString
System.out.println(ObjectUtils.toString(c));
// null safe な object#toString ( null の場合の文字列指定 )
System.out.println(ObjectUtils.toString(c, "-"));
// null safe な compare
System.out.println(ObjectUtils.compare(a, b));
// StringUtils#defaultIfNull の Object版
System.out.println(ObjectUtils.defaultIfNull(b, c));
// 一致しない
System.out.println(ObjectUtils.notEqual(b, c));
// 一致する
System.out.println(ObjectUtils.equals(a, b));
}
}