From cce041877f862842271a7951f4e4457f20574634 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:31:34 +0800 Subject: [PATCH] Cleanup NodeGroup with docs and annotation --- .../core/configuration/node/NodeGroup.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/node/NodeGroup.java b/src/main/java/org/mvplugins/multiverse/core/configuration/node/NodeGroup.java index 82e44363..a95e5789 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/node/NodeGroup.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/node/NodeGroup.java @@ -9,6 +9,7 @@ import java.util.Map; import io.github.townyadvanced.commentedconfiguration.setting.CommentedNode; import io.vavr.control.Option; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * A collection of {@link CommentedNode}s, with mappings to nodes by name. @@ -17,24 +18,32 @@ public class NodeGroup implements Collection { private final Collection nodes; private final Map nodesMap; + /** + * Creates a new empty node group. + */ public NodeGroup() { this.nodes = new ArrayList<>(); this.nodesMap = new HashMap<>(); } - public NodeGroup(Collection nodes) { + /** + * Creates a new node group with the given nodes. + * + * @param nodes The nodes to make up the group. + */ + public NodeGroup(@NotNull Collection nodes) { this.nodes = nodes; this.nodesMap = new HashMap<>(nodes.size()); nodes.forEach(this::addNodeIndex); } - private void addNodeIndex(Node node) { + private void addNodeIndex(@NotNull Node node) { if (node instanceof ValueNode) { ((ValueNode) node).getName().peek(name -> nodesMap.put(name, node)); } } - private void removeNodeIndex(Node node) { + private void removeNodeIndex(@NotNull Node node) { if (node instanceof ValueNode) { ((ValueNode) node).getName().peek(nodesMap::remove); } @@ -45,32 +54,29 @@ public class NodeGroup implements Collection { * * @return The names of all nodes in this group. */ - public Collection getNames() { + public @NotNull Collection getNames() { return nodesMap.keySet(); } - public Map getNodesMap() { - return nodesMap; - } - /** * Gets the node with the given name. * * @param name The name of the node to get. * @return The node with the given name, or {@link Option.None} if no node with the given name exists. */ - public Option findNode(String name) { + public @NotNull Option findNode(@Nullable String name) { return Option.of(nodesMap.get(name)); } /** * Gets the node with the given name. * - * @param name The name of the node to get. - * @param type The type of the node to get. + * @param name The name of node to get. + * @param type The type of node to get. + * @param The type of node. * @return The node with the given name, or {@link Option.None} if no node with the given name exists. */ - public Option findNode(String name, Class type) { + public @NotNull Option findNode(@Nullable String name, @NotNull Class type) { return Option.of(nodesMap.get(name)).map(node -> type.isAssignableFrom(node.getClass()) ? (T) node : null); }