generated from yandex-praktikum/java-kanban
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Выделение интерфейсов TaskManager и HistoryManager, покрытие тестами
- Loading branch information
1 parent
948eeab
commit 06d0867
Showing
11 changed files
with
844 additions
and
244 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package service; | ||
|
||
import model.Task; | ||
|
||
import java.util.List; | ||
|
||
public interface HistoryManager { | ||
void addInHistory(Task task); | ||
List<Task> getHistory(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package service; | ||
|
||
import model.Task; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class InMemoryHistoryManager implements HistoryManager { | ||
private static final int SIZE_HISTORY = 10; | ||
private final List<Task> history = new ArrayList<>(SIZE_HISTORY); | ||
|
||
private void removeHistoryFirst() { | ||
if (!history.isEmpty() && history.size() == SIZE_HISTORY) { | ||
history.removeFirst(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Task> getHistory() { | ||
return history; | ||
} | ||
|
||
@Override | ||
public void addInHistory(Task task) { | ||
if (task != null && SIZE_HISTORY != 0) { | ||
removeHistoryFirst(); | ||
history.add(task); | ||
} | ||
} | ||
} |
Oops, something went wrong.