Skip to content

Instantly share code, notes, and snippets.

@mworzala
Created November 2, 2018 03:50
Show Gist options
  • Save mworzala/2fb0a0a488a038b7cde256516e044401 to your computer and use it in GitHub Desktop.
Save mworzala/2fb0a0a488a038b7cde256516e044401 to your computer and use it in GitHub Desktop.
Node Builder
public class NodeParams {
public NodeParams(CommentedConfigurationNode parent, Object value, String comment, Object... path) {
if (parent.getNode(path).isVirtual())
parent.getNode(path).setValue(value).setComment(comment);
}
public class Builder {
private final CommentedConfigurationNode parent;
private Object[] path;
private Object value;
private Object comment;
public Builder(CommentedConfigurationNode parent) {
this.parent = parent;
}
public Builder setPath(Object... path) {
this.path = path;
return this;
}
public Builder setValue(Object value) {
this.value = value;
return this;
}
public Builder setComment(Object comment) {
this.comment = comment;
return this;
}
public void execute() {
new NodeParams(this.parent, this.value, this.comment.toString(), this.path);
}
}
}
public void addDefault(ccn node) {
new NodeParams.Builder().setPath("path", "to", "node").setValue("some_value").setComment("i am a comment").execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment