Skip to content

Instantly share code, notes, and snippets.

@tomasmalmsten
Last active April 22, 2018 10:56
Show Gist options
  • Save tomasmalmsten/a58a0a7d9afc2c064fcdb3dc1c38479b to your computer and use it in GitHub Desktop.
Save tomasmalmsten/a58a0a7d9afc2c064fcdb3dc1c38479b to your computer and use it in GitHub Desktop.
Clean Code - Functions snippet one
public int compareTo(final Object _other) throws ClassCastException, NullPointerException {
final ExampleClass otherExampleClass = (ExampleClass) _other;
if(equals(otherExampleClass)) {
return 0;
}
if(getCreatedDate() == null) {
if(otherExampleClass.getCreatedDate() == null) {
return 0;
}
return -1;
}
if(otherExampleClass.getCreatedDate() == null) {
return 1;
}
return otherExampleClass.getCreatedDate().compareTo(getCreatedDate());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment