Example of a properly implemented compareTo function in Java