Commit d119ece0 authored by Duilio Protti's avatar Duilio Protti

Routing-related classes moved away from public classes into ToDoRouting inner classes.

Previous public classes contained minimal logic and were not re-used within the app, so it's better to have them as inner classes of ToDoRouting to minimize coupling between different files and also for reducing the number of Java files.
parent 1aa649af
......@@ -163,7 +163,7 @@ public class ToDoPresenter {
private void updateFilteredList() {
filteredTodos.getList().clear();
for (ToDoItem task : todos) {
if (routing.getRoutingFunction().matches(task)) {
if (routing.getMatcher().matches(task)) {
filteredTodos.getList().add(task);
}
}
......
......@@ -2,25 +2,65 @@ package com.todo.client;
public enum ToDoRouting {
/**
* Displays all todo items
* Displays all todo items.
*/
ALL(new ToDoRoutingAll()),
ALL(new MatchAll()),
/**
* Displays active todo items - i.e. those that have not been done
* Displays active todo items - i.e. those that have not been done.
*/
ACTIVE(new ToDoRoutingActive()),
ACTIVE(new MatchActive()),
/**
* Displays completed todo items - i.e. those that have been done
* Displays completed todo items - i.e. those that have been done.
*/
COMPLETED(new ToDoRoutingCompleted());
COMPLETED(new MatchCompleted());
private final ToDoRoutingFunction routingFunction;
/**
* Matcher used to filter todo items, based on some criteria.
*/
public interface Matcher {
/**
* Determines whether the given todo item meets the criteria of this matcher.
*/
boolean matches(ToDoItem item);
}
/**
* A matcher that matches any todo item.
*/
private static class MatchAll implements Matcher {
@Override
public boolean matches(ToDoItem item) {
return true;
}
}
/**
* A matcher that matches only active todo items.
*/
private static class MatchActive implements Matcher {
@Override
public boolean matches(ToDoItem item) {
return !item.isDone();
}
}
/**
* A matcher that matches only completed todo items.
*/
private static class MatchCompleted implements Matcher {
@Override
public boolean matches(ToDoItem item) {
return item.isDone();
}
}
private final Matcher matcher;
private ToDoRouting(ToDoRoutingFunction routingFunction) {
this.routingFunction = routingFunction;
private ToDoRouting(Matcher matcher) {
this.matcher = matcher;
}
public ToDoRoutingFunction getRoutingFunction() {
return routingFunction;
public Matcher getMatcher() {
return matcher;
}
}
package com.todo.client;
/**
* A routing function that matches active todo items.
*/
public class ToDoRoutingActive implements ToDoRoutingFunction {
@Override
public boolean matches(ToDoItem item) {
return !item.isDone();
}
}
package com.todo.client;
/**
* A routing function that matches all todo items.
*/
public class ToDoRoutingAll implements ToDoRoutingFunction {
@Override
public boolean matches(ToDoItem item) {
return true;
}
}
package com.todo.client;
/**
* A routing function that matches completed todo items.
*/
public class ToDoRoutingCompleted implements ToDoRoutingFunction {
@Override
public boolean matches(ToDoItem item) {
return item.isDone();
}
}
package com.todo.client;
/**
* A routing function filters todo items, based on some criteria
*/
public interface ToDoRoutingFunction {
/**
* Determines whether the given todo item matches this routing function.
*/
boolean matches(ToDoItem item);
}
Markdown is supported
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