Fixed the "Lambda Sort" Article
This commit is contained in:
parent
e7d3347960
commit
1945c8a312
@ -37,7 +37,7 @@ public class Human {
|
|||||||
|
|
||||||
public static int compareByNameThenAge(final Human lhs, final Human rhs) {
|
public static int compareByNameThenAge(final Human lhs, final Human rhs) {
|
||||||
if (lhs.name.equals(rhs.name)) {
|
if (lhs.name.equals(rhs.name)) {
|
||||||
return lhs.age - rhs.age;
|
return Integer.compare(lhs.age, rhs.age);
|
||||||
} else {
|
} else {
|
||||||
return lhs.name.compareTo(rhs.name);
|
return lhs.name.compareTo(rhs.name);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class Java8SortUnitTest {
|
|||||||
final List<Human> humans = Lists.newArrayList(new Human("Sarah", 12), new Human("Sarah", 10), new Human("Zack", 12));
|
final List<Human> humans = Lists.newArrayList(new Human("Sarah", 12), new Human("Sarah", 10), new Human("Zack", 12));
|
||||||
humans.sort((lhs, rhs) -> {
|
humans.sort((lhs, rhs) -> {
|
||||||
if (lhs.getName().equals(rhs.getName())) {
|
if (lhs.getName().equals(rhs.getName())) {
|
||||||
return lhs.getAge() - rhs.getAge();
|
return Integer.compare(lhs.getAge(), rhs.getAge());
|
||||||
} else {
|
} else {
|
||||||
return lhs.getName().compareTo(rhs.getName());
|
return lhs.getName().compareTo(rhs.getName());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user