Created
November 2, 2018 03:50
-
-
Save mworzala/2fb0a0a488a038b7cde256516e044401 to your computer and use it in GitHub Desktop.
Node Builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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