Record Class GeneratorContext

java.lang.Object
java.lang.Record
io.github.toberocat.guiengine.utils.GeneratorContext

public record GeneratorContext(@NotNull com.fasterxml.jackson.core.JsonGenerator generator) extends Record
GeneratorContext is a utility class that encapsulates a JsonGenerator instance to assist in writing JSON data.

Created: 14.07.2023 Author: Tobias Madlberger (Tobias)

  • Constructor Summary

    Constructors
    Constructor
    Description
    GeneratorContext(@NotNull com.fasterxml.jackson.core.JsonGenerator generator)
    Creates an instance of a GeneratorContext record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    @NotNull com.fasterxml.jackson.core.JsonGenerator
    Retrieves the JsonGenerator associated with this context.
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.
    void
    writeBooleanField(@NotNull String fieldName, boolean value)
    Writes a JSON boolean field with the specified field name and value to the generator.
    void
    writeFunctionField(@NotNull String fieldName, @NotNull List<GuiFunction> functions)
     
    void
    writeNumberField(@NotNull String fieldName, double value)
    Writes a JSON number field with the specified field name and value to the generator.
    void
    writeNumberField(@NotNull String fieldName, float value)
    Writes a JSON number field with the specified field name and value to the generator.
    void
    writeNumberField(@NotNull String fieldName, int value)
    Writes a JSON number field with the specified field name and value to the generator.
    void
    writeNumberField(@NotNull String fieldName, long value)
    Writes a JSON number field with the specified field name and value to the generator.
    void
    writePOJOField(@NotNull String fieldName, Object value)
    Writes a JSON POJO field with the specified field name and value to the generator.
    void
    writeRaw(@NotNull String raw)
    Writes raw JSON data to the generator.
    void
    writeStringField(@NotNull String fieldName, @NotNull String value)
    Writes a JSON string field with the specified field name and value to the generator.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • GeneratorContext

      public GeneratorContext(@NotNull @NotNull com.fasterxml.jackson.core.JsonGenerator generator)
      Creates an instance of a GeneratorContext record class.
      Parameters:
      generator - the value for the generator record component
  • Method Details

    • generator

      @NotNull public @NotNull com.fasterxml.jackson.core.JsonGenerator generator()
      Retrieves the JsonGenerator associated with this context.
      Returns:
      The JsonGenerator instance.
    • writeStringField

      public void writeStringField(@NotNull @NotNull String fieldName, @NotNull @NotNull String value) throws IOException
      Writes a JSON string field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The string value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writeNumberField

      public void writeNumberField(@NotNull @NotNull String fieldName, int value) throws IOException
      Writes a JSON number field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The integer value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writeNumberField

      public void writeNumberField(@NotNull @NotNull String fieldName, long value) throws IOException
      Writes a JSON number field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The integer value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writeNumberField

      public void writeNumberField(@NotNull @NotNull String fieldName, float value) throws IOException
      Writes a JSON number field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The integer value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writeNumberField

      public void writeNumberField(@NotNull @NotNull String fieldName, double value) throws IOException
      Writes a JSON number field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The integer value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writeBooleanField

      public void writeBooleanField(@NotNull @NotNull String fieldName, boolean value) throws IOException
      Writes a JSON boolean field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The boolean value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writePOJOField

      public void writePOJOField(@NotNull @NotNull String fieldName, Object value) throws IOException
      Writes a JSON POJO field with the specified field name and value to the generator.
      Parameters:
      fieldName - The name of the JSON field to write.
      value - The object value to write for the field.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • writeFunctionField

      public void writeFunctionField(@NotNull @NotNull String fieldName, @NotNull @NotNull List<GuiFunction> functions) throws IOException
      Throws:
      IOException
    • writeRaw

      public void writeRaw(@NotNull @NotNull String raw) throws IOException
      Writes raw JSON data to the generator.
      Parameters:
      raw - The raw JSON data to write.
      Throws:
      IOException - If an I/O error occurs while writing to the generator.
    • 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.