mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
EntryList: remove getValues
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.isoron.uhabits.core.io
|
||||
|
||||
import org.isoron.uhabits.core.models.Entry
|
||||
import org.isoron.uhabits.core.models.EntryList
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
@@ -148,10 +149,10 @@ class HabitsCSVExporter(
|
||||
val timeframe = getTimeframe()
|
||||
val oldest = timeframe[0]
|
||||
val newest = DateUtils.getToday()
|
||||
val checkmarks: MutableList<IntArray> = ArrayList()
|
||||
val checkmarks: MutableList<ArrayList<Entry>> = ArrayList()
|
||||
val scores: MutableList<ArrayList<Score>> = ArrayList()
|
||||
for (habit in selectedHabits) {
|
||||
checkmarks.add(habit.computedEntries.getValues(oldest, newest))
|
||||
checkmarks.add(ArrayList(habit.computedEntries.getByInterval(oldest, newest)))
|
||||
scores.add(ArrayList(habit.scores.getByInterval(oldest, newest)))
|
||||
}
|
||||
|
||||
|
||||
@@ -189,39 +189,6 @@ open class EntryList {
|
||||
return map
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the values of the entries that fall inside a certain interval of time. The values
|
||||
* are returned in an array containing one integer value for each day of the interval. The
|
||||
* first entry corresponds to the most recent day in the interval. Each subsequent entry
|
||||
* corresponds to one day older than the previous entry. The boundaries of the time interval
|
||||
* are included.
|
||||
*/
|
||||
@Deprecated("")
|
||||
@Synchronized
|
||||
fun getValues(from: Timestamp, to: Timestamp): IntArray {
|
||||
if (from.isNewerThan(to)) throw IllegalArgumentException()
|
||||
val nDays = from.daysUntil(to) + 1
|
||||
val result = IntArray(nDays) { UNKNOWN }
|
||||
getKnown().filter { entry ->
|
||||
!entry.timestamp.isNewerThan(to) && !entry.timestamp.isOlderThan(from)
|
||||
}.forEach { entry ->
|
||||
val offset = entry.timestamp.daysUntil(to)
|
||||
result[offset] = entry.value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
@Synchronized
|
||||
fun getAllValues(): IntArray {
|
||||
val entries = getKnown()
|
||||
if (entries.isEmpty()) return IntArray(0)
|
||||
var (fromTimestamp, _) = entries.last()
|
||||
val toTimestamp = DateUtils.getTodayWithOffset()
|
||||
if (fromTimestamp.isNewerThan(toTimestamp)) fromTimestamp = toTimestamp
|
||||
return getValues(fromTimestamp, toTimestamp)
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
@Synchronized
|
||||
open fun getThisWeekValue(firstWeekday: Int, isNumerical: Boolean): Int {
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.core.ui.screens.habits.list;
|
||||
|
||||
import androidx.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
@@ -363,9 +364,12 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
if (targetId != null && !targetId.equals(id)) continue;
|
||||
|
||||
newData.scores.put(id, habit.getScores().get(today).getValue());
|
||||
newData.checkmarks.put(
|
||||
id,
|
||||
habit.getComputedEntries().getValues(dateFrom, today));
|
||||
Integer[] entries = habit.getComputedEntries()
|
||||
.getByInterval(dateFrom, today)
|
||||
.stream()
|
||||
.map(Entry::getValue)
|
||||
.toArray(Integer[]::new);
|
||||
newData.checkmarks.put(id, ArrayUtils.toPrimitive(entries));
|
||||
|
||||
runner.publishProgress(this, position);
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ public class WidgetBehavior
|
||||
}
|
||||
|
||||
public void onIncrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
|
||||
int currentValue = habit.getComputedEntries().getValues(timestamp, timestamp)[0];
|
||||
int currentValue = habit.getComputedEntries().get(timestamp).getValue();
|
||||
setValue(habit, timestamp, currentValue + amount);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
public void onDecrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
|
||||
int currentValue = habit.getComputedEntries().getValues(timestamp, timestamp)[0];
|
||||
int currentValue = habit.getComputedEntries().get(timestamp).getValue();
|
||||
setValue(habit, timestamp, currentValue - amount);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
@@ -65,27 +65,6 @@ class EntryListTest {
|
||||
assertEquals(Entry(today.minus(5), 20), actual[5])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetValues() {
|
||||
val entries = EntryList()
|
||||
val today = DateUtils.getToday()
|
||||
|
||||
entries.add(Entry(today.minus(3), YES_MANUAL))
|
||||
entries.add(Entry(today.minus(5), YES_MANUAL))
|
||||
entries.add(Entry(today.minus(6), YES_MANUAL))
|
||||
|
||||
val expected = intArrayOf(
|
||||
UNKNOWN, // 1
|
||||
UNKNOWN, // 2
|
||||
YES_MANUAL, // 3
|
||||
UNKNOWN, // 4
|
||||
YES_MANUAL, // 5
|
||||
YES_MANUAL, // 6
|
||||
UNKNOWN, // 7
|
||||
)
|
||||
assertThat(entries.getValues(today.minus(7), today.minus(1)), equalTo(expected))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testComputeBoolean() {
|
||||
val today = DateUtils.getToday()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.isoron.uhabits.core.ui.screens.habits.list;
|
||||
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
@@ -104,7 +105,11 @@ public class HabitCardListCacheTest extends BaseUnitTest
|
||||
assertThat(cache.getScore(h.getId()), equalTo(score));
|
||||
|
||||
int[] actualCheckmarks = cache.getCheckmarks(h.getId());
|
||||
int[] expectedCheckmarks = h.getComputedEntries().getValues(today.minus(9), today);
|
||||
int[] expectedCheckmarks = ArrayUtils.toPrimitive(h.getComputedEntries()
|
||||
.getByInterval(today.minus(9), today)
|
||||
.stream()
|
||||
.map(Entry::getValue)
|
||||
.toArray(Integer[]::new));
|
||||
|
||||
assertThat(actualCheckmarks, equalTo(expectedCheckmarks));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user