Skip to content

Instantly share code, notes, and snippets.

@andytill
Created September 4, 2012 11:46
Show Gist options
  • Save andytill/3620522 to your computer and use it in GitHub Desktop.
Save andytill/3620522 to your computer and use it in GitHub Desktop.
import java.util.List;
public class ControllerLookup {
private final List<IdentifiableController> identifiables;
public ControllerLookup(List<IdentifiableController> identifiables) {
this.identifiables = identifiables;
}
@SuppressWarnings("unchecked")
public <T> T lookup(String id) {
for (IdentifiableController controller : identifiables) {
if(controller.getId().equals(id)) {
return (T) controller;
}
}
throw new IllegalArgumentException("Could not find a controller with the ID '" + id + "'");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment