Last active
August 29, 2015 14:03
-
-
Save gusennan/e10277c6ae077b03d5f1 to your computer and use it in GitHub Desktop.
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
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