Unify Checkmarks and Repetitions

pull/699/head
Alinson S. Xavier 5 years ago
parent 23e9ccb236
commit a3cf2877b8

@ -75,7 +75,7 @@ public class HabitFixtures
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
for (int mark : marks)
habit.getRepetitions().setValue(today.minus(mark), YES_MANUAL);
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
return habit;
}
@ -109,7 +109,7 @@ public class HabitFixtures
582, 583, 584, 586, 589};
for (int mark : marks)
habit.getRepetitions().setValue(today.minus(mark), YES_MANUAL);
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
return habit;
}
@ -128,7 +128,7 @@ public class HabitFixtures
Timestamp timestamp = DateUtils.getToday();
for (int value : LONG_NUMERICAL_HABIT_CHECKS)
{
habit.getRepetitions().setValue(timestamp, value);
habit.getOriginalCheckmarks().setValue(timestamp, value);
timestamp = timestamp.minus(1);
}
@ -146,7 +146,7 @@ public class HabitFixtures
Timestamp timestamp = DateUtils.getToday();
for (boolean c : LONG_HABIT_CHECKS)
{
if (c) habit.getRepetitions().setValue(timestamp, YES_MANUAL);
if (c) habit.getOriginalCheckmarks().setValue(timestamp, YES_MANUAL);
timestamp = timestamp.minus(1);
}

@ -46,7 +46,7 @@ public class BarChartTest extends BaseViewTest
Habit habit = fixtures.createLongNumericalHabit();
view = new BarChart(targetContext);
Timestamp today = DateUtils.getToday();
CheckmarkList checkmarks = habit.getCheckmarks();
CheckmarkList checkmarks = habit.getComputedCheckmarks();
view.setCheckmarks(checkmarks.getByInterval(today.minus(20), today));
view.setColor(PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), targetContext));
view.setTarget(200.0);

@ -46,7 +46,7 @@ public class FrequencyChartTest extends BaseViewTest
Habit habit = fixtures.createLongHabit();
view = new FrequencyChart(targetContext);
view.setFrequency(habit.getRepetitions().getWeekdayFrequency());
view.setFrequency(habit.getOriginalCheckmarks().getWeekdayFrequency());
view.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
measureView(view, dpToPixels(300), dpToPixels(100));
}

@ -58,7 +58,7 @@ public class HistoryChartTest extends BaseViewTest
chart = new HistoryChart(targetContext);
chart.setSkipEnabled(true);
chart.setCheckmarks(habit.getCheckmarks().getAllValues());
chart.setCheckmarks(habit.getComputedCheckmarks().getAllValues());
chart.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
measureView(chart, dpToPixels(400), dpToPixels(200));

@ -43,7 +43,7 @@ class HabitCardViewTest : BaseViewTest() {
habit2 = fixtures.createLongNumericalHabit()
view = component.getHabitCardViewFactory().create().apply {
habit = habit1
values = habit1.checkmarks.allValues
values = habit1.computedCheckmarks.allValues
score = habit1.scores.todayValue
isSelected = false
buttonCount = 5
@ -70,7 +70,7 @@ class HabitCardViewTest : BaseViewTest() {
fun testRender_numerical() {
view.apply {
habit = habit2
values = habit2.checkmarks.allValues
values = habit2.computedCheckmarks.allValues
}
assertRenders(view, "$PATH/render_numerical.png")
}

@ -52,7 +52,7 @@ public class PerformanceTest extends BaseAndroidTest
for (int i = 0; i < 100000; i++)
{
habit.getScores().getTodayValue();
habit.getCheckmarks().getTodayValue();
habit.getComputedCheckmarks().getTodayValue();
}
}

@ -54,7 +54,7 @@ public class CheckmarkWidgetTest extends BaseViewTest
prefs.setSkipEnabled(true);
habit = fixtures.createVeryLongHabit();
checkmarks = habit.getCheckmarks();
checkmarks = habit.getComputedCheckmarks();
CheckmarkWidget widget = new CheckmarkWidget(targetContext, 0, habit);
view = convertToView(widget, 150, 200);

@ -51,8 +51,8 @@ public class CheckmarkWidgetViewTest extends BaseViewTest
float percentage = (float) score;
view.setActiveColor(PaletteUtils.getAndroidTestColor(0));
view.setCheckmarkState(habit.getCheckmarks().getTodayValue());
view.setCheckmarkValue(habit.getCheckmarks().getTodayValue());
view.setCheckmarkState(habit.getComputedCheckmarks().getTodayValue());
view.setCheckmarkValue(habit.getComputedCheckmarks().getTodayValue());
view.setPercentage(percentage);
view.setName(habit.getName());
view.refresh();

@ -124,7 +124,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
@Override
public void onPause()
{
habit.getCheckmarks().observable.removeListener(this);
habit.getComputedCheckmarks().observable.removeListener(this);
super.onPause();
}
@ -142,7 +142,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
getDialog().getWindow().setLayout(width, height);
refreshData();
habit.getCheckmarks().observable.addListener(this);
habit.getComputedCheckmarks().observable.addListener(this);
}
@Override
@ -175,7 +175,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
@Override
public void doInBackground()
{
checkmarks = habit.getCheckmarks().getAllValues();
checkmarks = habit.getComputedCheckmarks().getAllValues();
}
@Override

@ -96,9 +96,9 @@ class BarCardPresenter(
boolBucketSizes[boolSpinnerPosition]
}
val checkmarks = if (bucketSize == 1) {
habit.checkmarks.all
habit.computedCheckmarks.all
} else {
habit.checkmarks.groupBy(getTruncateField(bucketSize), firstWeekday)
habit.computedCheckmarks.groupBy(getTruncateField(bucketSize), firstWeekday)
}
return BarCardViewModel(
checkmarks = checkmarks,

@ -52,7 +52,7 @@ class FrequencyCardPresenter(
) {
fun present() = FrequencyCardViewModel(
color = habit.color,
frequency = habit.repetitions.weekdayFrequency,
frequency = habit.originalCheckmarks.weekdayFrequency,
firstWeekday = firstWeekday,
)
}

@ -66,7 +66,7 @@ class HistoryCardPresenter(
val isSkipEnabled: Boolean,
) {
fun present() = HistoryCardViewModel(
checkmarks = habit.checkmarks.allValues,
checkmarks = habit.computedCheckmarks.allValues,
color = habit.color,
firstWeekday = firstWeekday,
isNumerical = habit.isNumerical,

@ -79,7 +79,7 @@ class OverviewCardPresenter(val habit: Habit) {
scoreToday = scoreToday,
scoreMonthDiff = scoreToday - scoreLastMonth,
scoreYearDiff = scoreToday - scoreLastYear,
totalCount = habit.repetitions.totalCount,
totalCount = habit.originalCheckmarks.totalCount,
)
}
}

@ -57,7 +57,7 @@ class TargetCardPresenter(
val resources: Resources,
) {
suspend fun present(): TargetCardViewModel = Dispatchers.IO {
val checkmarks = habit.checkmarks
val checkmarks = habit.computedCheckmarks
val valueToday = checkmarks.todayValue / 1e3
val valueThisWeek = checkmarks.getThisWeekValue(firstWeekday) / 1e3
val valueThisMonth = checkmarks.thisMonthValue / 1e3

@ -46,12 +46,12 @@ open class CheckmarkWidget(
setActiveColor(habit.color.toThemedAndroidColor(context))
setName(habit.name)
setCheckmarkValue(habit.checkmarks.todayValue)
setCheckmarkValue(habit.computedCheckmarks.todayValue)
if (habit.isNumerical) {
setNumerical(true)
setCheckmarkState(getNumericalCheckmarkState())
} else {
setCheckmarkState(habit.checkmarks.todayValue)
setCheckmarkState(habit.computedCheckmarks.todayValue)
}
setPercentage(habit.scores.todayValue.toFloat())
refresh()

@ -44,7 +44,7 @@ class FrequencyWidget(
(widgetView.dataView as FrequencyChart).apply {
setFirstWeekday(firstWeekday)
setColor(habit.color.toThemedAndroidColor(context))
setFrequency(habit.repetitions.weekdayFrequency)
setFrequency(habit.originalCheckmarks.weekdayFrequency)
}
}

@ -46,7 +46,7 @@ class HistoryWidget(
setFirstWeekday(firstWeekday)
setSkipEnabled(prefs.isSkipEnabled)
setColor(habit.color.toThemedAndroidColor(context))
setCheckmarks(habit.checkmarks.allValues)
setCheckmarks(habit.computedCheckmarks.allValues)
setNumerical(habit.isNumerical)
setTarget(habit.targetValue / habit.frequency.denominator)
}

@ -71,7 +71,7 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
val app = this.applicationContext as HabitsApplication
AndroidThemeSwitcher(this, app.component.preferences).apply()
val numberPickerFactory = NumberPickerFactory(context)
numberPickerFactory.create(data.habit.checkmarks.today!!.value.toDouble() / 1000,
numberPickerFactory.create(data.habit.computedCheckmarks.today!!.value.toDouble() / 1000,
data.habit.unit,
this).show()
}

@ -52,8 +52,8 @@ public class CreateRepetitionCommand implements Command
@Override
public void execute()
{
RepetitionList reps = habit.getRepetitions();
reps.setValue(timestamp, value);
RepetitionList checks = habit.getOriginalCheckmarks();
checks.setValue(timestamp, value);
habitList.resort();
}

@ -95,7 +95,7 @@ public class HabitBullCSVImporter extends AbstractImporter
map.put(name, h);
}
h.getRepetitions().setValue(timestamp, YES_MANUAL);
h.getOriginalCheckmarks().setValue(timestamp, YES_MANUAL);
}
}
}

@ -126,7 +126,7 @@ public class HabitsCSVExporter
generateDirs.add(habitDirName);
writeScores(habitDirName, h.getScores());
writeCheckmarks(habitDirName, h.getCheckmarks());
writeCheckmarks(habitDirName, h.getComputedCheckmarks());
}
writeMultipleHabits();
@ -181,7 +181,7 @@ public class HabitsCSVExporter
List<double[]> scores = new ArrayList<>();
for (Habit h : selectedHabits)
{
checkmarks.add(h.getCheckmarks().getValues(oldest, newest));
checkmarks.add(h.getComputedCheckmarks().getValues(oldest, newest));
scores.add(h.getScores().getValues(oldest, newest));
}
@ -244,10 +244,10 @@ public class HabitsCSVExporter
Timestamp newest = Timestamp.ZERO;
for (Habit h : selectedHabits)
{
if(h.getRepetitions().getOldest() == null || h.getRepetitions().getNewest() == null)
if(h.getOriginalCheckmarks().getOldest() == null || h.getOriginalCheckmarks().getNewest() == null)
continue;
Timestamp currOld = h.getRepetitions().getOldest().getTimestamp();
Timestamp currNew = h.getRepetitions().getNewest().getTimestamp();
Timestamp currOld = h.getOriginalCheckmarks().getOldest().getTimestamp();
Timestamp currNew = h.getOriginalCheckmarks().getNewest().getTimestamp();
oldest = currOld.isOlderThan(oldest) ? currOld : oldest;
newest = currNew.isNewerThan(newest) ? currNew : newest;
}

