X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FPerson.java;h=f1409f52760d91eb57e59e7624a3af2a7304cbfa;hb=9f1e899962a92c9c1b8d3713eca0524964465014;hp=3e6788ffac59805d10321c8671f96d2e8c6bf6cb;hpb=416b4c77ff435499154345f4992f27c12ac0933c;p=Persons_Comparator.git diff --git a/src/Person.java b/src/Person.java index 3e6788f..f1409f5 100644 --- a/src/Person.java +++ b/src/Person.java @@ -1,21 +1,32 @@ -import java.util.ArrayList; import java.util.Comparator; -public class Person implements Comparable, Comparator { +public class Person implements Comparator { private Firstname firstname; private Origin origin; + private Country country; private Size size; private Weight weight; private Eye eye; - //List of persons in the database to compare to. - private ArrayList personArrayList; + private Integer distanceFromReference; + + Person() { + setFirstname(new Firstname()); + setOrigin(new Origin()); + setCountry(new Country()); + setPersonSize(new Size()); + setWeight(new Weight()); + setEye(new Eye()); + setDistanceFromReference(0); + } - Person(Firstname firstname, Origin origin, Size size, Weight weight, Eye eye) { - setFirstname(firstname); - setOrigin(origin); - setPersonSize(size); - setWeight(weight); - setEye(eye); + Person(String firstname, String country, Integer size, Integer weight, String colorEye) { + setFirstname(new Firstname(firstname)); + setOrigin(new Origin(country)); + setCountry(new Country(country)); + setPersonSize(new Size(size)); + setWeight(new Weight(weight)); + setEye(new Eye(colorEye)); + setDistanceFromReference(0); } public void setFirstname(Firstname firstname) { @@ -34,6 +45,14 @@ public class Person implements Comparable, Comparator { return origin; } + public void setCountry(Country country) { + this.country = country; + } + + public Country getCountry() { + return country; + } + public void setPersonSize(Size size) { this.size = size; } @@ -58,23 +77,35 @@ public class Person implements Comparable, Comparator { return eye; } - public void setPersonArrayList(ArrayList personArrayList) { - this.personArrayList = personArrayList; + public void setDistanceFromReference(Integer distanceFromReference) { + this.distanceFromReference = distanceFromReference; } - public ArrayList getPersonArrayList() { - return personArrayList; + public Integer getDistanceFromReference() { + return distanceFromReference; } @Override - public int compareTo(Person person) { - return this.firstname.compareTo(person.getFirstname()) + this.origin.compareTo(person.getOrigin()) - + this.size.compareTo(person.getPersonSize()) + this.weight.compareTo(person.getWeight()) - + this.eye.compareTo(person.getEye()); + public String toString() { + return "Person{" + + "firstname=" + firstname.getFirstname() + + ", origin=" + origin.getCountry() + + ", country=" + country.getName() + + ", size=" + size.getSize() + + ", weight=" + weight.getWeight() + + ", eye=" + eye.getStrColor() + "(" + this.getEye().getColor().getRed() + "," + this.getEye().getColor().getGreen() + "," + this.getEye().getColor().getBlue() + ")" + + ", distanceFromReference=" + this.getDistanceFromReference() + + '}'; + } + + public Integer distanceTo(Person person) { + return this.getFirstname().distanceTo(person.getFirstname()) + this.getOrigin().distanceTo(person.getOrigin()) + + this.getCountry().distanceTo(person.getCountry()) + this.getPersonSize().distanceTo(person.getPersonSize()) + + this.getWeight().distanceTo(person.getWeight()) + this.getEye().distanceTo(person.getEye()); } @Override public int compare(Person p1, Person p2) { - return p1.compareTo(p2); + return p1.getDistanceFromReference().compareTo(p2.getDistanceFromReference()); } }