It sets the modifier of the internal class inside builders as protected. As this way, if a class extends from it, it has access to its values.
Apart of this, dashboard.Panel is transformed into a generic class to be able to be able to use the methods from the extended class at any order. There are some examples to see this change better:
If we don't make panel generic:
public class Builder implements cog.Builder<Panel> {
protected final Panel internal;
public Builder() {
this.internal = new Panel();
}
public Builder title(String title) {
this.internal.title = title;
return this;
}
...
}
public class MyBuilder extends Builder {
public MyBuilder() {
super();
}
public MyBuilder myFunction(Integer b) {
this.internal.aInteger = b;
return this;
}
...
}
With this example:
It works: Panel panel = new MyClass.MyBuilder().myFunction(b).title("a").build();
It doesn't work: Panel panel = new MyClass.MyBuilder().title("a").myFunction(b).build();
When it calls to title, it returns a Builder and the builder doesn't has access to MyBuilder functions.
So, transforming dashboard.Panel into generic one:
public class Builder<T extends Builder<T>> implements cog.Builder<Panel> {
...
public T title(String title) {
this.panel.title = title;
return (T) this;
}
}
public class MyBuilder extends Builder<MyBuilder> {
// Same as before
}
With this, title method returns the builder of the (T) class, that in that case is MyBuilder, so you can access to the methods in any order.
Closes: https://github.com/grafana/cog/issues/559
It sets the modifier of the internal class inside builders as protected. As this way, if a class extends from it, it has access to its values.
Apart of this,
dashboard.Panel
is transformed into a generic class to be able to be able to use the methods from the extended class at any order. There are some examples to see this change better:If we don't make panel generic:
With this example:
Panel panel = new MyClass.MyBuilder().myFunction(b).title("a").build();
Panel panel = new MyClass.MyBuilder().title("a").myFunction(b).build();
When it calls to
title
, it returns aBuilder
and the builder doesn't has access toMyBuilder
functions.So, transforming dashboard.Panel into generic one:
With this,
title
method returns the builder of the(T)
class, that in that case isMyBuilder
, so you can access to the methods in any order.