mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Remove MemoryScoreList
This commit is contained in:
@@ -29,8 +29,10 @@ import java.util.*;
|
|||||||
|
|
||||||
import static org.isoron.uhabits.core.models.Entry.*;
|
import static org.isoron.uhabits.core.models.Entry.*;
|
||||||
|
|
||||||
public abstract class ScoreList implements Iterable<Score>
|
public class ScoreList implements Iterable<Score>
|
||||||
{
|
{
|
||||||
|
ArrayList<Score> list = new ArrayList<>();
|
||||||
|
|
||||||
protected Habit habit;
|
protected Habit habit;
|
||||||
|
|
||||||
public void setHabit(Habit habit)
|
public void setHabit(Habit habit)
|
||||||
@@ -46,7 +48,12 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
*
|
*
|
||||||
* @param scores the scores to add.
|
* @param scores the scores to add.
|
||||||
*/
|
*/
|
||||||
public abstract void add(List<Score> scores);
|
public void add(List<Score> scores)
|
||||||
|
{
|
||||||
|
list.addAll(scores);
|
||||||
|
Collections.sort(list,
|
||||||
|
(s1, s2) -> s2.getTimestamp().compareTo(s1.getTimestamp()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the score for today.
|
* Returns the value of the score for today.
|
||||||
@@ -88,8 +95,23 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
* @return the list of scores within the interval.
|
* @return the list of scores within the interval.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract List<Score> getByInterval(@NonNull Timestamp fromTimestamp,
|
public List<Score> getByInterval(@NonNull Timestamp fromTimestamp,
|
||||||
@NonNull Timestamp toTimestamp);
|
@NonNull Timestamp toTimestamp)
|
||||||
|
{
|
||||||
|
compute(fromTimestamp, toTimestamp);
|
||||||
|
|
||||||
|
List<Score> filtered = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Score s : list)
|
||||||
|
{
|
||||||
|
if (s.getTimestamp().isNewerThan(toTimestamp) ||
|
||||||
|
s.getTimestamp().isOlderThan(fromTimestamp)) continue;
|
||||||
|
filtered.add(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the scores that fall inside a certain interval
|
* Returns the values of the scores that fall inside a certain interval
|
||||||
@@ -124,7 +146,10 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
return scores;
|
return scores;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void recompute();
|
public void recompute()
|
||||||
|
{
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Score> iterator()
|
public Iterator<Score> iterator()
|
||||||
@@ -141,7 +166,11 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
*
|
*
|
||||||
* @return list of scores
|
* @return list of scores
|
||||||
*/
|
*/
|
||||||
public abstract List<Score> toList();
|
public List<Score> toList()
|
||||||
|
{
|
||||||
|
computeAll();
|
||||||
|
return new LinkedList<>(list);
|
||||||
|
}
|
||||||
|
|
||||||
public void writeCSV(Writer out) throws IOException
|
public void writeCSV(Writer out) throws IOException
|
||||||
{
|
{
|
||||||
@@ -216,21 +245,36 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
* @return the score with given timestamp, or null not yet computed.
|
* @return the score with given timestamp, or null not yet computed.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract Score getComputedByTimestamp(Timestamp timestamp);
|
protected Score getComputedByTimestamp(Timestamp timestamp)
|
||||||
|
{
|
||||||
|
for (Score s : list)
|
||||||
|
if (s.getTimestamp().equals(timestamp)) return s;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the most recent score that has already been computed. If no score
|
* Returns the most recent score that has already been computed. If no score
|
||||||
* has been computed yet, returns null.
|
* has been computed yet, returns null.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract Score getNewestComputed();
|
protected Score getNewestComputed()
|
||||||
|
{
|
||||||
|
if (list.isEmpty()) return null;
|
||||||
|
return list.get(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns oldest score already computed. If no score has been computed yet,
|
* Returns oldest score already computed. If no score has been computed yet,
|
||||||
* returns null.
|
* returns null.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract Score getOldestComputed();
|
protected Score getOldestComputed()
|
||||||
|
{
|
||||||
|
if (list.isEmpty()) return null;
|
||||||
|
return list.get(list.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes and stores one score for each day inside the given interval.
|
* Computes and stores one score for each day inside the given interval.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class MemoryModelFactory : ModelFactory {
|
|||||||
override fun buildComputedEntries() = EntryList()
|
override fun buildComputedEntries() = EntryList()
|
||||||
override fun buildOriginalEntries() = EntryList()
|
override fun buildOriginalEntries() = EntryList()
|
||||||
override fun buildHabitList() = MemoryHabitList()
|
override fun buildHabitList() = MemoryHabitList()
|
||||||
override fun buildScoreList() = MemoryScoreList()
|
override fun buildScoreList() = ScoreList()
|
||||||
override fun buildStreakList() = MemoryStreakList()
|
override fun buildStreakList() = MemoryStreakList()
|
||||||
override fun buildHabitListRepository() = throw NotImplementedError()
|
override fun buildHabitListRepository() = throw NotImplementedError()
|
||||||
override fun buildRepetitionListRepository() = throw NotImplementedError()
|
override fun buildRepetitionListRepository() = throw NotImplementedError()
|
||||||
|
|||||||
@@ -1,98 +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.memory;
|
|
||||||
|
|
||||||
import androidx.annotation.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.models.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MemoryScoreList extends ScoreList
|
|
||||||
{
|
|
||||||
ArrayList<Score> list = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(List<Score> scores)
|
|
||||||
{
|
|
||||||
list.addAll(scores);
|
|
||||||
Collections.sort(list,
|
|
||||||
(s1, s2) -> s2.getTimestamp().compareTo(s1.getTimestamp()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public List<Score> getByInterval(@NonNull Timestamp fromTimestamp,
|
|
||||||
@NonNull Timestamp toTimestamp)
|
|
||||||
{
|
|
||||||
compute(fromTimestamp, toTimestamp);
|
|
||||||
|
|
||||||
List<Score> filtered = new LinkedList<>();
|
|
||||||
|
|
||||||
for (Score s : list)
|
|
||||||
{
|
|
||||||
if (s.getTimestamp().isNewerThan(toTimestamp) ||
|
|
||||||
s.getTimestamp().isOlderThan(fromTimestamp)) continue;
|
|
||||||
filtered.add(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filtered;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Score getComputedByTimestamp(Timestamp timestamp)
|
|
||||||
{
|
|
||||||
for (Score s : list)
|
|
||||||
if (s.getTimestamp().equals(timestamp)) return s;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recompute()
|
|
||||||
{
|
|
||||||
list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public List<Score> toList()
|
|
||||||
{
|
|
||||||
computeAll();
|
|
||||||
return new LinkedList<>(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
protected Score getNewestComputed()
|
|
||||||
{
|
|
||||||
if (list.isEmpty()) return null;
|
|
||||||
return list.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
protected Score getOldestComputed()
|
|
||||||
{
|
|
||||||
if (list.isEmpty()) return null;
|
|
||||||
return list.get(list.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,7 +36,7 @@ class SQLModelFactory
|
|||||||
override fun buildOriginalEntries() = SQLiteEntryList(database)
|
override fun buildOriginalEntries() = SQLiteEntryList(database)
|
||||||
override fun buildComputedEntries() = EntryList()
|
override fun buildComputedEntries() = EntryList()
|
||||||
override fun buildHabitList() = SQLiteHabitList(this)
|
override fun buildHabitList() = SQLiteHabitList(this)
|
||||||
override fun buildScoreList() = MemoryScoreList()
|
override fun buildScoreList() = ScoreList()
|
||||||
override fun buildStreakList() = MemoryStreakList()
|
override fun buildStreakList() = MemoryStreakList()
|
||||||
|
|
||||||
override fun buildHabitListRepository() =
|
override fun buildHabitListRepository() =
|
||||||
|
|||||||
Reference in New Issue
Block a user