java.lang.Object
com.github.stefvanschie.inventoryframework.pane.util.Pattern

public class Pattern extends Object
A mask for PatternPanes that specifies in which positions the items should be placed. Objects of this class are immutable.
Since:
0.9.8
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pattern(@NotNull String @NotNull ... pattern)
    Creates a pattern based on the strings provided.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(int character)
    Gets whether the provided character is present in this pattern.
    boolean
    equals(Object object)
     
    int
    getCharacter(int x, int y)
    Gets the character at the specified position.
    int @NotNull []
    getColumn(int index)
    Gets the column of this pattern at the specified index.
    int
    Gets the height of this pattern
    int
    Gets the length of this pattern
    int @NotNull []
    getRow(int index)
    Gets the row of this mask at the specified index.
    int
     
    static @NotNull Pattern
    load(@NotNull Element element)
    Loads a pattern from an xml element.
    @NotNull Pattern
    setHeight(int height)
    Creates a new pattern with the specified height.
    @NotNull Pattern
    setLength(int length)
    Creates a new pattern with the specified length.
     

    Methods inherited from class java.lang.Object

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

    • Pattern

      public Pattern(@NotNull @NotNull String @NotNull ... pattern)
      Creates a pattern based on the strings provided. Each string is a row for the pattern and each character is a slot of that row. When multiple strings have a different length an IllegalArgumentException will be thrown. Surrogate pairs in strings are treated as a single character and not as two. This means that a string with five surrogate pairs, will count as having five characters, not ten.
      Parameters:
      pattern - a var-arg of strings that represent this pattern
      Throws:
      IllegalArgumentException - when strings have different lengths
      Since:
      0.9.8
  • Method Details

    • setHeight

      @NotNull @Contract(pure=true) public @NotNull Pattern setHeight(int height)
      Creates a new pattern with the specified height. If the new height is smaller than the previous height, the excess values will be truncated. If the new height is longer than the previous height, additional values will be added which are the same as the current bottom row. If the height is the same as the previous pattern, this will simply return a new pattern identical to this one.
      Parameters:
      height - the new height of the pattern
      Returns:
      a new pattern with the specified height
      Since:
      0.9.8
    • setLength

      @NotNull @Contract(pure=true) public @NotNull Pattern setLength(int length)
      Creates a new pattern with the specified length. If the new length is smaller than the previous length, the excess values will be truncated. If the new length is longer than the previous length, additional values will be added which are the same as the rightmost value on a given row. If the length is the same as the previous pattern, this will simply return a new pattern identical to this one.
      Parameters:
      length - the new length of the pattern
      Returns:
      a new pattern with the specified length
      Since:
      0.9.8
    • getColumn

      @Contract(pure=true) public int @NotNull [] getColumn(int index)
      Gets the column of this pattern at the specified index. The values indicate the character of the slots for that slot. The returned array is a copy of the original; modifications to the returned array will not be reflected in the pattern.
      Parameters:
      index - the column index
      Returns:
      the column of this pattern
      Throws:
      IllegalArgumentException - when the index is outside the pattern's range
      Since:
      0.9.8
    • contains

      @Contract(pure=true) public boolean contains(int character)
      Gets whether the provided character is present in this pattern. For checking surrogate pairs, the pair should be combined into one single number.
      Parameters:
      character - the character to look for
      Returns:
      whether the provided character is present
      Since:
      0.9.8
    • getRow

      @Contract(pure=true) public int @NotNull [] getRow(int index)
      Gets the row of this mask at the specified index. The values indicate the character of the slots for that slot. The returned array is a copy of the original; modifications to the returned array will not be reflected in the pattern.
      Parameters:
      index - the row index
      Returns:
      the row of this pattern
      Throws:
      IllegalArgumentException - when the index is outside the pattern's range
      Since:
      0.9.8
    • getCharacter

      @Contract(pure=true) public int getCharacter(int x, int y)
      Gets the character at the specified position. This returns an integer, instead of a character to properly account for characters above the 16-bit range.
      Parameters:
      x - the x position
      y - the y position
      Returns:
      the character at the specified position
      Throws:
      IllegalArgumentException - when the position is out of range
      Since:
      0.9.8
    • getLength

      @Contract(pure=true) public int getLength()
      Gets the length of this pattern
      Returns:
      the length
      Since:
      0.9.8
    • getHeight

      @Contract(pure=true) public int getHeight()
      Gets the height of this pattern
      Returns:
      the height
      Since:
      0.9.8
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • load

      @NotNull @Contract(pure=true) public static @NotNull Pattern load(@NotNull @NotNull Element element)
      Loads a pattern from an xml element.
      Parameters:
      element - the xml element
      Returns:
      the loaded pattern
      Since:
      0.9.8