Record Class CodecContext

java.lang.Object
java.lang.Record
de.Keyle.MyPet.api.gui.CodecContext
Record Components:
menuId - the menu being decoded, used in error messages
rows - the menu's height, for bounds checks
siblingSectionIds - ids of the other sections in the same menu

public record CodecContext(String menuId, int rows, Set<String> siblingSectionIds) extends Record
Information a JsonCodec needs at decode time to validate section data against its surrounding menu (bounds, sibling presence, etc.).
  • Constructor Details

    • CodecContext

      public CodecContext(String menuId, int rows, Set<String> siblingSectionIds)
      Creates an instance of a CodecContext record class.
      Parameters:
      menuId - the value for the menuId record component
      rows - the value for the rows record component
      siblingSectionIds - the value for the siblingSectionIds record component
  • Method Details

    • requireInBounds

      public void requireInBounds(String fieldName, int col, int row)
      Checks that a single slot lies inside the menu.
      Parameters:
      fieldName - name of the JSON field being validated, used in the error message
      col - column, which must be in [0, 9)
      row - row, which must be in [0, rows)
      Throws:
      ValidationException - if the slot falls outside the menu
    • requireRegionInBounds

      public void requireRegionInBounds(String fieldName, int col, int row, int width, int height)
      Checks that a rectangular region fits inside the menu.
      Parameters:
      fieldName - name of the JSON field being validated, used in the error message
      col - left-hand column of the region
      row - top row of the region
      width - region width, which must be positive
      height - region height, which must be positive
      Throws:
      ValidationException - if any part of the region falls outside the menu
    • requireSibling

      public void requireSibling(String fieldName, String siblingId)
      Checks that a section this one refers to actually exists in the same menu.
      Parameters:
      fieldName - name of the JSON field holding the reference
      siblingId - id the field points at
      Throws:
      ValidationException - if no section in this menu has that id
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • rows

      public int rows()
      Returns the value of the rows record component.
      Returns:
      the value of the rows record component
    • siblingSectionIds

      public Set<String> siblingSectionIds()
      Returns the value of the siblingSectionIds record component.
      Returns:
      the value of the siblingSectionIds record component