The idea is to make "optional" parameters or filters really optional and have a 
clean API. That's the reasoning behind refactoring them into an options object. 
With this in mind, the code in your branch looks good, but I'd change the 
signatures to:

```java
@Named("server:list")
@GET
@Path("/server")
@ResponseParser(ParseServers.class)
@Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
PaginatedCollection<Server> listServers(DatacenterIdListFilters 
datacenterIdListFilters);

@Named("server:list")
@GET
@Path("/server")
@Transform(ParseServers.ToPagedIterable.class)
@ResponseParser(ParseServers.class)
@Fallback(Fallbacks.EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Server> listServers();
```

I mean, if the filter is optional, just provide a method with no arguments (no 
filters). If users want to filter they can use the method with the options 
parameter. You can then have the function that advances take into account the 
presence or absence of the filters parameter:

```java
@Override
protected Function<Object, IterableWithMarker<Server>> 
markerToNextForArg0(final Optional<Object> arg0) {
   return new Function<Object, IterableWithMarker<Server>>() {
      @Override
      public IterableWithMarker<Server> apply(Object input) {
         DatacenterIdListFilters filters = arg0.isPresent() ? 
(DatacenterIdListFilters) input : new DatacenterIdListFilters();
         filters.paginationOptions((PaginationFilterOptions) input);
         return api.getServerApi().listServers(filters);
      }
   };
}
```

There is also no need to duplicate the `PaginationOptions` class if it is still 
used in other APIs (making it not extend the base options class was just a 
suggestion to illustrate it is not a need for a "marker" to the next page). 
Let's just remove the new Pagination options class and let the Ddatacenter 
filters builder accept the existing one. You can easily add all the pagination 
query params to the current filter query parameter map and there won't be 
duplicated code.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/433#issuecomment-382283023

Reply via email to