From 612c1b72e3cdd38aeba52bbc6288cf6b4c0add41 Mon Sep 17 00:00:00 2001 From: Aram Date: Tue, 17 Dec 2024 21:38:25 +0100 Subject: [PATCH] Added Comments --- .../software/bluelib/json/JSONParser.java | 129 +++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/software/bluelib/json/JSONParser.java b/common/src/main/java/software/bluelib/json/JSONParser.java index e91ff9b..554b65f 100644 --- a/common/src/main/java/software/bluelib/json/JSONParser.java +++ b/common/src/main/java/software/bluelib/json/JSONParser.java @@ -1,3 +1,5 @@ +// Copyright (c) BlueLib. Licensed under the MIT License. + package software.bluelib.json; import com.google.gson.JsonObject; @@ -11,12 +13,108 @@ import java.util.HashMap; import java.util.Map; +/** + * An abstract class for parsing JSON data. + *

+ * Purpose: This class provides methods to load and merge JSON data from specified folder paths.
+ * When: The JSON data is loaded and merged when the {@link #loadData(String, MinecraftServer)} method is called.
+ * Where: The JSON data is loaded from the specified folder path and merged into a single {@link JsonObject}.
+ * Additional Info: This class uses {@link JSONLoader} to load JSON data and {@link JSONMerger} to merge JSON objects. + *

+ * Key Methods: + * + * + * @see JSONLoader + * @see JSONMerger + * @see MinecraftServer + * @see JsonObject + * @see ResourceManager + * @see ResourceLocation + * @see Collection + * @since 1.7.0 + * @version 1.7.0 + * @author MeAlam + */ public abstract class JSONParser { + /** + * A map to store JSON data with their corresponding keys. + *

+ * Purpose: This map holds the JSON data loaded from the specified folder path.
+ * When: The map is populated when the {@link #loadData(String, MinecraftServer)} method is called.
+ * Where: The map is used to store JSON data with their corresponding keys.
+ * Additional Info: The keys are the resource locations of the JSON files. + *

+ * + * @since 1.7.0 + */ protected Map dataMap = new HashMap<>(); + + /** + * A static instance of JSONLoader to load JSON data. + *

+ * Purpose: This instance is used to load JSON data from the specified folder path.
+ * When: The instance is used when the {@link #loadData(String, MinecraftServer)} method is called.
+ * Where: The instance is used to load JSON data from the specified folder path.
+ * Additional Info: The JSONLoader class provides methods to load JSON data from resource locations. + *

+ * + * @see JSONLoader + * @since 1.7.0 + */ protected static final JSONLoader jsonLoader = new JSONLoader(); + + /** + * A static instance of JSONMerger to merge JSON objects. + *

+ * Purpose: This instance is used to merge JSON objects loaded from the specified folder path.
+ * When: The instance is used when the {@link #loadData(String, MinecraftServer)} method is called.
+ * Where: The instance is used to merge JSON objects loaded from the specified folder path.
+ * Additional Info: The JSONMerger class provides methods to merge JSON objects. + *

+ * + * @see JSONMerger + * @since 1.7.0 + */ protected static final JSONMerger jsonMerger = new JSONMerger(); + + /** + * A JsonObject to store the merged JSON data. + *

+ * Purpose: This object holds the merged JSON data from the specified folder path.
+ * When: The object is populated when the {@link #loadData(String, MinecraftServer)} method is called.
+ * Where: The object is used to store the merged JSON data.
+ * Additional Info: The merged JSON data is a combination of all JSON files loaded from the specified folder path. + *

+ * + * @since 1.7.0 + */ protected JsonObject mergedJsonObject; + /** + * Loads JSON data from the specified folder path and merges them. + *

+ * Purpose: This method loads JSON data from the specified folder path and merges them into a single {@link JsonObject}.
+ * When: The method is called to load and merge JSON data.
+ * Where: The method is called whenever JSON data needs to be loaded and merged.
+ * Additional Info: The method uses {@link JSONLoader} to load JSON data and {@link JSONMerger} to merge JSON objects. + *

+ * + * @param pFolderPath The folder path to load JSON data from. + * @param pServer The Minecraft server instance. + * @since 1.7.0 + * @author MeAlam + * @see JSONLoader + * @see JSONMerger + * @see MinecraftServer + * @see JsonObject + * @see ResourceManager + * @see ResourceLocation + * @see Collection + */ public void loadData(String pFolderPath, MinecraftServer pServer) { ResourceManager resourceManager = pServer.getResourceManager(); mergedJsonObject = new JsonObject(); @@ -37,11 +135,40 @@ public void loadData(String pFolderPath, MinecraftServer pServer) { } } + /** + * Returns the data map containing JSON data. + *

+ * Purpose: This method returns the data map containing JSON data loaded from the specified folder path.
+ * When: The method is called to retrieve the data map.
+ * Where: The method is called from any class or method.
+ * Additional Info: The data map contains JSON data with their corresponding keys. + *

+ * + * @return The data map. + * @since 1.7.0 + * @author MeAlam + * @see JsonObject + * @see Map + */ public Map getDataMap() { return dataMap; } + /** + * Returns the merged JSON object. + *

+ * Purpose: This method returns the merged JSON object containing data from all JSON files loaded from the specified folder path.
+ * When: The method is called to retrieve the merged JSON object.
+ * Where: The method is called from any class or method.
+ * Additional Info: The merged JSON object is a combination of all JSON files loaded from the specified folder path. + *

+ * + * @return The merged JSON object. + * @since 1.7.0 + * @author MeAlam + * @see JsonObject + */ public JsonObject getMergedJsonObject() { return mergedJsonObject; } -} +} \ No newline at end of file