more null fixes

This commit is contained in:
Egor 2022-02-22 01:21:08 +03:00
parent 4cc937b816
commit e36983b378
3 changed files with 4 additions and 4 deletions

View file

@ -143,7 +143,7 @@ public final class PeopleDatabaseCommands {
public static void sumOfHeight(PeopleDatabase peopleDatabase) {
int sum = peopleDatabase.getCollection()
.stream()
.mapToInt(Person::getHeight)
.mapToInt(p -> p.getHeight() == null ? 0 : p.getHeight())
.sum();
System.out.println("Сумма ростов всех людей в коллекции - " + sum);
}

View file

@ -73,7 +73,7 @@ public class Location implements Comparable<Location> {
*/
@Override
public int compareTo(Location other) {
return Comparator.comparing(Location::getName)
return Comparator.comparing(Location::getName, Comparator.nullsFirst(String::compareTo))
.thenComparing(Location::distance)
.compare(this, other);
}

View file

@ -174,8 +174,8 @@ public class Person implements Comparable<Person> {
@Override
public int compareTo(Person other) {
return Comparator.comparing(Person::getName)
.thenComparing(Person::getPassportID)
.thenComparing(Person::getHeight)
.thenComparing(Person::getPassportID, Comparator.nullsFirst(String::compareTo))
.thenComparing(Person::getHeight, Comparator.nullsFirst(Integer::compareTo))
.thenComparing(Person::getCreationDate)
.thenComparing(p -> p.getNationality().toString())
.thenComparing(Person::getLocation)