Commit e0b12ba2 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Make TodoListItem local and private

parent 8b1edba2
package todolist.core;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
......@@ -26,7 +28,7 @@ public class TodoList extends AbstractTodoList {
@Override
public TodoItem createTodoItem() {
return new TodoListItem(this);
return new TodoListItem();
}
/**
......@@ -44,7 +46,7 @@ public class TodoList extends AbstractTodoList {
if (item instanceof TodoListItem tli) {
todoListItem = tli;
} else {
todoListItem = new TodoListItem(this);
todoListItem = new TodoListItem();
todoListItem.setText(item.getText());
todoListItem.setChecked(item.isChecked());
todoListItem.setDeadline(item.getDeadline());
......@@ -114,4 +116,46 @@ public class TodoList extends AbstractTodoList {
protected void fireTodoListChanged(TodoListListener listener) {
listener.todoListChanged(this);
}
private class TodoListItem extends TodoItem {
TodoList getTodoList() {
return TodoList.this;
}
@Override
public void setText(String text) {
if (! Objects.equals(text, getText())) {
super.setText(text);
fireTodoListChanged(this);
}
}
@Override
public void setChecked(boolean checked) {
if (checked != isChecked()) {
super.setChecked(checked);
fireTodoListChanged(this);
}
}
@Override
public void setDeadline(LocalDateTime deadline) {
if (! Objects.equals(deadline, getDeadline())) {
super.setDeadline(deadline);
fireTodoListChanged(this);
}
}
@Override
public void setAs(TodoItem other) {
boolean equals = isChecked() == other.isChecked()
&& Objects.equals(getText(), other.getText())
&& Objects.equals(getDeadline(), other.getDeadline());
if (! equals) {
super.setAs(other);
fireTodoListChanged(this);
}
}
}
}
package todolist.core;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* TodoItems that belong to a TodoList.
*/
public class TodoListItem extends TodoItem {
private final TodoList todoList;
public TodoListItem(TodoList todoList) {
this.todoList = todoList;
}
public TodoList getTodoList() {
return todoList;
}
@Override
public void setText(String text) {
if (! Objects.equals(text, getText())) {
super.setText(text);
todoList.fireTodoListChanged(this);
}
}
@Override
public void setChecked(boolean checked) {
if (checked != isChecked()) {
super.setChecked(checked);
todoList.fireTodoListChanged(this);
}
}
@Override
public void setDeadline(LocalDateTime deadline) {
if (! Objects.equals(deadline, getDeadline())) {
super.setDeadline(deadline);
todoList.fireTodoListChanged(this);
}
}
@Override
public void setAs(TodoItem other) {
boolean equals = isChecked() == other.isChecked()
&& Objects.equals(getText(), other.getText())
&& Objects.equals(getDeadline(), other.getDeadline());
if (! equals) {
super.setAs(other);
todoList.fireTodoListChanged(this);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment