Merge pull request #3 from erius0/dev

Dev
This commit is contained in:
Egor 2022-02-21 21:32:19 +03:00 committed by GitHub
commit 5ffdb41147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 8 deletions

BIN
Package lab5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 KiB

View file

@ -9,7 +9,7 @@ import lombok.ToString;
* Класс данных координат
*/
@Data @NoArgsConstructor @EqualsAndHashCode @ToString
public class Coordinates {
public class Coordinates implements Comparable<Coordinates> {
/**
* Координата X типа float
@ -45,4 +45,13 @@ public class Coordinates {
throw new IllegalArgumentException("Поле y класса Coordinates должно быть больше -816");
this.y = y;
}
private double distance() {
return Math.sqrt(x * x + y * y);
}
@Override
public int compareTo(Coordinates other) {
return Double.compare(this.distance(), other.distance());
}
}

View file

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

View file

@ -171,12 +171,15 @@ public class Person implements Comparable<Person> {
*/
@Override
public int compareTo(Person other) {
return Comparator.comparing((Person p) -> p.name)
.thenComparing(p -> p.passportID)
.thenComparing(p -> p.height)
.thenComparing(p -> p.nationality)
.thenComparing(p -> p.location)
.thenComparing(p -> p.eyeColor)
return Comparator.comparing(Person::getName)
.thenComparing(Person::getPassportID)
.thenComparing(Person::getHeight)
.thenComparing(Person::getCreationDate)
.thenComparing(p -> p.getNationality().toString())
.thenComparing(Person::getLocation)
.thenComparing(Person::getCoordinates)
.thenComparing(p -> p.getEyeColor().toString())
.thenComparing(Person::getId)
.compare(this, other);
}
}