Skip to content

Instantly share code, notes, and snippets.

@rkhmelyuk
Created August 4, 2011 09:40
Show Gist options
  • Save rkhmelyuk/1124852 to your computer and use it in GitHub Desktop.
Save rkhmelyuk/1124852 to your computer and use it in GitHub Desktop.
int compareTo(Person other) {
if (other == null) {
return 1;
}
int result = 0;
if (this.age > other.age) {
result = 1;
}
else if (this.age < other.age) {
result = -1;
}
if (result == 0) {
if (this.lastName != null && other.lastName != null) {
result = this.lastName.compareTo(other.lastName);
if (result == 0) {
if (this.firstName != null && other.firstName != null) {
result = this.firstName.compareTo(other.firstName);
}
else {
result = this.firstName != null ? 1 : -1;
}
}
}
else {
result = this.lastName != null ? 1 : -1;
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment