Currently, when creating a new PipeConfig we use a constructor and specify a rootUrl:
URL rootUrl = new URL("http://todo-aerogear.rhcloud.com/todo-server");
Pipeline pipeline = new Pipeline(rootUrl);
PipeConfig config = new PipeConfig(rootUrl, Project.class);
Pipe<Project> projects = pipeline.pipe(Project.class, config);
We are specifying rootUrl twice which feels weird, as Pipeline is supposed to be a factory object. That information should be on PipeConfig.
One way would be like this:
URL rootUrl = new URL("http://todo-aerogear.rhcloud.com/todo-server");
Pipeline pipeline = new Pipeline();
PipeConfig config = new PipeConfig(rootUrl, Project.class);
Pipe<Project> projects = pipeline.pipe(Project.class, config);
But now, because of type safetype, we are passing in Project.class and PipeConfig together. How about we make PipeConfig a generic type? And add a new field. PipeConfig.java:
public class PipeConfig<T> {
//old fields
private final Class<T> entityClass;
public PipeConfig(URL baseURL, Class<T> klass) {
this.baseURL = baseURL;
this.name = klass.getSimpleName().toLowerCase();
this.endpoint = name;
this.type = PipeTypes.REST;
this.entityClass = klass;
}
Now creating a Pipe looks like:
URL rootUrl = new URL("http://todo-aerogear.rhcloud.com/todo-server");
Pipeline pipeline = new Pipeline();
PipeConfig<Project> config = new PipeConfig<Project>(rootUrl, Project.class);
Pipe<Project> projects = pipeline.pipe(config);
That's nicer.
And we can also have, as a convenience method:
URL rootUrl = new URL("http://todo-aerogear.rhcloud.com/todo-server");
Pipeline pipeline = new Pipeline();
Pipe<Project> projects = pipeline.pipe(rootUrl, Project.class);
WDYT?