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.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent builder for manual cell assignment.static enumDefines the primary axis for iteration and rendering logic.static final classFluent builder for mapping characters in a string pattern to objects. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.static <T> StructureArray.Builder<T> Starts a coordinated builder for manual grid assembly.static <T> StructureArray<T> Creates a 3-part column (Top, Middle..., Bottom).static <T> StructureArray<T> Creates a single-column structure.elementAt(int x, int y) Gets the element at a specific 2D coordinate.static <T> StructureArray<T> Creates a structure filled with elements provided by a supplier.static <T> StructureArray<T> Creates a structure filled with a static value.Flips the grid horizontally.Flips the grid vertically.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.intheight()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.int[]iterationOrder(StructureArray.Orientation orientation) Retrieves the sequence of flat indices for a given iteration mode.static <T> StructureArray<T> Creates a structure from an existing flat array.static <T> StructureArray.PatternBuilder<T> patternBuilder(Class<T> type) Starts a pattern-based builder for crafting grids using strings.static <T> StructureArray<T> Creates a solid rectangle.Rotates the structure 90 degrees clockwise.static <T> StructureArray<T> Creates a 3-part row (Left, Middle..., Right).static <T> StructureArray<T> Creates a single-row structure.intsize()static <T> StructureArray<T> Creates a solid square.T[]Returns a copy of the internal flat array.static <T> StructureArray<T> twoColumns(Class<T> type, int height, T left, T right) Creates a structure with two columns.static <T> StructureArray<T> Creates a structure with two rows.intwidth()
-
Method Details
-
ofGrid
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
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
Creates a single-row structure.- Type Parameters:
T- Generic type.- Parameters:
type- The class type.elements- Row elements.- Returns:
- A 1-high StructureArray.
-
columnOf
Creates a single-column structure.- Type Parameters:
T- Generic type.- Parameters:
type- The class type.elements- Column elements.- Returns:
- A 1-wide StructureArray.
-
row
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
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
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
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
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
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
Rotates the structure 90 degrees clockwise.- Returns:
- A new rotated StructureArray.
-
flippedHorizontally
Flips the grid horizontally.- Returns:
- A new mirrored StructureArray.
-
flippedVertically
Flips the grid vertically.- Returns:
- A new mirrored StructureArray.
-
iterationOrder
Retrieves the sequence of flat indices for a given iteration mode.- Parameters:
orientation- The desired orientation.- Returns:
- An array of integer indices.
-
elementAt
Gets the element at a specific 2D coordinate.- Parameters:
x- X coordinate.y- Y coordinate.- Returns:
- The element at (x, y).
-
toFlatArray
-
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
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
Starts a pattern-based builder for crafting grids using strings.- Type Parameters:
T- Type.- Parameters:
type- Class type.- Returns:
- A new PatternBuilder.
-