mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-29 05:55:48 +01:00
docs: Add more docstrings to methods implemented
This commit is contained in:
parent
ba2be24362
commit
274a7ed82b
@ -11,7 +11,13 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public class MVCommentedNode implements CommentedNode {
|
public class MVCommentedNode implements CommentedNode {
|
||||||
|
|
||||||
public static <T> Builder<Builder> builder(String path) {
|
/**
|
||||||
|
* Creates a new builder for a {@link MVCommentedNode}.
|
||||||
|
*
|
||||||
|
* @param path The path of the node.
|
||||||
|
* @return The new builder.
|
||||||
|
*/
|
||||||
|
public static Builder<Builder> builder(String path) {
|
||||||
return new Builder<>(path);
|
return new Builder<>(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,15 +45,31 @@ public class MVCommentedNode implements CommentedNode {
|
|||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for {@link MVCommentedNode}.
|
||||||
|
*
|
||||||
|
* @param <B> The type of the builder.
|
||||||
|
*/
|
||||||
public static class Builder<B extends Builder> {
|
public static class Builder<B extends Builder> {
|
||||||
protected final String path;
|
protected final String path;
|
||||||
protected final List<String> comments;
|
protected final List<String> comments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new builder for a {@link MVCommentedNode}.
|
||||||
|
*
|
||||||
|
* @param path The path of the node.
|
||||||
|
*/
|
||||||
protected Builder(String path) {
|
protected Builder(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.comments = new ArrayList<>();
|
this.comments = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a comment line to the node.
|
||||||
|
*
|
||||||
|
* @param comment The comment to add.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
public B comment(@NotNull String comment) {
|
public B comment(@NotNull String comment) {
|
||||||
if (!comment.isEmpty() && !comment.trim().startsWith("#")) {
|
if (!comment.isEmpty() && !comment.trim().startsWith("#")) {
|
||||||
// Automatically add a comment prefix if the comment doesn't start with one.
|
// Automatically add a comment prefix if the comment doesn't start with one.
|
||||||
@ -57,6 +79,11 @@ public class MVCommentedNode implements CommentedNode {
|
|||||||
return (B) this;
|
return (B) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the node.
|
||||||
|
*
|
||||||
|
* @return The built node.
|
||||||
|
*/
|
||||||
public MVCommentedNode build() {
|
public MVCommentedNode build() {
|
||||||
return new MVCommentedNode(path, comments.toArray(new String[0]));
|
return new MVCommentedNode(path, comments.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,14 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public class MVValueNode<T> extends MVCommentedNode implements NamedValueNode<T> {
|
public class MVValueNode<T> extends MVCommentedNode implements NamedValueNode<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new builder for a {@link MVValueNode}.
|
||||||
|
*
|
||||||
|
* @param path The path of the node.
|
||||||
|
* @param type The type of the value.
|
||||||
|
* @return The new builder.
|
||||||
|
* @param <T> The type of the value.
|
||||||
|
*/
|
||||||
public static <T> Builder<T, ? extends Builder> builder(String path, Class<T> type) {
|
public static <T> Builder<T, ? extends Builder> builder(String path, Class<T> type) {
|
||||||
return new Builder<>(path, type);
|
return new Builder<>(path, type);
|
||||||
}
|
}
|
||||||
@ -50,28 +58,55 @@ public class MVValueNode<T> extends MVCommentedNode implements NamedValueNode<T>
|
|||||||
return Optional.ofNullable(name);
|
return Optional.ofNullable(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for {@link MVValueNode}.
|
||||||
|
*
|
||||||
|
* @param <T> The type of the value.
|
||||||
|
* @param <B> The type of the builder.
|
||||||
|
*/
|
||||||
public static class Builder<T, B extends Builder<T, B>> extends MVCommentedNode.Builder<B> {
|
public static class Builder<T, B extends Builder<T, B>> extends MVCommentedNode.Builder<B> {
|
||||||
|
|
||||||
protected final Class<T> type;
|
protected final Class<T> type;
|
||||||
protected T defaultValue;
|
protected T defaultValue;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public Builder(@NotNull String path, @NotNull Class<T> type) {
|
/**
|
||||||
|
* Creates a new builder.
|
||||||
|
*
|
||||||
|
* @param path The path of the node.
|
||||||
|
* @param type The type of the value.
|
||||||
|
*/
|
||||||
|
protected Builder(@NotNull String path, @NotNull Class<T> type) {
|
||||||
super(path);
|
super(path);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = path;
|
this.name = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default value for this node.
|
||||||
|
*
|
||||||
|
* @param defaultValue The default value.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
public B defaultValue(@NotNull T defaultValue) {
|
public B defaultValue(@NotNull T defaultValue) {
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
return (B) this;
|
return (B) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of this node. Used for identifying the node from user input.
|
||||||
|
*
|
||||||
|
* @param name The name of this node.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
public B name(@Nullable String name) {
|
public B name(@Nullable String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return (B) this;
|
return (B) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MVValueNode<T> build() {
|
public MVValueNode<T> build() {
|
||||||
return new MVValueNode<>(path, comments.toArray(new String[0]), type, defaultValue, name);
|
return new MVValueNode<>(path, comments.toArray(new String[0]), type, defaultValue, name);
|
||||||
|
@ -3,8 +3,12 @@ package com.onarandombox.MultiverseCore.utils.settings.node;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import io.github.townyadvanced.commentedconfiguration.setting.TypedValueNode;
|
import io.github.townyadvanced.commentedconfiguration.setting.TypedValueNode;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link TypedValueNode} that has a name.
|
||||||
|
*
|
||||||
|
* @param <T> The type of the node's value.
|
||||||
|
*/
|
||||||
public interface NamedValueNode<T> extends TypedValueNode<T> {
|
public interface NamedValueNode<T> extends TypedValueNode<T> {
|
||||||
/**
|
/**
|
||||||
* Gets the name of this node. Used for identifying the node from user input.
|
* Gets the name of this node. Used for identifying the node from user input.
|
||||||
|
Loading…
Reference in New Issue
Block a user