> +      return filter(concat(transform(ImmutableSet.<String> 
> builder().addAll(projects).add("").build(),
> +              allTemplatesForProject())), isReady());
> +   }
> +
> +   protected Function<String, Set<? extends Template>> 
> allTemplatesForProject() {
> +      return new Function<String, Set<? extends Template>>() {
> +
> +         @Override
> +         public Set<? extends Template> apply(String from) {
> +            if (from != "")
> +               return 
> client.getTemplateApi().listTemplates(ListTemplatesOptions.Builder.projectId(from));
> +            else
> +               return client.getTemplateApi().listTemplates();
> +         }
> +
> +      };

Functional, I know, but could an evil imperative style be clearer and shorter 
here?
```
TemplateApi templateApi = client.getTemplateApi();
ImmutableSet.Builder<? extends Template> templates = ImmutableSet.builder();
// add non-project templates
templates.addAll(templateApi.listTemplates());
for (Project project : projectSupplier.get().values()) {
  
templates.addAll(templateApi.listTemplates(ListTemplatesOptions.Builder.projectId(project.getId()));
}
return filter(templates.build(), isReady());
```
And the use of the empty string as a "magic value" to force the non-project 
values to be added seems a bit hacky? If anything, add them to the template 
iterable explicitly before filtering?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/215/files#r7915845

Reply via email to