Class StructureArray<T>

java.lang.Object
com.github.darksoulq.abyssallib.common.util.StructureArray<T>
Type Parameters:
T - The type of elements contained within the structure.

public final class StructureArray<T> extends Object
A utility class for managing and manipulating 2D structural grids of generic elements.

This class provides extensive factory methods for creating shapes (rectangles, borders, lines) and supports transformations like rotation and flipping. It is primarily used to define the physical layout of items within a GUI.

  • Method Details

    • ofGrid

      public static <T> StructureArray<T> ofGrid(Class<T> type, int width, int height, T[] elements)
      Creates a structure from an existing flat array.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Grid width.
      height - Grid height.
      elements - Flat array (must be width * height in size).
      Returns:
      A new StructureArray.
    • filled

      public static <T> StructureArray<T> filled(Class<T> type, int width, int height, Supplier<T> supplier)
      Creates a structure filled with elements provided by a supplier.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Grid width.
      height - Grid height.
      supplier - A function providing the element for each cell.
      Returns:
      A filled StructureArray.
    • filled

      public static <T> StructureArray<T> filled(Class<T> type, int width, int height, T value)
      Creates a structure filled with a static value.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Grid width.
      height - Grid height.
      value - The object to place in every cell.
      Returns:
      A filled StructureArray.
    • generateGrid

      public static <T> StructureArray<T> generateGrid(Class<T> type, int width, int height, BiFunction<Integer,Integer,T> generator)
      Creates a structure using a generator based on coordinates.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Grid width.
      height - Grid height.
      generator - Function receiving (x, y) and returning an element.
      Returns:
      A generated StructureArray.
    • rowOf

      @SafeVarargs public static <T> StructureArray<T> rowOf(Class<T> type, T... elements)
      Creates a single-row structure.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      elements - Row elements.
      Returns:
      A 1-high StructureArray.
    • columnOf

      @SafeVarargs public static <T> StructureArray<T> columnOf(Class<T> type, T... elements)
      Creates a single-column structure.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      elements - Column elements.
      Returns:
      A 1-wide StructureArray.
    • row

      public static <T> StructureArray<T> row(Class<T> type, int length, T left, T middle, T right)
      Creates a 3-part row (Left, Middle..., Right).
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      length - Row width.
      left - Item at the far left.
      middle - Item(s) in the center.
      right - Item at the far right.
      Returns:
      A row StructureArray.
    • column

      public static <T> StructureArray<T> column(Class<T> type, int height, T top, T middle, T bottom)
      Creates a 3-part column (Top, Middle..., Bottom).
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      height - Column height.
      top - Item at the very top.
      middle - Item(s) in the center.
      bottom - Item at the very bottom.
      Returns:
      A column StructureArray.
    • rectangle

      public static <T> StructureArray<T> rectangle(Class<T> type, int width, int height, T fill)
      Creates a solid rectangle.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Width.
      height - Height.
      fill - The filling element.
      Returns:
      A rectangular StructureArray.
    • square

      public static <T> StructureArray<T> square(Class<T> type, int size, T fill)
      Creates a solid square.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      size - Side length.
      fill - The filling element.
      Returns:
      A square StructureArray.
    • borderedRectangle

      public static <T> StructureArray<T> borderedRectangle(Class<T> type, int width, int height, T topLeft, T topRight, T bottomLeft, T bottomRight, T topEdge, T bottomEdge, T leftEdge, T rightEdge, T center)
      Creates a complex rectangle with unique elements for corners, edges, and the center.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Width.
      height - Height.
      topLeft - Corner element.
      topRight - Corner element.
      bottomLeft - Corner element.
      bottomRight - Corner element.
      topEdge - Edge element.
      bottomEdge - Edge element.
      leftEdge - Edge element.
      rightEdge - Edge element.
      center - The internal filling.
      Returns:
      A bordered StructureArray.
    • hollowRectangle

      public static <T> StructureArray<T> hollowRectangle(Class<T> type, int width, int height, T border, T inside)
      Creates a rectangle where corners and edges use the same element.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Width.
      height - Height.
      border - The border element.
      inside - The internal filling.
      Returns:
      A hollow/bordered StructureArray.
    • twoColumns

      public static <T> StructureArray<T> twoColumns(Class<T> type, int height, T left, T right)
      Creates a structure with two columns.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      height - Height.
      left - Left column value.
      right - Right column value.
      Returns:
      A 2-wide StructureArray.
    • twoRows

      public static <T> StructureArray<T> twoRows(Class<T> type, int width, T top, T bottom)
      Creates a structure with two rows.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - The class type.
      width - Width.
      top - Top row value.
      bottom - Bottom row value.
      Returns:
      A 2-high StructureArray.
    • rotatedClockwise

      public StructureArray<T> rotatedClockwise()
      Rotates the structure 90 degrees clockwise.
      Returns:
      A new rotated StructureArray.
    • flippedHorizontally

      public StructureArray<T> flippedHorizontally()
      Flips the grid horizontally.
      Returns:
      A new mirrored StructureArray.
    • flippedVertically

      public StructureArray<T> flippedVertically()
      Flips the grid vertically.
      Returns:
      A new mirrored StructureArray.
    • iterationOrder

      public int[] iterationOrder(StructureArray.Orientation orientation)
      Retrieves the sequence of flat indices for a given iteration mode.
      Parameters:
      orientation - The desired orientation.
      Returns:
      An array of integer indices.
    • elementAt

      public T elementAt(int x, int y)
      Gets the element at a specific 2D coordinate.
      Parameters:
      x - X coordinate.
      y - Y coordinate.
      Returns:
      The element at (x, y).
    • toFlatArray

      public T[] toFlatArray()
      Returns a copy of the internal flat array.
      Returns:
      T[] array.
    • width

      public int width()
      Returns:
      Total horizontal cells.
    • height

      public int height()
      Returns:
      Total vertical cells.
    • size

      public int size()
      Returns:
      Total number of cells.
    • builder

      public static <T> StructureArray.Builder<T> builder(Class<T> type, int width, int height)
      Starts a coordinated builder for manual grid assembly.
      Type Parameters:
      T - Type.
      Parameters:
      type - Class type.
      width - Width.
      height - Height.
      Returns:
      A new Builder.
    • patternBuilder

      public static <T> StructureArray.PatternBuilder<T> patternBuilder(Class<T> type)
      Starts a pattern-based builder for crafting grids using strings.
      Type Parameters:
      T - Type.
      Parameters:
      type - Class type.
      Returns:
      A new PatternBuilder.