Record Class ParserContext
java.lang.Object
java.lang.Record
io.github.toberocat.guiengine.utils.ParserContext
public record ParserContext(@NotNull com.fasterxml.jackson.databind.JsonNode node, @NotNull GuiContext context, @NotNull GuiEngineApi api)
extends Record
A helper class representing a context for parsing JSON data.
This class provides utility methods to extract values from a JSON node
and convert them to their corresponding data types.
-
Constructor Summary
ConstructorsConstructorDescriptionParserContext
(@NotNull com.fasterxml.jackson.databind.JsonNode node, @NotNull GuiContext context, @NotNull GuiEngineApi api) Creates an instance of aParserContext
record class. -
Method Summary
Modifier and TypeMethodDescription@NotNull GuiEngineApi
api()
Returns the value of theapi
record component.@NotNull GuiContext
context()
Returns the value of thecontext
record component.final boolean
Indicates whether some other object is "equal to" this one.@Nullable ParserContext
Get a child node of the current node based on the specified field name.@NotNull List<ParserContext>
Read a node's children as a list of ParserContext objects.@NotNull Optional<List<GuiFunction>>
getFunctions
(@NotNull String field) Get an optional list of GuiFunction objects from the child node of the current node based on the specified field name.getOptionalBoolean
(@NotNull String field) Get an optional Boolean value from the child node of the current node based on the specified field name.@NotNull Optional<List<ParserContext>>
getOptionalFieldList
(@NotNull String field) Get an optional list of ParserContext objects from the child node of the current node based on the specified field name.getOptionalInt
(@NotNull String field) Get an optional Integer value from the child node of the current node based on the specified field name.@NotNull Optional<org.bukkit.Material>
getOptionalMaterial
(@NotNull String field) Get an optional Material enum value from the child node of the current node based on the specified field name.@NotNull Optional<ParserContext>
getOptionalNode
(@NotNull String field) Get an optional child node of the current node based on the specified field name.@NotNull Optional<Map<String,
ParserContext>> getOptionalNodeMap
(@NotNull String field) Get an optional map of String keys and ParserContext values from the child node of the current node based on the specified field name.@NotNull Optional<RenderPriority>
getOptionalRenderPriority
(@NotNull String field) Get an optional RenderPriority enum value from the child node of the current node based on the specified field name.getOptionalString
(@NotNull String field) Get an optional String value from the child node of the current node based on the specified field name.getOptionalStringArray
(@NotNull String field) Get an optional array of Strings from the child node of the current node based on the specified field name.getOptionalUUID
(@NotNull String field) Get an optional UUID value from the child node of the current node based on the specified field name.final int
hashCode()
Returns a hash code value for this object.@NotNull com.fasterxml.jackson.databind.JsonNode
node()
Returns the value of thenode
record component.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
ParserContext
public ParserContext(@NotNull @NotNull com.fasterxml.jackson.databind.JsonNode node, @NotNull @NotNull GuiContext context, @NotNull @NotNull GuiEngineApi api) Creates an instance of aParserContext
record class.- Parameters:
node
- the value for thenode
record componentcontext
- the value for thecontext
record componentapi
- the value for theapi
record component
-
-
Method Details
-
get
Get a child node of the current node based on the specified field name.- Parameters:
field
- The field name of the child node to retrieve.- Returns:
- A ParserContext representing the child node if found, or null if not present.
-
getOptionalNode
Get an optional child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional child node to retrieve.- Returns:
- An Optional containing the child node if found, or an empty Optional if not present.
-
getFieldList
Read a node's children as a list of ParserContext objects. If the current node is an array, each element will be represented as a separate ParserContext object. If the current node is not an array, the current node itself will be the only element in the list.- Returns:
- A list of ParserContext objects representing the node's children.
-
getOptionalFieldList
@NotNull public @NotNull Optional<List<ParserContext>> getOptionalFieldList(@NotNull @NotNull String field) Get an optional list of ParserContext objects from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional list.- Returns:
- An Optional containing the list of ParserContext objects if found, or an empty Optional if not present.
-
getOptionalMaterial
@NotNull public @NotNull Optional<org.bukkit.Material> getOptionalMaterial(@NotNull @NotNull String field) Get an optional Material enum value from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional Material.- Returns:
- An Optional containing the Material enum value if found, or an empty Optional if not present.
- Throws:
InvalidGuiComponentException
- If the provided material doesn't match any known materials.
-
getOptionalRenderPriority
@NotNull public @NotNull Optional<RenderPriority> getOptionalRenderPriority(@NotNull @NotNull String field) Get an optional RenderPriority enum value from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional RenderPriority.- Returns:
- An Optional containing the RenderPriority enum value if found, or an empty Optional if not present.
-
getOptionalString
Get an optional String value from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional String.- Returns:
- An Optional containing the String value if found, or an empty Optional if not present.
-
getOptionalUUID
Get an optional UUID value from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional UUID.- Returns:
- An Optional containing the UUID value if found, or an empty Optional if not present.
-
getOptionalBoolean
Get an optional Boolean value from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional Boolean.- Returns:
- An Optional containing the Boolean value if found, or an empty Optional if not present.
-
getOptionalInt
Get an optional Integer value from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional Integer.- Returns:
- An Optional containing the Integer value if found, or an empty Optional if not present.
-
getOptionalStringArray
Get an optional array of Strings from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional String array.- Returns:
- An Optional containing the array of Strings if found, or an empty Optional if not present.
-
getOptionalNodeMap
@NotNull public @NotNull Optional<Map<String,ParserContext>> getOptionalNodeMap(@NotNull @NotNull String field) Get an optional map of String keys and ParserContext values from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional node map.- Returns:
- An Optional containing the map of String keys and ParserContext values if found, or an empty Optional if not present.
-
getFunctions
Get an optional list of GuiFunction objects from the child node of the current node based on the specified field name.- Parameters:
field
- The field name of the optional functions.- Returns:
- An Optional containing the list of GuiFunction objects if found, or an empty Optional if not present.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
node
@NotNull public @NotNull com.fasterxml.jackson.databind.JsonNode node()Returns the value of thenode
record component.- Returns:
- the value of the
node
record component
-
context
Returns the value of thecontext
record component.- Returns:
- the value of the
context
record component
-
api
Returns the value of theapi
record component.- Returns:
- the value of the
api
record component
-