mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Change prise by take
add equals override to compare too drugs objects.
This commit is contained in:
parent
5a28a9748d
commit
592079bd01
1 changed files with 16 additions and 4 deletions
|
@ -5,6 +5,7 @@ import android.util.Log;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
|
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
|
||||||
import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday;
|
import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday;
|
||||||
|
@ -148,17 +149,17 @@ public class Drug implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDateEndOfStock() {
|
void setDateEndOfStock() {
|
||||||
int numberDayOfPrise;
|
int numberDayOfTake;
|
||||||
if (this.take > 0) {
|
if (this.take > 0) {
|
||||||
numberDayOfPrise = (int) Math.floor(this.stock / this.take);
|
numberDayOfTake = (int) Math.floor(this.stock / this.take);
|
||||||
} else {
|
} else {
|
||||||
numberDayOfPrise = 0;
|
numberDayOfTake = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date aDate = dateAtNoon(new Date());
|
Date aDate = dateAtNoon(new Date());
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(aDate);
|
calendar.setTime(aDate);
|
||||||
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfPrise);
|
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake);
|
||||||
|
|
||||||
this.dateEndOfStock = calendar.getTime();
|
this.dateEndOfStock = calendar.getTime();
|
||||||
}
|
}
|
||||||
|
@ -175,4 +176,15 @@ public class Drug implements Serializable {
|
||||||
setDateLastUpdate(new Date().getTime());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue