Guava
https://github.com/google/guava/wiki/CommonObjectUtilitiesExplained
https://github.com/google/guava/wiki/CommonObjectUtilitiesExplained
Note: The newly introduced
Objects
class in JDK 7 provides the equivalent Objects.equals
method.
public static int hashCode(@Nullable Object... objects) {
return Arrays.hashCode(objects);
}
ComparisonChain
performs a "lazy" comparison: it only performs comparisons until it finds a nonzero result, after which it ignores further input. public int compareTo(Foo that) {
return ComparisonChain.start()
.compare(this.aString, that.aString)
.compare(this.anInt, that.anInt)
.compare(this.anEnum, that.anEnum, Ordering.natural().nullsLast())
.result();
}
MoreObjects
firstNonNull(@Nullable T first, @Nullable T second)
https://github.com/google/guava/wiki/PrimitivesExplained
https://kodejava.org/calculate-timings-using-commons-lang-stopwatch/
https://kodejava.org/calculate-timings-using-commons-lang-stopwatch/
import org.apache.commons.lang.time.StopWatch; StopWatch stopWatch = new StopWatch(); // Start the watch, do some task and stop the watch stopWatch.start(); doSomeTask(5000); stopWatch.stop(); // Print out the total time of the watch System.out.println("Time: " + stopWatch.getTime());