From 592079bd01636abfe11d402c24edd50c41843228 Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:08:07 +0100 Subject: [PATCH] Change prise by take add equals override to compare too drugs objects. --- .../main/java/net/foucry/pilldroid/Drug.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/Drug.java b/app/src/main/java/net/foucry/pilldroid/Drug.java index 7eba859..54a1686 100644 --- a/app/src/main/java/net/foucry/pilldroid/Drug.java +++ b/app/src/main/java/net/foucry/pilldroid/Drug.java @@ -5,6 +5,7 @@ import android.util.Log; import java.io.Serializable; import java.util.Calendar; import java.util.Date; +import java.util.Objects; import static net.foucry.pilldroid.UtilDate.dateAtNoon; import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; @@ -148,17 +149,17 @@ public class Drug implements Serializable { } void setDateEndOfStock() { - int numberDayOfPrise; + int numberDayOfTake; if (this.take > 0) { - numberDayOfPrise = (int) Math.floor(this.stock / this.take); + numberDayOfTake = (int) Math.floor(this.stock / this.take); } else { - numberDayOfPrise = 0; + numberDayOfTake = 0; } Date aDate = dateAtNoon(new Date()); Calendar calendar = Calendar.getInstance(); calendar.setTime(aDate); - calendar.add(Calendar.DAY_OF_YEAR, numberDayOfPrise); + calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); this.dateEndOfStock = calendar.getTime(); } @@ -175,4 +176,15 @@ public class Drug implements Serializable { setDateLastUpdate(new Date().getTime()); } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Drug drug = (Drug) o; + return stock == drug.stock && + take == drug.take && + alertThreshold == drug.alertThreshold && + warnThreshold == drug.warnThreshold && + Objects.equals(name, drug.name); + } } \ No newline at end of file