Trying to create the develop method

This commit is contained in:
BGbaderguet 2020-11-15 19:37:20 +01:00
parent e6f0dc3029
commit 58d29974f5
4 changed files with 56 additions and 24 deletions

View File

@ -24,6 +24,11 @@ public interface ICityService
*/ */
void addCity(City cityToAdd); void addCity(City cityToAdd);
/**
* Updating the fields of a specific city
*/
void updateCity(City cityToUpdate);
/** /**
* Get all cities sorted by name * Get all cities sorted by name
* @return {@link List} * @return {@link List}

View File

@ -30,7 +30,7 @@ final public class City implements Serializable
} }
/** /**
* The primary key of the city in our datbase which is automatically incremented * The primary key of the city in our database which is automatically incremented
*/ */
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
public int id; public int id;
@ -40,16 +40,21 @@ final public class City implements Serializable
*/ */
@NonNull @NonNull
public String nameCity; public String nameCity;
@Nullable @Nullable
public String w_icon; public String w_icon = null;
@Nullable @Nullable
public String w_temp; public String w_temp = null;
@Nullable @Nullable
public String w_feelsliketemp; public String w_feelsliketemp = null;
@Nullable @Nullable
public String w_mintemp; public String w_mintemp = null;
@Nullable @Nullable
public String w_maxtemp; public String w_maxtemp = null;
/** /**
* Constructor of the city class * Constructor of the city class
@ -61,6 +66,26 @@ final public class City implements Serializable
this.nameCity = nameCity; this.nameCity = nameCity;
} }
public void setW_icon(@Nullable String w_icon) {
this.w_icon = w_icon;
}
public void setW_temp(@Nullable String w_temp) {
this.w_temp = w_temp;
}
public void setW_feelsliketemp(@Nullable String w_feelsliketemp) {
this.w_feelsliketemp = w_feelsliketemp;
}
public void setW_mintemp(@Nullable String w_mintemp) {
this.w_mintemp = w_mintemp;
}
public void setW_maxtemp(@Nullable String w_maxtemp) {
this.w_maxtemp = w_maxtemp;
}
/** /**
* Equals function that return true or false weither both name are same and both object belongs to City class * 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 * @param o The object to compare
@ -68,26 +93,20 @@ final public class City implements Serializable
*/ */
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o) return true;
{ if (o == null || getClass() != o.getClass()) return false;
return true; City city = (City) o;
} return id == city.id &&
if (o == null || getClass() != o.getClass()) nameCity.equals(city.nameCity) &&
{ Objects.equals(w_icon, city.w_icon) &&
return false; Objects.equals(w_temp, city.w_temp) &&
} Objects.equals(w_feelsliketemp, city.w_feelsliketemp) &&
City city1 = (City) o; Objects.equals(w_mintemp, city.w_mintemp) &&
Objects.equals(w_maxtemp, city.w_maxtemp);
return nameCity.equals(city1.nameCity);
} }
/**
* hashCode function
* @return Clé de hashage (int)
*/
@Override @Override
public int hashCode() public int hashCode() {
{ return Objects.hash(id, nameCity, w_icon, w_temp, w_feelsliketemp, w_mintemp, w_maxtemp);
return Objects.hash(nameCity);
} }
} }

View File

@ -5,6 +5,8 @@ import androidx.room.Delete;
import androidx.room.Insert; import androidx.room.Insert;
import androidx.room.OnConflictStrategy; import androidx.room.OnConflictStrategy;
import androidx.room.Query; import androidx.room.Query;
import androidx.room.Update;
import fr.romanet.vj.apps.myweather.ICityService; import fr.romanet.vj.apps.myweather.ICityService;
import fr.romanet.vj.apps.myweather.bo.City; import fr.romanet.vj.apps.myweather.bo.City;
import java.util.List; import java.util.List;
@ -24,7 +26,11 @@ public interface CityDao extends ICityService
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
void addCity(City cityToAdd); void addCity(City cityToAdd);
@Update
void updateCity(City cityToUpdate);
@Override @Override
@Query("SELECT * FROM City ORDER BY nameCity DESC") @Query("SELECT * FROM City ORDER BY nameCity DESC")
List<City> sortCityByName(); List<City> sortCityByName();
} }

View File

@ -48,6 +48,8 @@ public final class CityRepository
cityDatabase.cityDao().addCity(cityToAdd); cityDatabase.cityDao().addCity(cityToAdd);
} }
public void updateCity(City cityToUpdate) {cityDatabase.cityDao().updateCity(cityToUpdate);}
public List<City> sortCityByName() public List<City> sortCityByName()
{ {
return cityDatabase.cityDao().sortCityByName(); return cityDatabase.cityDao().sortCityByName();