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 @Data @NoArgsConstructor @EqualsAndHashCode @ToString
public class Coordinates { public class Coordinates implements Comparable<Coordinates> {
/** /**
* Координата X типа float * Координата X типа float
@ -45,4 +45,13 @@ public class Coordinates {
throw new IllegalArgumentException("Поле y класса Coordinates должно быть больше -816"); throw new IllegalArgumentException("Поле y класса Coordinates должно быть больше -816");
this.y = y; 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 @Override
public int compareTo(Location other) { public int compareTo(Location other) {
return Comparator.comparing((Location loc) -> loc.name) return Comparator.comparing(Location::getName)
.thenComparing(Location::distance) .thenComparing(Location::distance)
.compare(this, other); .compare(this, other);
} }

View file

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