Commit 2d461142 authored by Pascal Hartig's avatar Pascal Hartig

Merge pull request #876 from dprotti/privateroutingclasses

GWT - routing classes moved from public into ToDoRouting inner classes
parents 537c78a0 d119ece0
......@@ -162,7 +162,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());
private final ToDoRoutingFunction routingFunction;
private ToDoRouting(ToDoRoutingFunction routingFunction) {
this.routingFunction = routingFunction;
COMPLETED(new MatchCompleted());
/**
* 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(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