Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/edu/luc/cs/consoleapp/MainLeaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static void main(final String[] args) {
}

final var input = new Scanner(System.in).useDelimiter("(?U)[^\\p{Alpha}0-9']+");
final var result = new LeakyQueue(lastNWords, input).process();
final var coreLogic = new LeakyQueue(lastNWords, input);
final var result = coreLogic.process();

result.forEach(
value -> {
Expand All @@ -55,6 +56,8 @@ public static void main(final String[] args) {
* A sliding window queue that retains the last N elements.
* This component is independent of the user interface and can be tested independently.
* Nevertheless, it violates an important nonfunctional requirement: it leaks memory.
* In addition, it violates the functional requirement of
* interactively responding to each input.
*/
static class LeakyQueue {

Expand Down
17 changes: 17 additions & 0 deletions src/test/java/edu/luc/cs/consoleapp/OutputToList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package edu.luc.cs.consoleapp;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

class OutputToList implements OutputHandler {

final List<Queue<String>> result = new ArrayList<>();

@Override
public void accept(final Queue<String> value) {
final var snapshot = new LinkedList<>(value);
result.add(snapshot);
}
}