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 Details

    • ParserContext

      public ParserContext(@NotNull @NotNull com.fasterxml.jackson.databind.JsonNode node, @NotNull @NotNull GuiContext context, @NotNull @NotNull GuiEngineApi api)
      Creates an instance of a ParserContext record class.
      Parameters:
      node - the value for the node record component
      context - the value for the context record component
      api - the value for the api record component
  • Method Details

    • get

      @Nullable public @Nullable ParserContext get(String field)
      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

      @NotNull public @NotNull Optional<ParserContext> getOptionalNode(@NotNull @NotNull String field)
      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

      @NotNull public @NotNull List<ParserContext> 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

      @NotNull public @NotNull Optional<String> getOptionalString(@NotNull @NotNull String field)
      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

      @NotNull public @NotNull Optional<UUID> getOptionalUUID(@NotNull @NotNull String field)
      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

      @NotNull public @NotNull Optional<Boolean> getOptionalBoolean(@NotNull @NotNull String field)
      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

      @NotNull public @NotNull Optional<Integer> getOptionalInt(@NotNull @NotNull String field)
      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

      @NotNull public @NotNull Optional<String[]> getOptionalStringArray(@NotNull @NotNull String field)
      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

      @NotNull public @NotNull Optional<List<GuiFunction>> getFunctions(@NotNull @NotNull String field)
      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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • node

      @NotNull public @NotNull com.fasterxml.jackson.databind.JsonNode node()
      Returns the value of the node record component.
      Returns:
      the value of the node record component
    • context

      @NotNull public @NotNull GuiContext context()
      Returns the value of the context record component.
      Returns:
      the value of the context record component
    • api

      @NotNull public @NotNull GuiEngineApi api()
      Returns the value of the api record component.
      Returns:
      the value of the api record component