@ -131,8 +131,8 @@ public class LoopDBImporter extends AbstractImporter
for (RepetitionRecord r : reps)
{
Timestamp t = new Timestamp(r.timestamp);
Repetition rep = habit.getRepetitions().getByTimestamp(t);
if (rep == null || rep.getValue() != r.value)
Checkmark check = habit.getOriginalCheckmarks().getByTimestamp(t);
if (check == null || check.getValue() != r.value)
new CreateRepetitionCommand(habitList, habit, t, r.value).execute();
}
}

@ -167,7 +167,7 @@ public class RewireDBImporter extends AbstractImporter
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
cal.set(year, month - 1, day);
habit.getRepetitions().setValue(new Timestamp(cal), YES_MANUAL);
habit.getOriginalCheckmarks().setValue(new Timestamp(cal), YES_MANUAL);
} while (c.moveToNext());
}
finally

@ -102,7 +102,7 @@ public class TickmateDBImporter extends AbstractImporter
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
cal.set(year, month, day);
habit.getRepetitions().setValue(new Timestamp(cal), YES_MANUAL);
habit.getOriginalCheckmarks().setValue(new Timestamp(cal), YES_MANUAL);
} while (c.moveToNext());
}
finally

@ -50,13 +50,13 @@ public abstract class CheckmarkList
}
@NonNull
static List<Checkmark> buildCheckmarksFromIntervals(Repetition[] reps,
static List<Checkmark> buildCheckmarksFromIntervals(Checkmark[] original,
ArrayList<Interval> intervals)
{
if (reps.length == 0) throw new IllegalArgumentException();
if (original.length == 0) throw new IllegalArgumentException();
Timestamp today = DateUtils.getTodayWithOffset();
Timestamp begin = reps[0].getTimestamp();
Timestamp begin = original[0].getTimestamp();
if (intervals.size() > 0) begin = Timestamp.oldest(begin, intervals.get(0).begin);
int nDays = begin.daysUntil(today) + 1;
@ -75,11 +75,11 @@ public abstract class CheckmarkList
}
}
for (Repetition rep : reps)
for (Checkmark c : original)
{
Timestamp date = rep.getTimestamp();
Timestamp date = c.getTimestamp();
int offset = date.daysUntil(today);
int value = rep.getValue();
int value = c.getValue();
int prevValue = checkmarks.get(offset).getValue();
if (prevValue < value)
checkmarks.set(offset, new Checkmark(date, value));
@ -101,12 +101,12 @@ public abstract class CheckmarkList
*/
@NonNull
static ArrayList<Interval> buildIntervals(@NonNull Frequency freq,
@NonNull Repetition[] reps)
@NonNull Checkmark[] checks)
{
ArrayList<Repetition> filteredReps = new ArrayList<>();
for (Repetition r : reps)
if (r.getValue() == YES_MANUAL)
filteredReps.add(r);
ArrayList<Checkmark> filteredReps = new ArrayList<>();
for (Checkmark c : checks)
if (c.getValue() == YES_MANUAL)
filteredReps.add(c);
int num = freq.getNumerator();
int den = freq.getDenominator();
@ -114,8 +114,8 @@ public abstract class CheckmarkList
ArrayList<Interval> intervals = new ArrayList<>();
for (int i = 0; i < filteredReps.size() - num + 1; i++)
{
Repetition first = filteredReps.get(i);
Repetition last = filteredReps.get(i + num - 1);
Checkmark first = filteredReps.get(i);
Checkmark last = filteredReps.get(i + num - 1);
long distance = first.getTimestamp().daysUntil(last.getTimestamp());
if (distance >= den) continue;
@ -180,10 +180,10 @@ public abstract class CheckmarkList
@NonNull
public synchronized final int[] getAllValues()
{
Repetition oldestRep = habit.getRepetitions().getOldest();
if (oldestRep == null) return new int[0];
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
if (oldestOriginal == null) return new int[0];
Timestamp fromTimestamp = oldestRep.getTimestamp();
Timestamp fromTimestamp = oldestOriginal.getTimestamp();
Timestamp toTimestamp = DateUtils.getTodayWithOffset();
return getValues(fromTimestamp, toTimestamp);
@ -254,7 +254,7 @@ public abstract class CheckmarkList
private int getThisIntervalValue(DateUtils.TruncateField truncateField, int firstWeekday)
{
List<Checkmark> groups = habit.getCheckmarks().groupBy(truncateField, firstWeekday, 1);
List<Checkmark> groups = habit.getComputedCheckmarks().groupBy(truncateField, firstWeekday, 1);
if (groups.isEmpty()) return 0;
return groups.get(0).getValue();
}
@ -334,16 +334,16 @@ public abstract class CheckmarkList
if (newest != null && newest.getTimestamp().equals(today)) return;
invalidateNewerThan(Timestamp.ZERO);
Repetition oldestRep = habit.getRepetitions().getOldest();
Checkmark oldestRep = habit.getOriginalCheckmarks().getOldest();
if (oldestRep == null) return;
final Timestamp from = oldestRep.getTimestamp();
if (from.isNewerThan(today)) return;
Repetition reps[] = habit
.getRepetitions()
Checkmark reps[] = habit
.getOriginalCheckmarks()
.getByInterval(from, today)
.toArray(new Repetition[0]);
.toArray(new Checkmark[0]);
if (habit.isNumerical()) computeNumerical(reps);
else computeYesNo(reps);
@ -365,37 +365,37 @@ public abstract class CheckmarkList
@Nullable
protected abstract Checkmark getOldestComputed();
private void computeNumerical(Repetition[] reps)
private void computeNumerical(Checkmark[] original)
{
if (reps.length == 0) return;
if (original.length == 0) return;
Timestamp today = DateUtils.getTodayWithOffset();
Timestamp begin = reps[0].getTimestamp();
Timestamp begin = original[0].getTimestamp();
int nDays = begin.daysUntil(today) + 1;
List<Checkmark> checkmarks = new ArrayList<>(nDays);
List<Checkmark> computed = new ArrayList<>(nDays);
for (int i = 0; i < nDays; i++)
checkmarks.add(new Checkmark(today.minus(i), 0));
computed.add(new Checkmark(today.minus(i), 0));
for (Repetition rep : reps)
for (Checkmark c : original)
{
int offset = rep.getTimestamp().daysUntil(today);
checkmarks.set(offset, new Checkmark(rep.getTimestamp(), rep.getValue()));
int offset = c.getTimestamp().daysUntil(today);
computed.set(offset, new Checkmark(c.getTimestamp(), c.getValue()));
}
add(checkmarks);
add(computed);
}
private void computeYesNo(Repetition[] reps)
private void computeYesNo(Checkmark[] original)
{
ArrayList<Interval> intervals;
intervals = buildIntervals(habit.getFrequency(), reps);
intervals = buildIntervals(habit.getFrequency(), original);
snapIntervalsTogether(intervals);
add(buildCheckmarksFromIntervals(reps, intervals));
add(buildCheckmarksFromIntervals(original, intervals));
}
public List<Checkmark> getAll() {
Repetition oldest = habit.getRepetitions().getOldest();
Checkmark oldest = habit.getOriginalCheckmarks().getOldest();
if(oldest == null) return new ArrayList<>();
return getByInterval(oldest.getTimestamp(), DateUtils.getTodayWithOffset());
}

@ -114,11 +114,8 @@ public class Habit
observable.notifyListeners();
}
/**
* List of checkmarks belonging to this habit.
*/
@NonNull
public synchronized CheckmarkList getCheckmarks()
public synchronized CheckmarkList getComputedCheckmarks()
{
return checkmarks;
}
@ -206,8 +203,7 @@ public class Habit
data.reminder = reminder;
}
@NonNull
public RepetitionList getRepetitions()
public RepetitionList getOriginalCheckmarks()
{
return repetitions;
}
@ -300,7 +296,7 @@ public class Habit
public void invalidateNewerThan(Timestamp timestamp)
{
getScores().invalidateNewerThan(timestamp);
getCheckmarks().invalidateNewerThan(timestamp);
getComputedCheckmarks().invalidateNewerThan(timestamp);
getStreaks().invalidateNewerThan(timestamp);
}
@ -316,7 +312,7 @@ public class Habit
public synchronized boolean isCompletedToday()
{
int todayCheckmark = getCheckmarks().getTodayValue();
int todayCheckmark = getComputedCheckmarks().getTodayValue();
if (isNumerical())
{
if(getTargetType() == AT_LEAST)

@ -23,8 +23,6 @@ import androidx.annotation.*;
import com.opencsv.*;
import org.isoron.uhabits.core.utils.*;
import java.io.*;
import java.util.*;
@ -180,7 +178,7 @@ public abstract class HabitList implements Iterable<Habit>
{
for (Habit h : this)
{
h.getCheckmarks().invalidateNewerThan(Timestamp.ZERO);
h.getComputedCheckmarks().invalidateNewerThan(Timestamp.ZERO);
h.getStreaks().invalidateNewerThan(Timestamp.ZERO);
h.getScores().invalidateNewerThan(Timestamp.ZERO);
}

@ -1,32 +0,0 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.core.models
data class Repetition(
/**
* Time the repetition took place.
*/
val timestamp: Timestamp,
/**
* For boolean habits, [value] equals YES_MANUAL if performed or SKIP if skipped.
* For numerical habits, this number is stored in thousandths. That is, if the user enters
* value 1.50 on the app, it is here stored as 1500.
*/
val value: Int,
);

@ -25,9 +25,6 @@ import org.isoron.uhabits.core.utils.*;
import java.util.*;
/**
* The collection of {@link Repetition}s belonging to a habit.
*/
public abstract class RepetitionList
{
@NonNull
@ -43,17 +40,17 @@ public abstract class RepetitionList
}
/**
* Adds a repetition to the list.
* Adds a checkmark to the list.
* <p>
* Any implementation of this method must call observable.notifyListeners()
* after the repetition has been added.
* after the checkmark has been added.
*
* @param repetition the repetition to be added.
* @param checkmark the checkmark to be added.
*/
public abstract void add(Repetition repetition);
public abstract void add(Checkmark checkmark);
/**
* Returns the list of repetitions that happened within the given time
* Returns the list of checkmarks that happened within the given time
* interval.
* <p>
* The list is sorted by timestamp in increasing order. That is, the first
@ -62,31 +59,31 @@ public abstract class RepetitionList
*
* @param fromTimestamp timestamp of the beginning of the interval
* @param toTimestamp timestamp of the end of the interval
* @return list of repetitions within given time interval
* @return list of checkmarks within given time interval
*/
public abstract List<Repetition> getByInterval(Timestamp fromTimestamp,
public abstract List<Checkmark> getByInterval(Timestamp fromTimestamp,
Timestamp toTimestamp);
/**
* Returns the repetition that has the given timestamp, or null if none
* Returns the checkmark that has the given timestamp, or null if none
* exists.
*
* @param timestamp the repetition timestamp.
* @return the repetition that has the given timestamp.
* @param timestamp the checkmark timestamp.
* @return the checkmark that has the given timestamp.
*/
@Nullable
public abstract Repetition getByTimestamp(Timestamp timestamp);
public abstract Checkmark getByTimestamp(Timestamp timestamp);
/**
* If a repetition with the given timestamp exists, return its value. Otherwise, returns
* If a checkmark with the given timestamp exists, return its value. Otherwise, returns
* Checkmark.NO for boolean habits and zero for numerical habits.
*/
@NonNull
public int getValue(Timestamp timestamp)
{
Repetition rep = getByTimestamp(timestamp);
if (rep == null) return Checkmark.UNKNOWN;
return rep.getValue();
Checkmark check = getByTimestamp(timestamp);
if (check == null) return Checkmark.UNKNOWN;
return check.getValue();
}
@NonNull
@ -96,54 +93,54 @@ public abstract class RepetitionList
}
/**
* Returns the oldest repetition in the list.
* Returns the oldest checkmark in the list.
* <p>
* If the list is empty, returns null. Repetitions in the future are
* discarded.
*
* @return oldest repetition in the list, or null if list is empty.
* @return oldest checkmark in the list, or null if list is empty.
*/
@Nullable
public abstract Repetition getOldest();
public abstract Checkmark getOldest();
@Nullable
/**
* Returns the newest repetition in the list.
* Returns the newest checkmark in the list.
* <p>
* If the list is empty, returns null. Repetitions in the past are
* discarded.
*
* @return newest repetition in the list, or null if list is empty.
* @return newest checkmark in the list, or null if list is empty.
*/
public abstract Repetition getNewest();
public abstract Checkmark getNewest();
/**
* Returns the total number of successful repetitions for each month, from the first
* repetition until today, grouped by day of week.
* Returns the total number of successful checkmarks for each month, from the first
* checkmark until today, grouped by day of week.
* <p>
* The repetitions are returned in a HashMap. The key is the timestamp for
* The checkmarks are returned in a HashMap. The key is the timestamp for
* the first day of the month, at midnight (00:00). The value is an integer
* array with 7 entries. The first entry contains the total number of
* successful repetitions during the specified month that occurred on a Saturday. The
* successful checkmarks during the specified month that occurred on a Saturday. The
* second entry corresponds to Sunday, and so on. If there are no
* successful repetitions during a certain month, the value is null.
* successful checkmarks during a certain month, the value is null.
*
* @return total number of repetitions by month versus day of week
* @return total number of checkmarks by month versus day of week
*/
@NonNull
public HashMap<Timestamp, Integer[]> getWeekdayFrequency()
{
List<Repetition> reps =
List<Checkmark> checks =
getByInterval(Timestamp.ZERO, DateUtils.getTodayWithOffset());
HashMap<Timestamp, Integer[]> map = new HashMap<>();
for (Repetition r : reps)
for (Checkmark c : checks)
{
if (!habit.isNumerical() && r.getValue() != Checkmark.YES_MANUAL)
if (!habit.isNumerical() && c.getValue() != Checkmark.YES_MANUAL)
continue;
Calendar date = r.getTimestamp().toCalendar();
int weekday = r.getTimestamp().getWeekday();
Calendar date = c.getTimestamp().toCalendar();
int weekday = c.getTimestamp().getWeekday();
date.set(Calendar.DAY_OF_MONTH, 1);
Timestamp timestamp = new Timestamp(date.getTimeInMillis());
@ -163,24 +160,24 @@ public abstract class RepetitionList
}
/**
* Removes a given repetition from the list.
* Removes a given checkmark from the list.
* <p>
* If the list does not contain the repetition, it is unchanged.
* If the list does not contain the checkmark, it is unchanged.
* <p>
* Any implementation of this method must call observable.notifyListeners()
* after the repetition has been added.
* after the checkmark has been added.
*
* @param repetition the repetition to be removed
* @param checkmark the checkmark to be removed
*/
public abstract void remove(@NonNull Repetition repetition);
public abstract void remove(@NonNull Checkmark checkmark);
public abstract long getTotalCount();
public void setValue(Timestamp timestamp, int value)
{
Repetition rep = getByTimestamp(timestamp);
if (rep != null) remove(rep);
add(new Repetition(timestamp, value));
Checkmark check = getByTimestamp(timestamp);
if (check != null) remove(check);
add(new Checkmark(timestamp, value));
habit.invalidateNewerThan(timestamp);
}

@ -196,22 +196,22 @@ public abstract class ScoreList implements Iterable<Score>
protected synchronized void compute(@NonNull Timestamp from,
@NonNull Timestamp to)
{
Score newest = getNewestComputed();
Score oldest = getOldestComputed();
Score newestComputed = getNewestComputed();
Score oldestComputed = getOldestComputed();
if (newest == null)
if (newestComputed == null)
{
Repetition oldestRep = habit.getRepetitions().getOldest();
if (oldestRep != null) from =
Timestamp.oldest(from, oldestRep.getTimestamp());
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
if (oldestOriginal != null) from =
Timestamp.oldest(from, oldestOriginal.getTimestamp());
forceRecompute(from, to, 0);
}
else
{
if (oldest == null) throw new IllegalStateException();
forceRecompute(from, oldest.getTimestamp().minus(1), 0);
forceRecompute(newest.getTimestamp().plus(1), to,
newest.getValue());
if (oldestComputed == null) throw new IllegalStateException();
forceRecompute(from, oldestComputed.getTimestamp().minus(1), 0);
forceRecompute(newestComputed.getTimestamp().plus(1), to,
newestComputed.getValue());
}
}
@ -221,7 +221,7 @@ public abstract class ScoreList implements Iterable<Score>
*/
protected void computeAll()
{
Repetition oldestRep = habit.getRepetitions().getOldest();
Checkmark oldestRep = habit.getOriginalCheckmarks().getOldest();
if (oldestRep == null) return;
Timestamp today = DateUtils.getTodayWithOffset();
@ -273,7 +273,7 @@ public abstract class ScoreList implements Iterable<Score>
int numerator = habit.getFrequency().getNumerator();
int denominator = habit.getFrequency().getDenominator();
final double freq = habit.getFrequency().toDouble();
final int[] checkmarkValues = habit.getCheckmarks().getValues(from, to);
final int[] checkmarkValues = habit.getComputedCheckmarks().getValues(from, to);
// For non-daily boolean habits, we double the numerator and the denominator to smooth
// out irregular repetition schedules (for example, weekly habits performed on different

@ -71,7 +71,7 @@ public abstract class StreakList
Timestamp beginning = findBeginning();
if (beginning == null || beginning.isNewerThan(today)) return;
int checks[] = habit.getCheckmarks().getValues(beginning, today);
int checks[] = habit.getComputedCheckmarks().getValues(beginning, today);
List<Streak> streaks = checkmarksToStreaks(beginning, checks);
removeNewestComputed();
@ -113,8 +113,8 @@ public abstract class StreakList
Streak newestStreak = getNewestComputed();
if (newestStreak != null) return newestStreak.getStart();
Repetition oldestRep = habit.getRepetitions().getOldest();
if (oldestRep != null) return oldestRep.getTimestamp();
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
if (oldestOriginal != null) return oldestOriginal.getTimestamp();
return null;
}

@ -186,8 +186,8 @@ public class MemoryHabitList extends HabitList
return h1.isNumerical() ? -1 : 1;
}
Integer v1 = Objects.requireNonNull(h1.getCheckmarks().getToday()).getValue();
Integer v2 = Objects.requireNonNull(h2.getCheckmarks().getToday()).getValue();
Integer v1 = Objects.requireNonNull(h1.getComputedCheckmarks().getToday()).getValue();
Integer v2 = Objects.requireNonNull(h2.getComputedCheckmarks().getToday()).getValue();
return v2.compareTo(v1);
};

@ -30,7 +30,7 @@ import java.util.*;
*/
public class MemoryRepetitionList extends RepetitionList
{
ArrayList<Repetition> list;
ArrayList<Checkmark> list;
public MemoryRepetitionList(Habit habit)
{
@ -39,18 +39,18 @@ public class MemoryRepetitionList extends RepetitionList
}
@Override
public void add(Repetition repetition)
public void add(Checkmark repetition)
{
list.add(repetition);
observable.notifyListeners();
}
@Override
public List<Repetition> getByInterval(Timestamp fromTimestamp, Timestamp toTimestamp)
public List<Checkmark> getByInterval(Timestamp fromTimestamp, Timestamp toTimestamp)
{
ArrayList<Repetition> filtered = new ArrayList<>();
ArrayList<Checkmark> filtered = new ArrayList<>();
for (Repetition r : list)
for (Checkmark r : list)
{
Timestamp t = r.getTimestamp();
if (t.isOlderThan(fromTimestamp) || t.isNewerThan(toTimestamp)) continue;
@ -65,9 +65,9 @@ public class MemoryRepetitionList extends RepetitionList
@Nullable
@Override
public Repetition getByTimestamp(Timestamp timestamp)
public Checkmark getByTimestamp(Timestamp timestamp)
{
for (Repetition r : list)
for (Checkmark r : list)
if (r.getTimestamp().equals(timestamp)) return r;
return null;
@ -75,12 +75,12 @@ public class MemoryRepetitionList extends RepetitionList
@Nullable
@Override
public Repetition getOldest()
public Checkmark getOldest()
{
Timestamp oldestTimestamp = Timestamp.ZERO.plus(1000000);
Repetition oldestRep = null;
Checkmark oldestRep = null;
for (Repetition rep : list)
for (Checkmark rep : list)
{
if (rep.getTimestamp().isOlderThan(oldestTimestamp))
{
@ -94,12 +94,12 @@ public class MemoryRepetitionList extends RepetitionList
@Nullable
@Override
public Repetition getNewest()
public Checkmark getNewest()
{
Timestamp newestTimestamp = Timestamp.ZERO;
Repetition newestRep = null;
Checkmark newestRep = null;
for (Repetition rep : list)
for (Checkmark rep : list)
{
if (rep.getTimestamp().isNewerThan(newestTimestamp))
{
@ -112,7 +112,7 @@ public class MemoryRepetitionList extends RepetitionList
}
@Override
public void remove(@NonNull Repetition repetition)
public void remove(@NonNull Checkmark repetition)
{
list.remove(repetition);
observable.notifyListeners();
@ -122,7 +122,7 @@ public class MemoryRepetitionList extends RepetitionList
public long getTotalCount()
{
int count = 0;
for (Repetition rep : list)
for (Checkmark rep : list)
if (rep.getValue() == Checkmark.YES_MANUAL)
count++;
return count;

@ -1,24 +0,0 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public Licenses along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Provides core models classes, such as {@link org.isoron.uhabits.core.models.Habit}
* and {@link org.isoron.uhabits.core.models.Repetition}.
*/
package org.isoron.uhabits.core.models;

@ -201,7 +201,7 @@ public class SQLiteHabitList extends HabitList
if (record == null) throw new RuntimeException("habit not in database");
repository.executeAsTransaction(() ->
{
((SQLiteRepetitionList) habit.getRepetitions()).removeAll();
habit.getOriginalCheckmarks().removeAll();
repository.remove(record);
});

@ -62,24 +62,24 @@ public class SQLiteRepetitionList extends RepetitionList
habit.getId().toString());
for (RepetitionRecord rec : records)
list.add(rec.toRepetition());
list.add(rec.toCheckmark());
}
@Override
public void add(Repetition rep)
public void add(Checkmark check)
{
loadRecords();
list.add(rep);
list.add(check);
check(habit.getId());
RepetitionRecord record = new RepetitionRecord();
record.habit_id = habit.getId();
record.copyFrom(rep);
record.copyFrom(check);
repository.save(record);
observable.notifyListeners();
}
@Override
public List<Repetition> getByInterval(Timestamp timeFrom, Timestamp timeTo)
public List<Checkmark> getByInterval(Timestamp timeFrom, Timestamp timeTo)
{
loadRecords();
return list.getByInterval(timeFrom, timeTo);
@ -87,35 +87,35 @@ public class SQLiteRepetitionList extends RepetitionList
@Override
@Nullable
public Repetition getByTimestamp(Timestamp timestamp)
public Checkmark getByTimestamp(Timestamp timestamp)
{
loadRecords();
return list.getByTimestamp(timestamp);
}
@Override
public Repetition getOldest()
public Checkmark getOldest()
{
loadRecords();
return list.getOldest();
}
@Override
public Repetition getNewest()
public Checkmark getNewest()
{
loadRecords();
return list.getNewest();
}
@Override
public void remove(@NonNull Repetition repetition)
public void remove(@NonNull Checkmark checkmark)
{
loadRecords();
list.remove(repetition);
list.remove(checkmark);
check(habit.getId());
repository.execSQL(
"delete from repetitions where habit = ? and timestamp = ?",
habit.getId(), repetition.getTimestamp().getUnixTime());
habit.getId(), checkmark.getTimestamp().getUnixTime());
observable.notifyListeners();
}

@ -25,7 +25,7 @@ import org.isoron.uhabits.core.database.*;
import org.isoron.uhabits.core.models.*;
/**
* The SQLite database record corresponding to a {@link Repetition}.
* The SQLite database record corresponding to a {@link Checkmark}.
*/
@Table(name = "Repetitions")
public class RepetitionRecord
@ -44,14 +44,14 @@ public class RepetitionRecord
@Column
public Long id;
public void copyFrom(Repetition repetition)
public void copyFrom(Checkmark checkmark)
{
timestamp = repetition.getTimestamp().getUnixTime();
value = repetition.getValue();
timestamp = checkmark.getTimestamp().getUnixTime();
value = checkmark.getValue();
}
public Repetition toRepetition()
public Checkmark toCheckmark()
{
return new Repetition(new Timestamp(timestamp), value);
return new Checkmark(new Timestamp(timestamp), value);
}
}

@ -65,7 +65,7 @@ public class HabitFixtures
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
for (int mark : marks)
habit.getRepetitions().setValue(today.minus(mark), YES_MANUAL);
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
return habit;
}
@ -89,7 +89,7 @@ public class HabitFixtures
for (int i = 0; i < times.length; i++)
{
Timestamp timestamp = today.minus(times[i]);
habit.getRepetitions().setValue(timestamp, values[i]);
habit.getOriginalCheckmarks().setValue(timestamp, values[i]);
}
return habit;
@ -125,7 +125,7 @@ public class HabitFixtures
for (int i = 0; i < times.length; i++)
{
Timestamp timestamp = reference.minus(times[i]);
habit.getRepetitions().setValue(timestamp, values[i]);
habit.getOriginalCheckmarks().setValue(timestamp, values[i]);
}
return habit;
@ -144,7 +144,7 @@ public class HabitFixtures
{
int value = NO;
if (c) value = YES_MANUAL;
habit.getRepetitions().setValue(timestamp, value);
habit.getOriginalCheckmarks().setValue(timestamp, value);
timestamp = timestamp.minus(1);
}
@ -153,7 +153,7 @@ public class HabitFixtures
private void saveIfSQLite(Habit habit)
{
if (!(habit.getRepetitions() instanceof SQLiteRepetitionList)) return;
if (!(habit.getOriginalCheckmarks() instanceof SQLiteRepetitionList)) return;
habitList.add(habit);
}
}

@ -178,7 +178,7 @@ public class NotificationTray
@Override
public void doInBackground()
{
todayValue = habit.getCheckmarks().getTodayValue();
todayValue = habit.getComputedCheckmarks().getTodayValue();
}
@Override

@ -361,7 +361,7 @@ public class HabitCardListCache implements CommandRunner.Listener
newData.scores.put(id, habit.getScores().getTodayValue());
newData.checkmarks.put(
id,
habit.getCheckmarks().getValues(dateFrom, dateTo));
habit.getComputedCheckmarks().getValues(dateFrom, dateTo));
runner.publishProgress(this, position);
}

@ -82,7 +82,7 @@ public class ListHabitsBehavior
public void onEdit(@NonNull Habit habit, Timestamp timestamp)
{
CheckmarkList checkmarks = habit.getCheckmarks();
CheckmarkList checkmarks = habit.getComputedCheckmarks();
double oldValue = checkmarks.getValues(timestamp, timestamp)[0];
screen.showNumberPicker(oldValue / 1000, habit.getUnit(), newValue ->

@ -56,7 +56,7 @@ class ShowHabitBehavior(
override fun onToggleCheckmark(timestamp: Timestamp, value: Int) {
if (habit.isNumerical) {
val checkmarks = habit.checkmarks
val checkmarks = habit.computedCheckmarks
val oldValue = checkmarks.getValues(timestamp, timestamp)[0].toDouble()
screen.showNumberPicker(oldValue / 1000, habit.unit) { newValue: Double ->
val thousands = Math.round(newValue * 1000).toInt()

@ -58,14 +58,14 @@ class ShowHabitMenuBehavior(
fun onRandomize() {
val random = Random()
habit.repetitions.removeAll()
habit.originalCheckmarks.removeAll()
var strength = 50.0
for (i in 0 until 365 * 5) {
if (i % 7 == 0) strength = Math.max(0.0, Math.min(100.0, strength + 10 * random.nextGaussian()))
if (random.nextInt(100) > strength) continue
var value = Checkmark.YES_MANUAL
if (habit.isNumerical) value = (1000 + 250 * random.nextGaussian() * strength / 100).toInt() * 1000
habit.repetitions.setValue(DateUtils.getToday().minus(i), value)
habit.originalCheckmarks.setValue(DateUtils.getToday().minus(i), value)
}
habit.invalidateNewerThan(Timestamp.ZERO)
screen.refresh()

@ -70,7 +70,7 @@ public class WidgetBehavior
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
{
int currentValue = habit.getRepetitions().getValue(timestamp);
int currentValue = habit.getOriginalCheckmarks().getValue(timestamp);
int newValue;
if(preferences.isSkipEnabled())
newValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
@ -81,13 +81,13 @@ public class WidgetBehavior
}
public void onIncrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
int currentValue = habit.getCheckmarks().getValues(timestamp, timestamp)[0];
int currentValue = habit.getComputedCheckmarks().getValues(timestamp, timestamp)[0];
setValue(habit, timestamp, currentValue + amount);
notificationTray.cancel(habit);
}
public void onDecrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
int currentValue = habit.getCheckmarks().getValues(timestamp, timestamp)[0];
int currentValue = habit.getComputedCheckmarks().getValues(timestamp, timestamp)[0];
setValue(habit, timestamp, currentValue - amount);
notificationTray.cancel(habit);
}

@ -51,13 +51,13 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
@Test
public void testExecute()
{
RepetitionList reps = habit.getRepetitions();
Repetition rep = reps.getByTimestamp(today);
assertNotNull(rep);
assertEquals(YES_MANUAL, rep.getValue());
RepetitionList reps = habit.getOriginalCheckmarks();
Checkmark check = reps.getByTimestamp(today);
assertNotNull(check);
assertEquals(YES_MANUAL, check.getValue());
command.execute();
rep = reps.getByTimestamp(today);
assertNotNull(rep);
assertEquals(100, rep.getValue());
check = reps.getByTimestamp(today);
assertNotNull(check);
assertEquals(100, check.getValue());
}
}

@ -123,7 +123,7 @@ public class ImportTest extends BaseUnitTest
GregorianCalendar date = DateUtils.getStartOfTodayCalendar();
date.set(year, month - 1, day);
Timestamp timestamp = new Timestamp(date);
return h.getRepetitions().getValue(timestamp) == YES_MANUAL;
return h.getOriginalCheckmarks().getValue(timestamp) == YES_MANUAL;
}
private void importFromFile(String assetFilename) throws IOException

@ -67,11 +67,11 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_buildCheckmarksFromIntervals_1() throws Exception
{
Repetition reps[] = new Repetition[]{
new Repetition(day(10), YES_MANUAL),
new Repetition(day(5), YES_MANUAL),
new Repetition(day(2), YES_MANUAL),
new Repetition(day(1), YES_MANUAL),
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(10), YES_MANUAL),
new Checkmark(day(5), YES_MANUAL),
new Checkmark(day(2), YES_MANUAL),
new Checkmark(day(1), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
@ -93,15 +93,15 @@ public class CheckmarkListTest extends BaseUnitTest
expected.add(new Checkmark(day(10), YES_MANUAL));
List<Checkmark> actual =
CheckmarkList.buildCheckmarksFromIntervals(reps, intervals);
CheckmarkList.buildCheckmarksFromIntervals(checks, intervals);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildCheckmarksFromIntervals_2() throws Exception
{
Repetition reps[] = new Repetition[]{
new Repetition(day(0), YES_MANUAL),
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(0), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
@ -111,17 +111,17 @@ public class CheckmarkListTest extends BaseUnitTest
expected.add(new Checkmark(day(0), YES_MANUAL));
List<Checkmark> actual =
CheckmarkList.buildCheckmarksFromIntervals(reps, intervals);
CheckmarkList.buildCheckmarksFromIntervals(checks, intervals);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildIntervals_1() throws Exception
{
Repetition reps[] = new Repetition[]{
new Repetition(day(23), YES_MANUAL),
new Repetition(day(18), YES_MANUAL),
new Repetition(day(8), YES_MANUAL),
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(23), YES_MANUAL),
new Checkmark(day(18), YES_MANUAL),
new Checkmark(day(8), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -130,17 +130,17 @@ public class CheckmarkListTest extends BaseUnitTest
expected.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
ArrayList<CheckmarkList.Interval> actual;
actual = CheckmarkList.buildIntervals(Frequency.WEEKLY, reps);
actual = CheckmarkList.buildIntervals(Frequency.WEEKLY, checks);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildIntervals_2() throws Exception
{
Repetition reps[] = new Repetition[]{
new Repetition(day(23), YES_MANUAL),
new Repetition(day(18), YES_MANUAL),
new Repetition(day(8), YES_MANUAL),
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(23), YES_MANUAL),
new Checkmark(day(18), YES_MANUAL),
new Checkmark(day(8), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -149,19 +149,19 @@ public class CheckmarkListTest extends BaseUnitTest
expected.add(new CheckmarkList.Interval(day(8), day(8), day(8)));
ArrayList<CheckmarkList.Interval> actual;
actual = CheckmarkList.buildIntervals(Frequency.DAILY, reps);
actual = CheckmarkList.buildIntervals(Frequency.DAILY, checks);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildIntervals_3() throws Exception
{
Repetition reps[] = new Repetition[]{
new Repetition(day(23), YES_MANUAL),
new Repetition(day(22), YES_MANUAL),
new Repetition(day(18), YES_MANUAL),
new Repetition(day(15), YES_MANUAL),
new Repetition(day(8), YES_MANUAL),
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(23), YES_MANUAL),
new Checkmark(day(22), YES_MANUAL),
new Checkmark(day(18), YES_MANUAL),
new Checkmark(day(15), YES_MANUAL),
new Checkmark(day(8), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -171,7 +171,7 @@ public class CheckmarkListTest extends BaseUnitTest
ArrayList<CheckmarkList.Interval> actual;
actual =
CheckmarkList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, reps);
CheckmarkList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, checks);
assertThat(actual, equalTo(expected));
}
@ -179,10 +179,10 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_buildIntervals_4() throws Exception
{
Repetition[] reps = new Repetition[]{
new Repetition(day(30), YES_MANUAL),
new Repetition(day(20), SKIP),
new Repetition(day(10), YES_MANUAL),
Checkmark[] checks = new Checkmark[]{
new Checkmark(day(30), YES_MANUAL),
new Checkmark(day(20), SKIP),
new Checkmark(day(10), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -190,7 +190,7 @@ public class CheckmarkListTest extends BaseUnitTest
expected.add(new CheckmarkList.Interval(day(10), day(10), day(8)));
ArrayList<CheckmarkList.Interval> actual;
actual = CheckmarkList.buildIntervals(new Frequency(1, 3), reps);
actual = CheckmarkList.buildIntervals(new Frequency(1, 3), checks);
assertThat(actual, equalTo(expected));
}
@ -209,7 +209,7 @@ public class CheckmarkListTest extends BaseUnitTest
YES_MANUAL
};
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@ -235,7 +235,7 @@ public class CheckmarkListTest extends BaseUnitTest
YES_MANUAL
};
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@ -244,7 +244,7 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_getAllValues_withEmptyHabit()
{
int[] expectedValues = new int[0];
int[] actualValues = emptyHabit.getCheckmarks().getAllValues();
int[] actualValues = emptyHabit.getComputedCheckmarks().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@ -265,7 +265,7 @@ public class CheckmarkListTest extends BaseUnitTest
YES_MANUAL
};
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@ -273,7 +273,7 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_getByInterval_withNumericalHabits() throws Exception
{
CheckmarkList checkmarks = numericalHabit.getCheckmarks();
CheckmarkList checkmarks = numericalHabit.getComputedCheckmarks();
List<Checkmark> expected =
Arrays.asList(new Checkmark(day(1), 200), new Checkmark(day(2), 0),
@ -287,7 +287,7 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_getTodayValue()
{
CheckmarkList checkmarks = nonDailyHabit.getCheckmarks();
CheckmarkList checkmarks = nonDailyHabit.getComputedCheckmarks();
travelInTime(-1);
assertThat(checkmarks.getTodayValue(), equalTo(NO));
@ -303,7 +303,7 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_getValues_withInvalidInterval()
{
int values[] = nonDailyHabit
.getCheckmarks()
.getComputedCheckmarks()
.getValues(new Timestamp(0L).plus(100), new Timestamp(0L));
assertThat(values, equalTo(new int[0]));
}
@ -328,7 +328,7 @@ public class CheckmarkListTest extends BaseUnitTest
UNKNOWN
};
int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to);
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getValues(from, to);
assertThat(actualValues, equalTo(expectedValues));
}
@ -376,7 +376,7 @@ public class CheckmarkListTest extends BaseUnitTest
StringWriter writer = new StringWriter();
nonDailyHabit.getCheckmarks().writeCSV(writer);
nonDailyHabit.getComputedCheckmarks().writeCSV(writer);
assertThat(writer.toString(), equalTo(expectedCSV));
}
@ -404,7 +404,7 @@ public class CheckmarkListTest extends BaseUnitTest
public void testGroupBy() throws Exception
{
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
CheckmarkList checkmarks = habit.getCheckmarks();
CheckmarkList checkmarks = habit.getComputedCheckmarks();
List<Checkmark> byMonth = checkmarks.groupBy(MONTH, Calendar.SATURDAY);
assertThat(byMonth.size(), equalTo(25)); // from 2013-01-01 to 2015-01-01
@ -430,7 +430,7 @@ public class CheckmarkListTest extends BaseUnitTest
public void testGetTodayValue() throws Exception
{
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
CheckmarkList checkmarks = habit.getCheckmarks();
CheckmarkList checkmarks = habit.getComputedCheckmarks();
DateUtils.setFixedLocalTime(unixTime(2050, MAY, 1));
assertThat(checkmarks.getTodayValue(), equalTo(0));

@ -49,8 +49,8 @@ public class HabitTest extends BaseUnitTest
assertThat(habit.hasReminder(), is(false));
assertNotNull(habit.getStreaks());
assertNotNull(habit.getScores());
assertNotNull(habit.getRepetitions());
assertNotNull(habit.getCheckmarks());
assertNotNull(habit.getOriginalCheckmarks());
assertNotNull(habit.getComputedCheckmarks());
}
@Test
@ -89,7 +89,7 @@ public class HabitTest extends BaseUnitTest
{
Habit h = modelFactory.buildHabit();
assertFalse(h.isCompletedToday());
h.getRepetitions().setValue(getToday(), Checkmark.YES_MANUAL);
h.getOriginalCheckmarks().setValue(getToday(), Checkmark.YES_MANUAL);
assertTrue(h.isCompletedToday());
}
@ -102,19 +102,19 @@ public class HabitTest extends BaseUnitTest
h.setTargetValue(100.0);
assertFalse(h.isCompletedToday());
h.getRepetitions().setValue(getToday(), 200_000);
h.getOriginalCheckmarks().setValue(getToday(), 200_000);
assertTrue(h.isCompletedToday());
h.getRepetitions().setValue(getToday(), 100_000);
h.getOriginalCheckmarks().setValue(getToday(), 100_000);
assertTrue(h.isCompletedToday());
h.getRepetitions().setValue(getToday(), 50_000);
h.getOriginalCheckmarks().setValue(getToday(), 50_000);
assertFalse(h.isCompletedToday());
h.setTargetType(Habit.AT_MOST);
h.getRepetitions().setValue(getToday(), 200_000);
h.getOriginalCheckmarks().setValue(getToday(), 200_000);
assertFalse(h.isCompletedToday());
h.getRepetitions().setValue(getToday(), 100_000);
h.getOriginalCheckmarks().setValue(getToday(), 100_000);
assertTrue(h.isCompletedToday());
h.getRepetitions().setValue(getToday(), 50_000);
h.getOriginalCheckmarks().setValue(getToday(), 50_000);
assertTrue(h.isCompletedToday());
}
@ -137,7 +137,6 @@ public class HabitTest extends BaseUnitTest
.suppress(Warning.NONFINAL_FIELDS)
.verify();
EqualsVerifier.forClass(Repetition.class).verify();
EqualsVerifier.forClass(Score.class).verify();
EqualsVerifier.forClass(Streak.class).verify();
EqualsVerifier.forClass(Reminder.class).verify();

@ -54,7 +54,7 @@ public class RepetitionListTest extends BaseUnitTest
{
super.setUp();
habit = fixtures.createEmptyHabit();
reps = habit.getRepetitions();
reps = habit.getOriginalCheckmarks();
today = DateUtils.getToday();
@ -79,15 +79,15 @@ public class RepetitionListTest extends BaseUnitTest
@Test
public void test_getOldest()
{
Repetition rep = reps.getOldest();
assertThat(rep.getTimestamp(), equalTo(today.minus(7)));
Checkmark check = reps.getOldest();
assertThat(check.getTimestamp(), equalTo(today.minus(7)));
}
@Test
public void test_getWeekDayFrequency()
{
habit = fixtures.createEmptyHabit();
reps = habit.getRepetitions();
reps = habit.getOriginalCheckmarks();
Random random = new Random(123L);
Integer weekdayCount[][] = new Integer[12][7];

@ -326,14 +326,14 @@ public class ScoreListTest extends BaseUnitTest
private void check(final int offset)
{
RepetitionList reps = habit.getRepetitions();
RepetitionList reps = habit.getOriginalCheckmarks();
Timestamp today = DateUtils.getToday();
reps.setValue(today.minus(offset), YES_MANUAL);
}
private void check(final int from, final int to)
{
RepetitionList reps = habit.getRepetitions();
RepetitionList reps = habit.getOriginalCheckmarks();
Timestamp today = DateUtils.getToday();
for (int i = from; i < to; i++)
@ -342,7 +342,7 @@ public class ScoreListTest extends BaseUnitTest
private void check(ArrayList<Integer> values)
{
RepetitionList reps = habit.getRepetitions();
RepetitionList reps = habit.getOriginalCheckmarks();
Timestamp today = DateUtils.getToday();
for (int i = 0; i < values.size(); i++)
if (values.get(i) == YES_MANUAL)
@ -351,7 +351,7 @@ public class ScoreListTest extends BaseUnitTest
private void addSkip(final int day)
{
RepetitionList reps = habit.getRepetitions();
RepetitionList reps = habit.getOriginalCheckmarks();
Timestamp today = DateUtils.getToday();
reps.setValue(today.minus(day), Checkmark.SKIP);
}

@ -42,7 +42,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
private Timestamp today;
private RepetitionList repetitions;
private RepetitionList originalCheckmarks;
private long day;
@ -60,7 +60,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
repository = new Repository<>(RepetitionRecord.class, db);
habit = fixtures.createLongHabit();
repetitions = habit.getRepetitions();
originalCheckmarks = habit.getOriginalCheckmarks();
today = DateUtils.getToday();
}
@ -70,8 +70,8 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
RepetitionRecord record = getByTimestamp(today.plus(1));
assertNull(record);
Repetition rep = new Repetition(today.plus(1), YES_MANUAL);
habit.getRepetitions().add(rep);
Checkmark rep = new Checkmark(today.plus(1), YES_MANUAL);
habit.getOriginalCheckmarks().add(rep);
record = getByTimestamp(today.plus(1));
assertNotNull(record);
@ -81,30 +81,30 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
@Test
public void testGetByInterval()
{
List<Repetition> reps =
repetitions.getByInterval(today.minus(10), today);
List<Checkmark> checks =
originalCheckmarks.getByInterval(today.minus(10), today);
assertThat(reps.size(), equalTo(8));
assertThat(reps.get(0).getTimestamp(), equalTo(today.minus(10)));
assertThat(reps.get(4).getTimestamp(), equalTo(today.minus(5)));
assertThat(reps.get(5).getTimestamp(), equalTo(today.minus(3)));
assertThat(checks.size(), equalTo(8));
assertThat(checks.get(0).getTimestamp(), equalTo(today.minus(10)));
assertThat(checks.get(4).getTimestamp(), equalTo(today.minus(5)));
assertThat(checks.get(5).getTimestamp(), equalTo(today.minus(3)));
}
@Test
public void testGetByTimestamp()
{
Repetition rep = repetitions.getByTimestamp(today);
Checkmark rep = originalCheckmarks.getByTimestamp(today);
assertNotNull(rep);
assertThat(rep.getTimestamp(), equalTo(today));
rep = repetitions.getByTimestamp(today.minus(2));
rep = originalCheckmarks.getByTimestamp(today.minus(2));
assertNull(rep);
}
@Test
public void testGetOldest()
{
Repetition rep = repetitions.getOldest();
Checkmark rep = originalCheckmarks.getOldest();
assertNotNull(rep);
assertThat(rep.getTimestamp(), equalTo(today.minus(120)));
}
@ -113,7 +113,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
public void testGetOldest_withEmptyHabit()
{
Habit empty = fixtures.createEmptyHabit();
Repetition rep = empty.getRepetitions().getOldest();
Checkmark rep = empty.getOriginalCheckmarks().getOldest();
assertNull(rep);
}
@ -123,8 +123,8 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
RepetitionRecord record = getByTimestamp(today);
assertNotNull(record);
Repetition rep = record.toRepetition();
repetitions.remove(rep);
Checkmark rep = record.toCheckmark();
originalCheckmarks.remove(rep);
record = getByTimestamp(today);
assertNull(record);

@ -33,9 +33,9 @@ public class RepetitionRecordTest extends BaseUnitTest
@Test
public void testRecord() throws Exception
{
Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 50);
Checkmark check = new Checkmark(Timestamp.ZERO.plus(100), 50);
RepetitionRecord record = new RepetitionRecord();
record.copyFrom(rep);
assertThat(rep, equalTo(record.toRepetition()));
record.copyFrom(check);
assertThat(check, equalTo(record.toCheckmark()));
}
}

@ -105,7 +105,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
Timestamp today = DateUtils.getToday();
int[] actualCheckmarks = cache.getCheckmarks(h.getId());
int[] expectedCheckmarks =
h.getCheckmarks().getValues(today.minus(9), today);
h.getComputedCheckmarks().getValues(today.minus(9), today);
assertThat(actualCheckmarks, equalTo(expectedCheckmarks));
}

@ -86,7 +86,7 @@ public class ListHabitsBehaviorTest extends BaseUnitTest
behavior.onEdit(habit2, DateUtils.getToday());
verify(screen).showNumberPicker(eq(0.1), eq("miles"), picker.capture());
picker.getValue().onNumberPicked(100);
assertThat(habit2.getCheckmarks().getTodayValue(), equalTo(100000));
assertThat(habit2.getComputedCheckmarks().getTodayValue(), equalTo(100000));
}
@Test

@ -91,7 +91,7 @@ public class WidgetBehaviorTest extends BaseUnitTest
if(skipEnabled) nextValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
else nextValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue);
habit.getRepetitions().setValue(timestamp, currentValue);
habit.getOriginalCheckmarks().setValue(timestamp, currentValue);
behavior.onToggleRepetition(habit, timestamp);
verify(preferences).isSkipEnabled();
verify(commandRunner).execute(
@ -106,7 +106,7 @@ public class WidgetBehaviorTest extends BaseUnitTest
public void testOnIncrement()
{
habit = fixtures.createNumericalHabit();
habit.getRepetitions().setValue(timestamp, 500);
habit.getOriginalCheckmarks().setValue(timestamp, 500);
behavior.onIncrement(habit, timestamp, 100);
verify(commandRunner).execute(
@ -120,7 +120,7 @@ public class WidgetBehaviorTest extends BaseUnitTest
public void testOnDecrement()
{
habit = fixtures.createNumericalHabit();
habit.getRepetitions().setValue(timestamp, 500);
habit.getOriginalCheckmarks().setValue(timestamp, 500);
behavior.onDecrement(habit, timestamp, 100);
verify(commandRunner).execute(

Loading…
Cancel
Save