Skip to content

Instantly share code, notes, and snippets.

@gusennan
Last active August 29, 2015 14:03
Show Gist options
  • Save gusennan/e10277c6ae077b03d5f1 to your computer and use it in GitHub Desktop.
Save gusennan/e10277c6ae077b03d5f1 to your computer and use it in GitHub Desktop.
public interface Filter {
public boolean PassesFilter(Leg leg);
public void add(Filter f);
}
public class Filter implements Filter {
private Filter f;
public boolean PassesCriteria(Leg leg) {
// execute
if (f != null) {
return f.PassesCriteria(leg) && myCheck(leg);
} else {
return myCheck(leg);
}
}
private boolean myCheck(Leg leg) {
// Check filter condition here.
}
public void add(Filter f) {
this.filter = f;
}
}
// Client usage
boolean show = new EarliestDepartureFilter().add(
new LatestArrivalFilter().add(
new PriceFilter().add(
new StationsFilter()
)
)
).PassesCriteria(leg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment