Skip to content

Commit

Permalink
Remove MemoryStreakList.java
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Dec 29, 2020
1 parent c023711 commit 54fe849
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@
* <p>
* This list is populated automatically from the list of repetitions.
*/
public abstract class StreakList
public class StreakList
{
protected Habit habit;

protected ModelObservable observable = new ModelObservable();

ArrayList<Streak> list = new ArrayList<>();

public void setHabit(Habit habit)
{
this.habit = habit;
}

public abstract List<Streak> getAll();
public List<Streak> getAll()
{
rebuild();
return new LinkedList<>(list);
}

@NonNull
public List<Streak> getBest(int limit)
Expand All @@ -54,15 +60,29 @@ public List<Streak> getBest(int limit)
}

@Nullable
public abstract Streak getNewestComputed();
public Streak getNewestComputed()
{
Streak newest = null;

for (Streak s : list)
if (newest == null || s.getEnd().isNewerThan(newest.getEnd()))
newest = s;

return newest;

}

@NonNull
public ModelObservable getObservable()
{
return observable;
}

public abstract void recompute();
public void recompute()
{
list.clear();
observable.notifyListeners();
}

public synchronized void rebuild()
{
Expand Down Expand Up @@ -146,7 +166,18 @@ protected ArrayList<Timestamp> getTransitions(Timestamp beginning, int[] checks)
return list;
}

protected abstract void add(@NonNull List<Streak> streaks);
protected void add(@NonNull List<Streak> streaks)
{
list.addAll(streaks);
Collections.sort(list, (s1, s2) -> s2.compareNewer(s1));
observable.notifyListeners();

}

protected void removeNewestComputed()
{
Streak newest = getNewestComputed();
if (newest != null) list.remove(newest);

protected abstract void removeNewestComputed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MemoryModelFactory : ModelFactory {
override fun buildOriginalEntries() = EntryList()
override fun buildHabitList() = MemoryHabitList()
override fun buildScoreList() = ScoreList()
override fun buildStreakList() = MemoryStreakList()
override fun buildStreakList() = StreakList()
override fun buildHabitListRepository() = throw NotImplementedError()
override fun buildRepetitionListRepository() = throw NotImplementedError()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.isoron.uhabits.core.models.sqlite

import org.isoron.uhabits.core.database.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.models.memory.*
import org.isoron.uhabits.core.models.sqlite.records.*
import javax.inject.*

Expand All @@ -37,7 +36,7 @@ class SQLModelFactory
override fun buildComputedEntries() = EntryList()
override fun buildHabitList() = SQLiteHabitList(this)
override fun buildScoreList() = ScoreList()
override fun buildStreakList() = MemoryStreakList()
override fun buildStreakList() = StreakList()

override fun buildHabitListRepository() =
Repository(HabitRecord::class.java, database)
Expand Down

0 comments on commit 54fe849

Please sign in to comment.