Replaced Long.compare with Long.compareTo for compatibility with Java 6.
Formatting and generics.