mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Write missing tests and docs for RepetitionList
This commit is contained in:
@@ -26,10 +26,15 @@ import com.activeandroid.annotation.Table;
|
||||
@Table(name = "Repetitions")
|
||||
public class Repetition extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Habit to which this repetition belong.
|
||||
*/
|
||||
@Column(name = "habit")
|
||||
public Habit habit;
|
||||
|
||||
/**
|
||||
* Timestamp of the day this repetition occurred. Time of day should be midnight (UTC).
|
||||
*/
|
||||
@Column(name = "timestamp")
|
||||
public Long timestamp;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ package org.isoron.uhabits.models;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.activeandroid.Cache;
|
||||
import com.activeandroid.query.Delete;
|
||||
@@ -35,14 +37,15 @@ import java.util.HashMap;
|
||||
|
||||
public class RepetitionList
|
||||
{
|
||||
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
public RepetitionList(Habit habit)
|
||||
public RepetitionList(@NonNull Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected From select()
|
||||
{
|
||||
return new Select().from(Repetition.class)
|
||||
@@ -51,6 +54,7 @@ public class RepetitionList
|
||||
.orderBy("timestamp");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected From selectFromTo(long timeFrom, long timeTo)
|
||||
{
|
||||
return select().and("timestamp >= ?", timeFrom).and("timestamp <= ?", timeTo);
|
||||
@@ -114,6 +118,7 @@ public class RepetitionList
|
||||
*
|
||||
* @return oldest repetition for the habit
|
||||
*/
|
||||
@Nullable
|
||||
public Repetition getOldest()
|
||||
{
|
||||
return (Repetition) select().limit(1).executeSingle();
|
||||
@@ -129,6 +134,7 @@ public class RepetitionList
|
||||
*
|
||||
* @return total number of repetitions by month versus day of week
|
||||
*/
|
||||
@NonNull
|
||||
public HashMap<Long, Integer[]> getWeekdayFrequency()
|
||||
{
|
||||
Repetition oldestRep = getOldest();
|
||||
|
||||
Reference in New Issue
Block a user