diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java b/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java new file mode 100644 index 0000000..631b3ba --- /dev/null +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java @@ -0,0 +1,82 @@ +package fr.romanet.vj.apps.myweather.bo; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.PrimaryKey; +import java.io.Serializable; +import java.util.Comparator; +import java.util.Objects; + +//This class is used in order to represent a city +@Entity +final public class City implements Serializable +{ + //Class CityComparator that implements Comparator interface in order to compare two cities + public static final class CityComparator implements Comparator + { + /** + * Compare function that compare two city by their name + * @param o1 The first city to compare + * @param o2 Second city to compare with the first + * @return + */ + @Override + public int compare(City o1, City o2) + { + return o1.nameCity.compareTo(o2.nameCity); + } + + } + + /** + * The primary key of the city in our datbase which is automatically incremented + */ + @PrimaryKey(autoGenerate = true) + public int id; + + /** + * The name of the city + */ + @NonNull + public String nameCity; + + /** + * Constructor of the city class + * @param nameCity The name of the new city + */ + public City(@NonNull String nameCity) + { + id = 0; + this.nameCity = nameCity; + } + + /** + * Equals function that return true or false weither both name are same and both object belongs to City class + * @param o The object to compare + * @return true or false + */ + @Override + public boolean equals(Object o) { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + City city1 = (City) o; + + return nameCity.equals(city1.nameCity); + } + + /** + * hashCode function + * @return Clé de hashage (int) + */ + @Override + public int hashCode() + { + return Objects.hash(nameCity); + } +}