+ * + * * Depending on the implementation, this list can either be empty or be * populated by some pre-existing habits, for example, from a certain * database. */ - public HabitList() - { - observable = new ModelObservable(); - filter = new HabitMatcherBuilder().setArchivedAllowed(true).build(); + constructor() { + observable = ModelObservable() + filter = HabitMatcherBuilder().setArchivedAllowed(true).build() } - protected HabitList(@NonNull HabitMatcher filter) - { - observable = new ModelObservable(); - this.filter = filter; + protected constructor(filter: HabitMatcher) { + observable = ModelObservable() + this.filter = filter } /** * Inserts a new habit in the list. - *
+ *
+ *
* If the id of the habit is null, the list will assign it a new id, which
* is guaranteed to be unique in the scope of the list. If id is not null,
* the caller should make sure that the list does not already contain
@@ -69,8 +63,8 @@ public abstract class HabitList implements Iterable
+ *
+ *
* If the given habit is not in the list, does nothing.
*
* @param h the habit to be removed.
*/
- public abstract void remove(@NonNull Habit h);
+ abstract fun remove(h: Habit)
/**
* Removes all the habits from the list.
*/
- public void removeAll()
- {
- List
+ *
+ *
* Depending on the implementation, this operation might trigger a write to
* disk, or do nothing at all. To make sure that the habits get persisted,
* this operation must be called.
*
* @param habits the list of habits that have been modified.
*/
- public abstract void update(List
- * See {@link #update(List)} for more details.
+ *
+ *
+ * See [.update] for more details.
*
* @param habit the habit that has been modified.
*/
- public void update(@NonNull Habit habit)
- {
- update(Collections.singletonList(habit));
+ fun update(habit: Habit) {
+ update(listOf(habit))
}
/**
@@ -217,9 +195,9 @@ public abstract class HabitList implements Iterable
+ *
+ *
* Only models should call this method.
*/
- public synchronized void notifyListeners()
- {
- for (Listener l : listeners) l.onModelChange();
+ @Synchronized
+ fun notifyListeners() {
+ for (l in listeners) l.onModelChange()
}
/**
* Removes the given listener.
- *
+ *
+ *
* The listener will no longer be notified when the model changes. If the
* given listener is not subscribed to this observable, does nothing.
*
* @param l the listener to be removed
*/
- public synchronized void removeListener(Listener l)
- {
- listeners.remove(l);
+ @Synchronized
+ fun removeListener(l: Listener) {
+ listeners.remove(l)
}
/**
* Interface implemented by objects that want to be notified when the model
* changes.
*/
- public interface Listener
- {
+ interface Listener {
/**
* Called whenever the model associated to this observable has been
* modified.
*/
- void onModelChange();
+ fun onModelChange()
+ }
+
+ /**
+ * Creates a new ModelObservable with no listeners.
+ */
+ init {
+ listeners = LinkedList()
}
}