more null fixes
This commit is contained in:
parent
4cc937b816
commit
e36983b378
3 changed files with 4 additions and 4 deletions
|
@ -143,7 +143,7 @@ public final class PeopleDatabaseCommands {
|
||||||
public static void sumOfHeight(PeopleDatabase peopleDatabase) {
|
public static void sumOfHeight(PeopleDatabase peopleDatabase) {
|
||||||
int sum = peopleDatabase.getCollection()
|
int sum = peopleDatabase.getCollection()
|
||||||
.stream()
|
.stream()
|
||||||
.mapToInt(Person::getHeight)
|
.mapToInt(p -> p.getHeight() == null ? 0 : p.getHeight())
|
||||||
.sum();
|
.sum();
|
||||||
System.out.println("Сумма ростов всех людей в коллекции - " + sum);
|
System.out.println("Сумма ростов всех людей в коллекции - " + sum);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class Location implements Comparable<Location> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Location other) {
|
public int compareTo(Location other) {
|
||||||
return Comparator.comparing(Location::getName)
|
return Comparator.comparing(Location::getName, Comparator.nullsFirst(String::compareTo))
|
||||||
.thenComparing(Location::distance)
|
.thenComparing(Location::distance)
|
||||||
.compare(this, other);
|
.compare(this, other);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,8 +174,8 @@ public class Person implements Comparable<Person> {
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Person other) {
|
public int compareTo(Person other) {
|
||||||
return Comparator.comparing(Person::getName)
|
return Comparator.comparing(Person::getName)
|
||||||
.thenComparing(Person::getPassportID)
|
.thenComparing(Person::getPassportID, Comparator.nullsFirst(String::compareTo))
|
||||||
.thenComparing(Person::getHeight)
|
.thenComparing(Person::getHeight, Comparator.nullsFirst(Integer::compareTo))
|
||||||
.thenComparing(Person::getCreationDate)
|
.thenComparing(Person::getCreationDate)
|
||||||
.thenComparing(p -> p.getNationality().toString())
|
.thenComparing(p -> p.getNationality().toString())
|
||||||
.thenComparing(Person::getLocation)
|
.thenComparing(Person::getLocation)
|
||||||
|
|
Loading…
Reference in a new issue