Rename Checkmark to Entry

This commit is contained in:
2020-12-23 19:08:31 -06:00
parent a3cf2877b8
commit 71597ca89b
64 changed files with 452 additions and 471 deletions

View File

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

View File

@@ -31,7 +31,7 @@ import java.util.*;
import javax.inject.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
/**
@@ -95,7 +95,7 @@ public class HabitBullCSVImporter extends AbstractImporter
map.put(name, h);
}
h.getOriginalCheckmarks().setValue(timestamp, YES_MANUAL);
h.getOriginalEntries().setValue(timestamp, YES_MANUAL);
}
}
}

View File

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

View File

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

View File

@@ -30,7 +30,7 @@ import java.util.*;
import javax.inject.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
/**
* Class that imports database files exported by Rewire.
@@ -167,7 +167,7 @@ public class RewireDBImporter extends AbstractImporter
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
cal.set(year, month - 1, day);
habit.getOriginalCheckmarks().setValue(new Timestamp(cal), YES_MANUAL);
habit.getOriginalEntries().setValue(new Timestamp(cal), YES_MANUAL);
} while (c.moveToNext());
}
finally

View File

@@ -30,7 +30,7 @@ import java.util.*;
import javax.inject.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
/**
* Class that imports data from database files exported by Tickmate.
@@ -102,7 +102,7 @@ public class TickmateDBImporter extends AbstractImporter
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
cal.set(year, month, day);
habit.getOriginalCheckmarks().setValue(new Timestamp(cal), YES_MANUAL);
habit.getOriginalEntries().setValue(new Timestamp(cal), YES_MANUAL);
} while (c.moveToNext());
}
finally

View File

@@ -30,11 +30,11 @@ import java.util.*;
import javax.annotation.concurrent.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
/**
* The collection of {@link Checkmark}s belonging to a habit.
* The collection of {@link Entry}s belonging to a habit.
*/
@ThreadSafe
public abstract class CheckmarkList
@@ -50,8 +50,8 @@ public abstract class CheckmarkList
}
@NonNull
static List<Checkmark> buildCheckmarksFromIntervals(Checkmark[] original,
ArrayList<Interval> intervals)
static List<Entry> buildEntriesFromInterval(Entry[] original,
ArrayList<Interval> intervals)
{
if (original.length == 0) throw new IllegalArgumentException();
@@ -60,9 +60,9 @@ public abstract class CheckmarkList
if (intervals.size() > 0) begin = Timestamp.oldest(begin, intervals.get(0).begin);
int nDays = begin.daysUntil(today) + 1;
List<Checkmark> checkmarks = new ArrayList<>(nDays);
List<Entry> entries = new ArrayList<>(nDays);
for (int i = 0; i < nDays; i++)
checkmarks.add(new Checkmark(today.minus(i), UNKNOWN));
entries.add(new Entry(today.minus(i), UNKNOWN));
for (Interval interval : intervals)
{
@@ -71,51 +71,50 @@ public abstract class CheckmarkList
Timestamp date = interval.begin.plus(i);
int offset = date.daysUntil(today);
if (offset < 0) continue;
checkmarks.set(offset, new Checkmark(date, YES_AUTO));
entries.set(offset, new Entry(date, YES_AUTO));
}
}
for (Checkmark c : original)
for (Entry e : original)
{
Timestamp date = c.getTimestamp();
Timestamp date = e.getTimestamp();
int offset = date.daysUntil(today);
int value = c.getValue();
int prevValue = checkmarks.get(offset).getValue();
int value = e.getValue();
int prevValue = entries.get(offset).getValue();
if (prevValue < value)
checkmarks.set(offset, new Checkmark(date, value));
entries.set(offset, new Entry(date, value));
}
return checkmarks;
return entries;
}
/**
* For non-daily habits, some groups of repetitions generate many
* checkmarks. For example, for weekly habits, each repetition generates
* For non-daily habits, some manual entries generate many
* automatic entries. For example, for weekly habits, each repetition generates
* seven checkmarks. For twice-a-week habits, two repetitions that are close
* enough together also generate seven checkmarks.
* <p>
* This group of generated checkmarks, for a given set of repetition, is
* represented by an interval. This function computes the list of intervals
* for a given list of repetitions. It tries to build the intervals as far
* away in the future as possible.
* This group of generated entries is represented by an interval. This function
* computes the list of intervals for a given list of original entries. It tries
* to build the intervals as far away in the future as possible.
*/
@NonNull
static ArrayList<Interval> buildIntervals(@NonNull Frequency freq,
@NonNull Checkmark[] checks)
@NonNull Entry[] entries)
{
ArrayList<Checkmark> filteredReps = new ArrayList<>();
for (Checkmark c : checks)
if (c.getValue() == YES_MANUAL)
filteredReps.add(c);
ArrayList<Entry> filteredEntries = new ArrayList<>();
for (Entry e : entries)
if (e.getValue() == YES_MANUAL)
filteredEntries.add(e);
int num = freq.getNumerator();
int den = freq.getDenominator();
ArrayList<Interval> intervals = new ArrayList<>();
for (int i = 0; i < filteredReps.size() - num + 1; i++)
for (int i = 0; i < filteredEntries.size() - num + 1; i++)
{
Checkmark first = filteredReps.get(i);
Checkmark last = filteredReps.get(i + num - 1);
Entry first = filteredEntries.get(i);
Entry last = filteredEntries.get(i + num - 1);
long distance = first.getTimestamp().daysUntil(last.getTimestamp());
if (distance >= den) continue;
@@ -155,15 +154,7 @@ public abstract class CheckmarkList
}
}
/**
* Adds all the given checkmarks to the list.
* <p>
* This should never be called by the application, since the checkmarks are
* computed automatically from the list of repetitions.
*
* @param checkmarks the checkmarks to be added.
*/
public abstract void add(List<Checkmark> checkmarks);
public abstract void add(List<Entry> entries);
/**
* Returns the values for all the checkmarks, since the oldest repetition of
@@ -180,7 +171,7 @@ public abstract class CheckmarkList
@NonNull
public synchronized final int[] getAllValues()
{
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
Entry oldestOriginal = habit.getOriginalEntries().getOldest();
if (oldestOriginal == null) return new int[0];
Timestamp fromTimestamp = oldestOriginal.getTimestamp();
@@ -202,8 +193,8 @@ public abstract class CheckmarkList
* @return the list of checkmarks within the interval.
*/
@NonNull
public abstract List<Checkmark> getByInterval(Timestamp fromTimestamp,
Timestamp toTimestamp);
public abstract List<Entry> getByInterval(Timestamp fromTimestamp,
Timestamp toTimestamp);
/**
* Returns the checkmark for today.
@@ -211,7 +202,7 @@ public abstract class CheckmarkList
* @return checkmark for today
*/
@Nullable
public synchronized final Checkmark getToday()
public synchronized final Entry getToday()
{
compute();
Timestamp today = DateUtils.getTodayWithOffset();
@@ -225,7 +216,7 @@ public abstract class CheckmarkList
*/
public synchronized int getTodayValue()
{
Checkmark today = getToday();
Entry today = getToday();
if (today != null) return today.getValue();
else return UNKNOWN;
}
@@ -254,7 +245,7 @@ public abstract class CheckmarkList
private int getThisIntervalValue(DateUtils.TruncateField truncateField, int firstWeekday)
{
List<Checkmark> groups = habit.getComputedCheckmarks().groupBy(truncateField, firstWeekday, 1);
List<Entry> groups = habit.getComputedEntries().groupBy(truncateField, firstWeekday, 1);
if (groups.isEmpty()) return 0;
return groups.get(0).getValue();
}
@@ -276,11 +267,11 @@ public abstract class CheckmarkList
{
if (from.isNewerThan(to)) return new int[0];
List<Checkmark> checkmarks = getByInterval(from, to);
int values[] = new int[checkmarks.size()];
List<Entry> entries = getByInterval(from, to);
int values[] = new int[entries.size()];
int i = 0;
for (Checkmark c : checkmarks)
for (Entry c : entries)
values[i++] = c.getValue();
return values;
@@ -330,20 +321,20 @@ public abstract class CheckmarkList
{
final Timestamp today = DateUtils.getTodayWithOffset();
Checkmark newest = getNewestComputed();
Entry newest = getNewestComputed();
if (newest != null && newest.getTimestamp().equals(today)) return;
invalidateNewerThan(Timestamp.ZERO);
Checkmark oldestRep = habit.getOriginalCheckmarks().getOldest();
Entry oldestRep = habit.getOriginalEntries().getOldest();
if (oldestRep == null) return;
final Timestamp from = oldestRep.getTimestamp();
if (from.isNewerThan(today)) return;
Checkmark reps[] = habit
.getOriginalCheckmarks()
Entry reps[] = habit
.getOriginalEntries()
.getByInterval(from, today)
.toArray(new Checkmark[0]);
.toArray(new Entry[0]);
if (habit.isNumerical()) computeNumerical(reps);
else computeYesNo(reps);
@@ -355,7 +346,7 @@ public abstract class CheckmarkList
* @return newest checkmark already computed
*/
@Nullable
protected abstract Checkmark getNewestComputed();
protected abstract Entry getNewestComputed();
/**
* Returns oldest checkmark that has already been computed.
@@ -363,9 +354,9 @@ public abstract class CheckmarkList
* @return oldest checkmark already computed
*/
@Nullable
protected abstract Checkmark getOldestComputed();
protected abstract Entry getOldestComputed();
private void computeNumerical(Checkmark[] original)
private void computeNumerical(Entry[] original)
{
if (original.length == 0) return;
@@ -373,29 +364,29 @@ public abstract class CheckmarkList
Timestamp begin = original[0].getTimestamp();
int nDays = begin.daysUntil(today) + 1;
List<Checkmark> computed = new ArrayList<>(nDays);
List<Entry> computed = new ArrayList<>(nDays);
for (int i = 0; i < nDays; i++)
computed.add(new Checkmark(today.minus(i), 0));
computed.add(new Entry(today.minus(i), 0));
for (Checkmark c : original)
for (Entry e : original)
{
int offset = c.getTimestamp().daysUntil(today);
computed.set(offset, new Checkmark(c.getTimestamp(), c.getValue()));
int offset = e.getTimestamp().daysUntil(today);
computed.set(offset, new Entry(e.getTimestamp(), e.getValue()));
}
add(computed);
}
private void computeYesNo(Checkmark[] original)
private void computeYesNo(Entry[] original)
{
ArrayList<Interval> intervals;
intervals = buildIntervals(habit.getFrequency(), original);
snapIntervalsTogether(intervals);
add(buildCheckmarksFromIntervals(original, intervals));
add(buildEntriesFromInterval(original, intervals));
}
public List<Checkmark> getAll() {
Checkmark oldest = habit.getOriginalCheckmarks().getOldest();
public List<Entry> getAll() {
Entry oldest = habit.getOriginalEntries().getOldest();
if(oldest == null) return new ArrayList<>();
return getByInterval(oldest.getTimestamp(), DateUtils.getTodayWithOffset());
}
@@ -457,24 +448,24 @@ public abstract class CheckmarkList
}
@NonNull
public List<Checkmark> groupBy(DateUtils.TruncateField field, int firstWeekday)
public List<Entry> groupBy(DateUtils.TruncateField field, int firstWeekday)
{
return groupBy(field, firstWeekday, 0);
}
@NonNull
public List<Checkmark> groupBy(DateUtils.TruncateField field,
int firstWeekday,
int maxGroups)
public List<Entry> groupBy(DateUtils.TruncateField field,
int firstWeekday,
int maxGroups)
{
List<Checkmark> checks = getAll();
List<Entry> checks = getAll();
int count = 0;
Timestamp[] truncatedTimestamps = new Timestamp[checks.size()];
int[] values = new int[checks.size()];
for (Checkmark rep : checks)
for (Entry rep : checks)
{
Timestamp tt = rep.getTimestamp().truncate(field, firstWeekday);
if (count == 0 || !truncatedTimestamps[count - 1].equals(tt))
@@ -485,18 +476,18 @@ public abstract class CheckmarkList
if(habit.isNumerical())
values[count - 1] += rep.getValue();
else if(rep.getValue() == Checkmark.YES_MANUAL)
else if(rep.getValue() == Entry.YES_MANUAL)
values[count - 1] += 1000;
}
ArrayList<Checkmark> groupedCheckmarks = new ArrayList<>();
ArrayList<Entry> groupedEntries = new ArrayList<>();
for (int i = 0; i < count; i++)
{
Checkmark rep = new Checkmark(truncatedTimestamps[i], values[i]);
groupedCheckmarks.add(rep);
Entry rep = new Entry(truncatedTimestamps[i], values[i]);
groupedEntries.add(rep);
}
return groupedCheckmarks;
return groupedEntries;
}
}

View File

@@ -18,45 +18,35 @@
*/
package org.isoron.uhabits.core.models
/**
* A Checkmark represents the completion status of the habit for a given day.
*
* While repetitions simply record that the habit was performed at a given date, a checkmark
* provides more information, such as whether a repetition was expected at that day or not.
*
* Checkmarks are computed automatically from the list of repetitions.
*
* Note that the status comparator in relies on SKIP > YES_MANUAL > YES_AUTO > NO.
*/
data class Checkmark(
data class Entry(
val timestamp: Timestamp,
val value: Int,
) {
companion object {
/**
* Checkmark value indicating that the habit is not applicable for this timestamp.
* Value indicating that the habit is not applicable for this timestamp.
*/
const val SKIP = 3
/**
* Checkmark value indicating that the user has performed the habit at this timestamp.
* Value indicating that the user has performed the habit at this timestamp.
*/
const val YES_MANUAL = 2
/**
* Checkmark value indicating that the user did not perform the habit, but they were not
* Value indicating that the user did not perform the habit, but they were not
* expected to, because of the frequency of the habit.
*/
const val YES_AUTO = 1
/**
* Checkmark value indicating that the user did not perform the habit, even though they were
* Value indicating that the user did not perform the habit, even though they were
* expected to perform it.
*/
const val NO = 0
/**
* Checkmark value indicating that no data is available for the given timestamp.
* Value indicating that no data is available for the given timestamp.
*/
const val UNKNOWN = -1

View File

@@ -28,7 +28,7 @@ import java.util.*;
import javax.annotation.concurrent.*;
import javax.inject.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
/**
@@ -115,7 +115,7 @@ public class Habit
}
@NonNull
public synchronized CheckmarkList getComputedCheckmarks()
public synchronized CheckmarkList getComputedEntries()
{
return checkmarks;
}
@@ -203,7 +203,7 @@ public class Habit
data.reminder = reminder;
}
public RepetitionList getOriginalCheckmarks()
public RepetitionList getOriginalEntries()
{
return repetitions;
}
@@ -296,7 +296,7 @@ public class Habit
public void invalidateNewerThan(Timestamp timestamp)
{
getScores().invalidateNewerThan(timestamp);
getComputedCheckmarks().invalidateNewerThan(timestamp);
getComputedEntries().invalidateNewerThan(timestamp);
getStreaks().invalidateNewerThan(timestamp);
}
@@ -312,7 +312,7 @@ public class Habit
public synchronized boolean isCompletedToday()
{
int todayCheckmark = getComputedCheckmarks().getTodayValue();
int todayCheckmark = getComputedEntries().getTodayValue();
if (isNumerical())
{
if(getTargetType() == AT_LEAST)

View File

@@ -178,7 +178,7 @@ public abstract class HabitList implements Iterable<Habit>
{
for (Habit h : this)
{
h.getComputedCheckmarks().invalidateNewerThan(Timestamp.ZERO);
h.getComputedEntries().invalidateNewerThan(Timestamp.ZERO);
h.getStreaks().invalidateNewerThan(Timestamp.ZERO);
h.getScores().invalidateNewerThan(Timestamp.ZERO);
}

View File

@@ -45,9 +45,9 @@ public abstract class RepetitionList
* Any implementation of this method must call observable.notifyListeners()
* after the checkmark has been added.
*
* @param checkmark the checkmark to be added.
* @param entry the checkmark to be added.
*/
public abstract void add(Checkmark checkmark);
public abstract void add(Entry entry);
/**
* Returns the list of checkmarks that happened within the given time
@@ -61,8 +61,8 @@ public abstract class RepetitionList
* @param toTimestamp timestamp of the end of the interval
* @return list of checkmarks within given time interval
*/
public abstract List<Checkmark> getByInterval(Timestamp fromTimestamp,
Timestamp toTimestamp);
public abstract List<Entry> getByInterval(Timestamp fromTimestamp,
Timestamp toTimestamp);
/**
* Returns the checkmark that has the given timestamp, or null if none
@@ -72,7 +72,7 @@ public abstract class RepetitionList
* @return the checkmark that has the given timestamp.
*/
@Nullable
public abstract Checkmark getByTimestamp(Timestamp timestamp);
public abstract Entry getByTimestamp(Timestamp timestamp);
/**
* If a checkmark with the given timestamp exists, return its value. Otherwise, returns
@@ -81,8 +81,8 @@ public abstract class RepetitionList
@NonNull
public int getValue(Timestamp timestamp)
{
Checkmark check = getByTimestamp(timestamp);
if (check == null) return Checkmark.UNKNOWN;
Entry check = getByTimestamp(timestamp);
if (check == null) return Entry.UNKNOWN;
return check.getValue();
}
@@ -101,7 +101,7 @@ public abstract class RepetitionList
* @return oldest checkmark in the list, or null if list is empty.
*/
@Nullable
public abstract Checkmark getOldest();
public abstract Entry getOldest();
@Nullable
/**
@@ -112,7 +112,7 @@ public abstract class RepetitionList
*
* @return newest checkmark in the list, or null if list is empty.
*/
public abstract Checkmark getNewest();
public abstract Entry getNewest();
/**
* Returns the total number of successful checkmarks for each month, from the first
@@ -130,17 +130,17 @@ public abstract class RepetitionList
@NonNull
public HashMap<Timestamp, Integer[]> getWeekdayFrequency()
{
List<Checkmark> checks =
List<Entry> entries =
getByInterval(Timestamp.ZERO, DateUtils.getTodayWithOffset());
HashMap<Timestamp, Integer[]> map = new HashMap<>();
for (Checkmark c : checks)
for (Entry e : entries)
{
if (!habit.isNumerical() && c.getValue() != Checkmark.YES_MANUAL)
if (!habit.isNumerical() && e.getValue() != Entry.YES_MANUAL)
continue;
Calendar date = c.getTimestamp().toCalendar();
int weekday = c.getTimestamp().getWeekday();
Calendar date = e.getTimestamp().toCalendar();
int weekday = e.getTimestamp().getWeekday();
date.set(Calendar.DAY_OF_MONTH, 1);
Timestamp timestamp = new Timestamp(date.getTimeInMillis());
@@ -167,17 +167,17 @@ public abstract class RepetitionList
* Any implementation of this method must call observable.notifyListeners()
* after the checkmark has been added.
*
* @param checkmark the checkmark to be removed
* @param entry the checkmark to be removed
*/
public abstract void remove(@NonNull Checkmark checkmark);
public abstract void remove(@NonNull Entry entry);
public abstract long getTotalCount();
public void setValue(Timestamp timestamp, int value)
{
Checkmark check = getByTimestamp(timestamp);
Entry check = getByTimestamp(timestamp);
if (check != null) remove(check);
add(new Checkmark(timestamp, value));
add(new Entry(timestamp, value));
habit.invalidateNewerThan(timestamp);
}

View File

@@ -27,7 +27,7 @@ import java.io.*;
import java.text.*;
import java.util.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
public abstract class ScoreList implements Iterable<Score>
{
@@ -201,9 +201,9 @@ public abstract class ScoreList implements Iterable<Score>
if (newestComputed == null)
{
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
if (oldestOriginal != null) from =
Timestamp.oldest(from, oldestOriginal.getTimestamp());
Entry oldest = habit.getOriginalEntries().getOldest();
if (oldest != null) from =
Timestamp.oldest(from, oldest.getTimestamp());
forceRecompute(from, to, 0);
}
else
@@ -221,11 +221,11 @@ public abstract class ScoreList implements Iterable<Score>
*/
protected void computeAll()
{
Checkmark oldestRep = habit.getOriginalCheckmarks().getOldest();
if (oldestRep == null) return;
Entry oldest = habit.getOriginalEntries().getOldest();
if (oldest == null) return;
Timestamp today = DateUtils.getTodayWithOffset();
compute(oldestRep.getTimestamp(), today);
compute(oldest.getTimestamp(), today);
}
/**
@@ -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.getComputedCheckmarks().getValues(from, to);
final int[] values = habit.getComputedEntries().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
@@ -286,26 +286,26 @@ public abstract class ScoreList implements Iterable<Score>
List<Score> scores = new LinkedList<>();
for (int i = 0; i < checkmarkValues.length; i++)
for (int i = 0; i < values.length; i++)
{
int offset = checkmarkValues.length - i - 1;
int offset = values.length - i - 1;
if (habit.isNumerical())
{
rollingSum += checkmarkValues[offset];
if (offset + denominator < checkmarkValues.length) {
rollingSum -= checkmarkValues[offset + denominator];
rollingSum += values[offset];
if (offset + denominator < values.length) {
rollingSum -= values[offset + denominator];
}
double percentageCompleted = Math.min(1, rollingSum / 1000 / habit.getTargetValue());
previousValue = Score.compute(freq, previousValue, percentageCompleted);
}
else
{
if (checkmarkValues[offset] == YES_MANUAL)
if (values[offset] == YES_MANUAL)
rollingSum += 1.0;
if (offset + denominator < checkmarkValues.length)
if (checkmarkValues[offset + denominator] == YES_MANUAL)
if (offset + denominator < values.length)
if (values[offset + denominator] == YES_MANUAL)
rollingSum -= 1.0;
if (checkmarkValues[offset] != SKIP)
if (values[offset] != SKIP)
{
double percentageCompleted = Math.min(1, rollingSum / numerator);
previousValue = Score.compute(freq, previousValue, percentageCompleted);

View File

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

View File

@@ -30,7 +30,7 @@ import java.util.*;
*/
public class MemoryCheckmarkList extends CheckmarkList
{
ArrayList<Checkmark> list;
ArrayList<Entry> list;
public MemoryCheckmarkList(Habit habit)
{
@@ -39,36 +39,36 @@ public class MemoryCheckmarkList extends CheckmarkList
}
@Override
public void add(List<Checkmark> checkmarks)
public void add(List<Entry> entries)
{
list.addAll(checkmarks);
list.addAll(entries);
Collections.sort(list,
(c1, c2) -> c2.getTimestamp().compare(c1.getTimestamp()));
}
@NonNull
@Override
public synchronized List<Checkmark> getByInterval(Timestamp from,
Timestamp to)
public synchronized List<Entry> getByInterval(Timestamp from,
Timestamp to)
{
compute();
Timestamp newestComputed = new Timestamp(0);
Timestamp oldestComputed = new Timestamp(0).plus(1000000);
Checkmark newest = getNewestComputed();
Checkmark oldest = getOldestComputed();
Entry newest = getNewestComputed();
Entry oldest = getOldestComputed();
if(newest != null) newestComputed = newest.getTimestamp();
if(oldest != null) oldestComputed = oldest.getTimestamp();
List<Checkmark> filtered = new ArrayList<>(
List<Entry> filtered = new ArrayList<>(
Math.max(0, oldestComputed.daysUntil(newestComputed) + 1));
for(int i = 0; i <= from.daysUntil(to); i++)
{
Timestamp t = to.minus(i);
if(t.isNewerThan(newestComputed) || t.isOlderThan(oldestComputed))
filtered.add(new Checkmark(t, Checkmark.UNKNOWN));
filtered.add(new Entry(t, Entry.UNKNOWN));
else
filtered.add(list.get(t.daysUntil(newestComputed)));
}
@@ -85,7 +85,7 @@ public class MemoryCheckmarkList extends CheckmarkList
@Override
@Nullable
protected Checkmark getOldestComputed()
protected Entry getOldestComputed()
{
if(list.isEmpty()) return null;
return list.get(list.size()-1);
@@ -93,7 +93,7 @@ public class MemoryCheckmarkList extends CheckmarkList
@Override
@Nullable
protected Checkmark getNewestComputed()
protected Entry getNewestComputed()
{
if(list.isEmpty()) return null;
return list.get(0);

View File

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

View File

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

View File

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

View File

@@ -66,20 +66,20 @@ public class SQLiteRepetitionList extends RepetitionList
}
@Override
public void add(Checkmark check)
public void add(Entry entry)
{
loadRecords();
list.add(check);
list.add(entry);
check(habit.getId());
RepetitionRecord record = new RepetitionRecord();
record.habit_id = habit.getId();
record.copyFrom(check);
record.copyFrom(entry);
repository.save(record);
observable.notifyListeners();
}
@Override
public List<Checkmark> getByInterval(Timestamp timeFrom, Timestamp timeTo)
public List<Entry> getByInterval(Timestamp timeFrom, Timestamp timeTo)
{
loadRecords();
return list.getByInterval(timeFrom, timeTo);
@@ -87,35 +87,35 @@ public class SQLiteRepetitionList extends RepetitionList
@Override
@Nullable
public Checkmark getByTimestamp(Timestamp timestamp)
public Entry getByTimestamp(Timestamp timestamp)
{
loadRecords();
return list.getByTimestamp(timestamp);
}
@Override
public Checkmark getOldest()
public Entry getOldest()
{
loadRecords();
return list.getOldest();
}
@Override
public Checkmark getNewest()
public Entry getNewest()
{
loadRecords();
return list.getNewest();
}
@Override
public void remove(@NonNull Checkmark checkmark)
public void remove(@NonNull Entry entry)
{
loadRecords();
list.remove(checkmark);
list.remove(entry);
check(habit.getId());
repository.execSQL(
"delete from repetitions where habit = ? and timestamp = ?",
habit.getId(), checkmark.getTimestamp().getUnixTime());
habit.getId(), entry.getTimestamp().getUnixTime());
observable.notifyListeners();
}

View File

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

View File

@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.models.sqlite.*;
import org.isoron.uhabits.core.utils.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
public class HabitFixtures
{
@@ -65,7 +65,7 @@ public class HabitFixtures
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
for (int mark : marks)
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
habit.getOriginalEntries().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.getOriginalCheckmarks().setValue(timestamp, values[i]);
habit.getOriginalEntries().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.getOriginalCheckmarks().setValue(timestamp, values[i]);
habit.getOriginalEntries().setValue(timestamp, values[i]);
}
return habit;
@@ -144,7 +144,7 @@ public class HabitFixtures
{
int value = NO;
if (c) value = YES_MANUAL;
habit.getOriginalCheckmarks().setValue(timestamp, value);
habit.getOriginalEntries().setValue(timestamp, value);
timestamp = timestamp.minus(1);
}
@@ -153,7 +153,7 @@ public class HabitFixtures
private void saveIfSQLite(Habit habit)
{
if (!(habit.getOriginalCheckmarks() instanceof SQLiteRepetitionList)) return;
if (!(habit.getOriginalEntries() instanceof SQLiteRepetitionList)) return;
habitList.add(habit);
}
}

View File

@@ -178,7 +178,7 @@ public class NotificationTray
@Override
public void doInBackground()
{
todayValue = habit.getComputedCheckmarks().getTodayValue();
todayValue = habit.getComputedEntries().getTodayValue();
}
@Override
@@ -186,7 +186,7 @@ public class NotificationTray
{
systemTray.log("Showing notification for habit=" + habit.id);
if (todayValue != Checkmark.UNKNOWN) {
if (todayValue != Entry.UNKNOWN) {
systemTray.log(String.format(
Locale.US,
"Habit %d already checked. Skipping.",

View File

@@ -22,5 +22,5 @@ package org.isoron.uhabits.core.ui.callbacks
import org.isoron.uhabits.core.models.*
interface OnToggleCheckmarkListener {
fun onToggleCheckmark(timestamp: Timestamp, value: Int) {}
fun onToggleEntry(timestamp: Timestamp, value: Int) {}
}

View File

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

View File

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

View File

@@ -54,10 +54,10 @@ class ShowHabitBehavior(
screen.showHistoryEditorDialog(this)
}
override fun onToggleCheckmark(timestamp: Timestamp, value: Int) {
override fun onToggleEntry(timestamp: Timestamp, value: Int) {
if (habit.isNumerical) {
val checkmarks = habit.computedCheckmarks
val oldValue = checkmarks.getValues(timestamp, timestamp)[0].toDouble()
val entries = habit.computedEntries
val oldValue = entries.getValues(timestamp, timestamp)[0].toDouble()
screen.showNumberPicker(oldValue / 1000, habit.unit) { newValue: Double ->
val thousands = Math.round(newValue * 1000).toInt()
commandRunner.execute(

View File

@@ -58,14 +58,14 @@ class ShowHabitMenuBehavior(
fun onRandomize() {
val random = Random()
habit.originalCheckmarks.removeAll()
habit.originalEntries.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
var value = Entry.YES_MANUAL
if (habit.isNumerical) value = (1000 + 250 * random.nextGaussian() * strength / 100).toInt() * 1000
habit.originalCheckmarks.setValue(DateUtils.getToday().minus(i), value)
habit.originalEntries.setValue(DateUtils.getToday().minus(i), value)
}
habit.invalidateNewerThan(Timestamp.ZERO)
screen.refresh()

View File

@@ -29,7 +29,7 @@ import org.jetbrains.annotations.*;
import javax.inject.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
public class WidgetBehavior
{
@@ -70,24 +70,24 @@ public class WidgetBehavior
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
{
int currentValue = habit.getOriginalCheckmarks().getValue(timestamp);
int currentValue = habit.getOriginalEntries().getValue(timestamp);
int newValue;
if(preferences.isSkipEnabled())
newValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
newValue = Entry.Companion.nextToggleValueWithSkip(currentValue);
else
newValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue);
newValue = Entry.Companion.nextToggleValueWithoutSkip(currentValue);
setValue(habit, timestamp, newValue);
notificationTray.cancel(habit);
}
public void onIncrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
int currentValue = habit.getComputedCheckmarks().getValues(timestamp, timestamp)[0];
int currentValue = habit.getComputedEntries().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.getComputedCheckmarks().getValues(timestamp, timestamp)[0];
int currentValue = habit.getComputedEntries().getValues(timestamp, timestamp)[0];
setValue(habit, timestamp, currentValue - amount);
notificationTray.cancel(habit);
}

View File

@@ -24,7 +24,7 @@ import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*;
import org.junit.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.junit.Assert.*;
public class CreateRepetitionCommandTest extends BaseUnitTest
@@ -51,13 +51,13 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
@Test
public void testExecute()
{
RepetitionList reps = habit.getOriginalCheckmarks();
Checkmark check = reps.getByTimestamp(today);
assertNotNull(check);
assertEquals(YES_MANUAL, check.getValue());
RepetitionList originalEntries = habit.getOriginalEntries();
Entry entry = originalEntries.getByTimestamp(today);
assertNotNull(entry);
assertEquals(YES_MANUAL, entry.getValue());
command.execute();
check = reps.getByTimestamp(today);
assertNotNull(check);
assertEquals(100, check.getValue());
entry = originalEntries.getByTimestamp(today);
assertNotNull(entry);
assertEquals(100, entry.getValue());
}
}

View File

@@ -30,7 +30,7 @@ import java.util.*;
import static junit.framework.TestCase.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.isoron.uhabits.core.models.Frequency.*;
import static org.junit.Assert.assertTrue;
@@ -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.getOriginalCheckmarks().getValue(timestamp) == YES_MANUAL;
return h.getOriginalEntries().getValue(timestamp) == YES_MANUAL;
}
private void importFromFile(String assetFilename) throws IOException

View File

@@ -31,12 +31,12 @@ import nl.jqno.equalsverifier.*;
import static java.util.Calendar.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsEqual.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.isoron.uhabits.core.utils.DateUtils.TruncateField.MONTH;
import static org.isoron.uhabits.core.utils.DateUtils.TruncateField.QUARTER;
import static org.isoron.uhabits.core.utils.DateUtils.TruncateField.YEAR;
public class CheckmarkListTest extends BaseUnitTest
public class EntryListTest extends BaseUnitTest
{
private long dayLength;
@@ -67,11 +67,11 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_buildCheckmarksFromIntervals_1() throws Exception
{
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),
Entry entries[] = new Entry[]{
new Entry(day(10), YES_MANUAL),
new Entry(day(5), YES_MANUAL),
new Entry(day(2), YES_MANUAL),
new Entry(day(1), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
@@ -79,49 +79,49 @@ public class CheckmarkListTest extends BaseUnitTest
intervals.add(new CheckmarkList.Interval(day(6), day(5), day(4)));
intervals.add(new CheckmarkList.Interval(day(2), day(2), day(1)));
List<Checkmark> expected = new ArrayList<>();
expected.add(new Checkmark(day(0), UNKNOWN));
expected.add(new Checkmark(day(1), YES_MANUAL));
expected.add(new Checkmark(day(2), YES_MANUAL));
expected.add(new Checkmark(day(3), UNKNOWN));
expected.add(new Checkmark(day(4), YES_AUTO));
expected.add(new Checkmark(day(5), YES_MANUAL));
expected.add(new Checkmark(day(6), YES_AUTO));
expected.add(new Checkmark(day(7), UNKNOWN));
expected.add(new Checkmark(day(8), YES_AUTO));
expected.add(new Checkmark(day(9), YES_AUTO));
expected.add(new Checkmark(day(10), YES_MANUAL));
List<Entry> expected = new ArrayList<>();
expected.add(new Entry(day(0), UNKNOWN));
expected.add(new Entry(day(1), YES_MANUAL));
expected.add(new Entry(day(2), YES_MANUAL));
expected.add(new Entry(day(3), UNKNOWN));
expected.add(new Entry(day(4), YES_AUTO));
expected.add(new Entry(day(5), YES_MANUAL));
expected.add(new Entry(day(6), YES_AUTO));
expected.add(new Entry(day(7), UNKNOWN));
expected.add(new Entry(day(8), YES_AUTO));
expected.add(new Entry(day(9), YES_AUTO));
expected.add(new Entry(day(10), YES_MANUAL));
List<Checkmark> actual =
CheckmarkList.buildCheckmarksFromIntervals(checks, intervals);
List<Entry> actual =
CheckmarkList.buildEntriesFromInterval(entries, intervals);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildCheckmarksFromIntervals_2() throws Exception
{
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(0), YES_MANUAL),
Entry entries[] = new Entry[]{
new Entry(day(0), YES_MANUAL),
};
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
intervals.add(new CheckmarkList.Interval(day(0), day(0), day(-10)));
List<Checkmark> expected = new ArrayList<>();
expected.add(new Checkmark(day(0), YES_MANUAL));
List<Entry> expected = new ArrayList<>();
expected.add(new Entry(day(0), YES_MANUAL));
List<Checkmark> actual =
CheckmarkList.buildCheckmarksFromIntervals(checks, intervals);
List<Entry> actual =
CheckmarkList.buildEntriesFromInterval(entries, intervals);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildIntervals_1() throws Exception
{
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(23), YES_MANUAL),
new Checkmark(day(18), YES_MANUAL),
new Checkmark(day(8), YES_MANUAL),
Entry entries[] = new Entry[]{
new Entry(day(23), YES_MANUAL),
new Entry(day(18), YES_MANUAL),
new Entry(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, checks);
actual = CheckmarkList.buildIntervals(Frequency.WEEKLY, entries);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildIntervals_2() throws Exception
{
Checkmark checks[] = new Checkmark[]{
new Checkmark(day(23), YES_MANUAL),
new Checkmark(day(18), YES_MANUAL),
new Checkmark(day(8), YES_MANUAL),
Entry entries[] = new Entry[]{
new Entry(day(23), YES_MANUAL),
new Entry(day(18), YES_MANUAL),
new Entry(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, checks);
actual = CheckmarkList.buildIntervals(Frequency.DAILY, entries);
assertThat(actual, equalTo(expected));
}
@Test
public void test_buildIntervals_3() throws Exception
{
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),
Entry entries[] = new Entry[]{
new Entry(day(23), YES_MANUAL),
new Entry(day(22), YES_MANUAL),
new Entry(day(18), YES_MANUAL),
new Entry(day(15), YES_MANUAL),
new Entry(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, checks);
CheckmarkList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, entries);
assertThat(actual, equalTo(expected));
}
@@ -179,10 +179,10 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_buildIntervals_4() throws Exception
{
Checkmark[] checks = new Checkmark[]{
new Checkmark(day(30), YES_MANUAL),
new Checkmark(day(20), SKIP),
new Checkmark(day(10), YES_MANUAL),
Entry[] entries = new Entry[]{
new Entry(day(30), YES_MANUAL),
new Entry(day(20), SKIP),
new Entry(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), checks);
actual = CheckmarkList.buildIntervals(new Frequency(1, 3), entries);
assertThat(actual, equalTo(expected));
}
@@ -209,7 +209,7 @@ public class CheckmarkListTest extends BaseUnitTest
YES_MANUAL
};
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
int[] actualValues = nonDailyHabit.getComputedEntries().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@@ -235,7 +235,7 @@ public class CheckmarkListTest extends BaseUnitTest
YES_MANUAL
};
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
int[] actualValues = nonDailyHabit.getComputedEntries().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.getComputedCheckmarks().getAllValues();
int[] actualValues = emptyHabit.getComputedEntries().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@@ -265,7 +265,7 @@ public class CheckmarkListTest extends BaseUnitTest
YES_MANUAL
};
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
int[] actualValues = nonDailyHabit.getComputedEntries().getAllValues();
assertThat(actualValues, equalTo(expectedValues));
}
@@ -273,37 +273,37 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void test_getByInterval_withNumericalHabits() throws Exception
{
CheckmarkList checkmarks = numericalHabit.getComputedCheckmarks();
CheckmarkList entries = numericalHabit.getComputedEntries();
List<Checkmark> expected =
Arrays.asList(new Checkmark(day(1), 200), new Checkmark(day(2), 0),
new Checkmark(day(3), 300), new Checkmark(day(4), 0),
new Checkmark(day(5), 400));
List<Entry> expected =
Arrays.asList(new Entry(day(1), 200), new Entry(day(2), 0),
new Entry(day(3), 300), new Entry(day(4), 0),
new Entry(day(5), 400));
List<Checkmark> actual = checkmarks.getByInterval(day(5), day(1));
List<Entry> actual = entries.getByInterval(day(5), day(1));
assertThat(actual, equalTo(expected));
}
@Test
public void test_getTodayValue()
{
CheckmarkList checkmarks = nonDailyHabit.getComputedCheckmarks();
CheckmarkList entries = nonDailyHabit.getComputedEntries();
travelInTime(-1);
assertThat(checkmarks.getTodayValue(), equalTo(NO));
assertThat(entries.getTodayValue(), equalTo(NO));
travelInTime(0);
assertThat(checkmarks.getTodayValue(), equalTo(YES_MANUAL));
assertThat(entries.getTodayValue(), equalTo(YES_MANUAL));
travelInTime(1);
assertThat(checkmarks.getTodayValue(), equalTo(UNKNOWN));
assertThat(entries.getTodayValue(), equalTo(UNKNOWN));
}
@Test
public void test_getValues_withInvalidInterval()
{
int values[] = nonDailyHabit
.getComputedCheckmarks()
.getComputedEntries()
.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.getComputedCheckmarks().getValues(from, to);
int[] actualValues = nonDailyHabit.getComputedEntries().getValues(from, to);
assertThat(actualValues, equalTo(expectedValues));
}
@@ -376,7 +376,7 @@ public class CheckmarkListTest extends BaseUnitTest
StringWriter writer = new StringWriter();
nonDailyHabit.getComputedCheckmarks().writeCSV(writer);
nonDailyHabit.getComputedEntries().writeCSV(writer);
assertThat(writer.toString(), equalTo(expectedCSV));
}
@@ -395,7 +395,7 @@ public class CheckmarkListTest extends BaseUnitTest
@Test
public void testEquals() throws Exception
{
EqualsVerifier.forClass(Checkmark.class).verify();
EqualsVerifier.forClass(Entry.class).verify();
EqualsVerifier.forClass(Timestamp.class).verify();
EqualsVerifier.forClass(CheckmarkList.Interval.class).verify();
}
@@ -404,33 +404,33 @@ public class CheckmarkListTest extends BaseUnitTest
public void testGroupBy() throws Exception
{
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
CheckmarkList checkmarks = habit.getComputedCheckmarks();
CheckmarkList entries = habit.getComputedEntries();
List<Checkmark> byMonth = checkmarks.groupBy(MONTH, Calendar.SATURDAY);
List<Entry> byMonth = entries.groupBy(MONTH, Calendar.SATURDAY);
assertThat(byMonth.size(), equalTo(25)); // from 2013-01-01 to 2015-01-01
assertThat(byMonth.get(0), equalTo(new Checkmark(timestamp(2015, JANUARY, 1), 0)));
assertThat(byMonth.get(6), equalTo(new Checkmark(timestamp(2014, JULY, 1), 0)));
assertThat(byMonth.get(12), equalTo(new Checkmark(timestamp(2014, JANUARY, 1), 1706)));
assertThat(byMonth.get(18), equalTo(new Checkmark(timestamp(2013, JULY, 1), 1379)));
assertThat(byMonth.get(0), equalTo(new Entry(timestamp(2015, JANUARY, 1), 0)));
assertThat(byMonth.get(6), equalTo(new Entry(timestamp(2014, JULY, 1), 0)));
assertThat(byMonth.get(12), equalTo(new Entry(timestamp(2014, JANUARY, 1), 1706)));
assertThat(byMonth.get(18), equalTo(new Entry(timestamp(2013, JULY, 1), 1379)));
List<Checkmark> byQuarter = checkmarks.groupBy(QUARTER, Calendar.SATURDAY);
List<Entry> byQuarter = entries.groupBy(QUARTER, Calendar.SATURDAY);
assertThat(byQuarter.size(), equalTo(9)); // from 2013-Q1 to 2015-Q1
assertThat(byQuarter.get(0), equalTo(new Checkmark(timestamp(2015, JANUARY, 1), 0)));
assertThat(byQuarter.get(4), equalTo(new Checkmark(timestamp(2014, JANUARY, 1), 4964)));
assertThat(byQuarter.get(8), equalTo(new Checkmark(timestamp(2013, JANUARY, 1), 4975)));
assertThat(byQuarter.get(0), equalTo(new Entry(timestamp(2015, JANUARY, 1), 0)));
assertThat(byQuarter.get(4), equalTo(new Entry(timestamp(2014, JANUARY, 1), 4964)));
assertThat(byQuarter.get(8), equalTo(new Entry(timestamp(2013, JANUARY, 1), 4975)));
List<Checkmark> byYear = checkmarks.groupBy(YEAR, Calendar.SATURDAY);
List<Entry> byYear = entries.groupBy(YEAR, Calendar.SATURDAY);
assertThat(byYear.size(), equalTo(3)); // from 2013 to 2015
assertThat(byYear.get(0), equalTo(new Checkmark(timestamp(2015, JANUARY, 1), 0)));
assertThat(byYear.get(1), equalTo(new Checkmark(timestamp(2014, JANUARY, 1), 8227)));
assertThat(byYear.get(2), equalTo(new Checkmark(timestamp(2013, JANUARY, 1), 16172)));
assertThat(byYear.get(0), equalTo(new Entry(timestamp(2015, JANUARY, 1), 0)));
assertThat(byYear.get(1), equalTo(new Entry(timestamp(2014, JANUARY, 1), 8227)));
assertThat(byYear.get(2), equalTo(new Entry(timestamp(2013, JANUARY, 1), 16172)));
}
@Test
public void testGetTodayValue() throws Exception
{
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
CheckmarkList checkmarks = habit.getComputedCheckmarks();
CheckmarkList checkmarks = habit.getComputedEntries();
DateUtils.setFixedLocalTime(unixTime(2050, MAY, 1));
assertThat(checkmarks.getTodayValue(), equalTo(0));

View File

@@ -49,8 +49,8 @@ public class HabitTest extends BaseUnitTest
assertThat(habit.hasReminder(), is(false));
assertNotNull(habit.getStreaks());
assertNotNull(habit.getScores());
assertNotNull(habit.getOriginalCheckmarks());
assertNotNull(habit.getComputedCheckmarks());
assertNotNull(habit.getOriginalEntries());
assertNotNull(habit.getComputedEntries());
}
@Test
@@ -89,7 +89,7 @@ public class HabitTest extends BaseUnitTest
{
Habit h = modelFactory.buildHabit();
assertFalse(h.isCompletedToday());
h.getOriginalCheckmarks().setValue(getToday(), Checkmark.YES_MANUAL);
h.getOriginalEntries().setValue(getToday(), Entry.YES_MANUAL);
assertTrue(h.isCompletedToday());
}
@@ -102,19 +102,19 @@ public class HabitTest extends BaseUnitTest
h.setTargetValue(100.0);
assertFalse(h.isCompletedToday());
h.getOriginalCheckmarks().setValue(getToday(), 200_000);
h.getOriginalEntries().setValue(getToday(), 200_000);
assertTrue(h.isCompletedToday());
h.getOriginalCheckmarks().setValue(getToday(), 100_000);
h.getOriginalEntries().setValue(getToday(), 100_000);
assertTrue(h.isCompletedToday());
h.getOriginalCheckmarks().setValue(getToday(), 50_000);
h.getOriginalEntries().setValue(getToday(), 50_000);
assertFalse(h.isCompletedToday());
h.setTargetType(Habit.AT_MOST);
h.getOriginalCheckmarks().setValue(getToday(), 200_000);
h.getOriginalEntries().setValue(getToday(), 200_000);
assertFalse(h.isCompletedToday());
h.getOriginalCheckmarks().setValue(getToday(), 100_000);
h.getOriginalEntries().setValue(getToday(), 100_000);
assertTrue(h.isCompletedToday());
h.getOriginalCheckmarks().setValue(getToday(), 50_000);
h.getOriginalEntries().setValue(getToday(), 50_000);
assertTrue(h.isCompletedToday());
}

View File

@@ -30,7 +30,7 @@ import java.util.*;
import static java.util.Calendar.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsEqual.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.mockito.Mockito.*;
public class RepetitionListTest extends BaseUnitTest
@@ -54,7 +54,7 @@ public class RepetitionListTest extends BaseUnitTest
{
super.setUp();
habit = fixtures.createEmptyHabit();
reps = habit.getOriginalCheckmarks();
reps = habit.getOriginalEntries();
today = DateUtils.getToday();
@@ -79,7 +79,7 @@ public class RepetitionListTest extends BaseUnitTest
@Test
public void test_getOldest()
{
Checkmark check = reps.getOldest();
Entry check = reps.getOldest();
assertThat(check.getTimestamp(), equalTo(today.minus(7)));
}
@@ -87,7 +87,7 @@ public class RepetitionListTest extends BaseUnitTest
public void test_getWeekDayFrequency()
{
habit = fixtures.createEmptyHabit();
reps = habit.getOriginalCheckmarks();
reps = habit.getOriginalEntries();
Random random = new Random(123L);
Integer weekdayCount[][] = new Integer[12][7];

View File

@@ -30,7 +30,7 @@ import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.hamcrest.number.OrderingComparison.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
public class ScoreListTest extends BaseUnitTest
{
@@ -326,34 +326,34 @@ public class ScoreListTest extends BaseUnitTest
private void check(final int offset)
{
RepetitionList reps = habit.getOriginalCheckmarks();
RepetitionList entries = habit.getOriginalEntries();
Timestamp today = DateUtils.getToday();
reps.setValue(today.minus(offset), YES_MANUAL);
entries.setValue(today.minus(offset), YES_MANUAL);
}
private void check(final int from, final int to)
{
RepetitionList reps = habit.getOriginalCheckmarks();
RepetitionList entries = habit.getOriginalEntries();
Timestamp today = DateUtils.getToday();
for (int i = from; i < to; i++)
reps.setValue(today.minus(i), YES_MANUAL);
entries.setValue(today.minus(i), YES_MANUAL);
}
private void check(ArrayList<Integer> values)
{
RepetitionList reps = habit.getOriginalCheckmarks();
RepetitionList entries = habit.getOriginalEntries();
Timestamp today = DateUtils.getToday();
for (int i = 0; i < values.size(); i++)
if (values.get(i) == YES_MANUAL)
reps.setValue(today.minus(i), YES_MANUAL);
entries.setValue(today.minus(i), YES_MANUAL);
}
private void addSkip(final int day)
{
RepetitionList reps = habit.getOriginalCheckmarks();
RepetitionList entries = habit.getOriginalEntries();
Timestamp today = DateUtils.getToday();
reps.setValue(today.minus(day), Checkmark.SKIP);
entries.setValue(today.minus(day), Entry.SKIP);
}
private void checkScoreValues(double[] expectedValues)

View File

@@ -34,7 +34,7 @@ import java.util.*;
import static junit.framework.TestCase.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsEqual.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
public class SQLiteRepetitionListTest extends BaseUnitTest
{
@@ -60,7 +60,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
repository = new Repository<>(RepetitionRecord.class, db);
habit = fixtures.createLongHabit();
originalCheckmarks = habit.getOriginalCheckmarks();
originalCheckmarks = habit.getOriginalEntries();
today = DateUtils.getToday();
}
@@ -70,8 +70,8 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
RepetitionRecord record = getByTimestamp(today.plus(1));
assertNull(record);
Checkmark rep = new Checkmark(today.plus(1), YES_MANUAL);
habit.getOriginalCheckmarks().add(rep);
Entry rep = new Entry(today.plus(1), YES_MANUAL);
habit.getOriginalEntries().add(rep);
record = getByTimestamp(today.plus(1));
assertNotNull(record);
@@ -81,7 +81,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
@Test
public void testGetByInterval()
{
List<Checkmark> checks =
List<Entry> checks =
originalCheckmarks.getByInterval(today.minus(10), today);
assertThat(checks.size(), equalTo(8));
@@ -93,7 +93,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
@Test
public void testGetByTimestamp()
{
Checkmark rep = originalCheckmarks.getByTimestamp(today);
Entry rep = originalCheckmarks.getByTimestamp(today);
assertNotNull(rep);
assertThat(rep.getTimestamp(), equalTo(today));
@@ -104,7 +104,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
@Test
public void testGetOldest()
{
Checkmark rep = originalCheckmarks.getOldest();
Entry 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();
Checkmark rep = empty.getOriginalCheckmarks().getOldest();
Entry rep = empty.getOriginalEntries().getOldest();
assertNull(rep);
}
@@ -123,7 +123,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
RepetitionRecord record = getByTimestamp(today);
assertNotNull(record);
Checkmark rep = record.toCheckmark();
Entry rep = record.toCheckmark();
originalCheckmarks.remove(rep);
record = getByTimestamp(today);

View File

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

View File

@@ -84,7 +84,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
{
Habit h2 = habitList.getByPosition(2);
Timestamp today = DateUtils.getToday();
commandRunner.execute(new CreateRepetitionCommand(habitList, h2, today, Checkmark.NO), h2.getId());
commandRunner.execute(new CreateRepetitionCommand(habitList, h2, today, Entry.NO), h2.getId());
verify(listener).onItemChanged(2);
verify(listener).onRefreshFinished();
verifyNoMoreInteractions(listener);
@@ -105,7 +105,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
Timestamp today = DateUtils.getToday();
int[] actualCheckmarks = cache.getCheckmarks(h.getId());
int[] expectedCheckmarks =
h.getComputedCheckmarks().getValues(today.minus(9), today);
h.getComputedEntries().getValues(today.minus(9), today);
assertThat(actualCheckmarks, equalTo(expectedCheckmarks));
}

View File

@@ -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.getComputedCheckmarks().getTodayValue(), equalTo(100000));
assertThat(habit2.getComputedEntries().getTodayValue(), equalTo(100000));
}
@Test
@@ -173,7 +173,7 @@ public class ListHabitsBehaviorTest extends BaseUnitTest
public void testOnToggle()
{
assertTrue(habit1.isCompletedToday());
behavior.onToggle(habit1, DateUtils.getToday(), Checkmark.NO);
behavior.onToggle(habit1, DateUtils.getToday(), Entry.NO);
assertFalse(habit1.isCompletedToday());
}

View File

@@ -28,7 +28,7 @@ import org.junit.*;
import java.util.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.models.Entry.*;
import static org.mockito.Mockito.*;
public class WidgetBehaviorTest extends BaseUnitTest
@@ -88,10 +88,10 @@ public class WidgetBehaviorTest extends BaseUnitTest
when(preferences.isSkipEnabled()).thenReturn(skipEnabled);
int nextValue;
if(skipEnabled) nextValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
else nextValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue);
if(skipEnabled) nextValue = Entry.Companion.nextToggleValueWithSkip(currentValue);
else nextValue = Entry.Companion.nextToggleValueWithoutSkip(currentValue);
habit.getOriginalCheckmarks().setValue(timestamp, currentValue);
habit.getOriginalEntries().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.getOriginalCheckmarks().setValue(timestamp, 500);
habit.getOriginalEntries().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.getOriginalCheckmarks().setValue(timestamp, 500);
habit.getOriginalEntries().setValue(timestamp, 500);
behavior.onDecrement(habit, timestamp, 100);
verify(commandRunner).execute(