T - the type of the values that will be associated with the character keys.public final class Pattern<T> extends Object
| Constructor and Description |
|---|
Pattern(boolean wrapAround,
String... lines)
ctor.
|
Pattern(String... lines)
ctor.
|
| Modifier and Type | Method and Description |
|---|---|
@NotNull Pattern<T> |
attach(char character,
T object)
attaches an object to a character in this pattern instance.
|
@NotNull List<SlotPos> |
findAllKeys(char character)
searches through this patterns lines to find all occurrences of this key.
|
@NotNull Optional<SlotPos> |
findKey(char character)
searches through this patterns lines to find the first top-left occurrence of this key.
|
int |
getColumnCount()
this method counts the amount of rows this pattern has based on the length of the lines.
|
@NotNull Optional<T> |
getDefaultValue()
returns the default value set via
setDefault(Object) |
@NotNull Optional<T> |
getObject(int index)
returns the object from the n-th key in this pattern.
|
@NotNull Optional<T> |
getObject(int row,
int column)
retrieves the object associated with the key found at the row and column in this pattern, if there is no object
attached to that character,
the default object set via
setDefault(Object) is used. |
@NotNull Optional<T> |
getObject(@NotNull SlotPos slot)
this method is simple a shorthand to the method call
getObject(slot.getRow(),
slot.getColumn()),
so all the special cases described in that method will apply to this one. |
int |
getRowCount()
this method counts the amount of rows this pattern has based on the amount of lines provided at creation.
|
boolean |
isWrapAround()
a simple getter for the value provided at the Patterns creation, if this pattern supports wrapAround.
|
@NotNull Pattern<T> |
setDefault(T defaultValue)
sets a new default value, which can be null and will override the previous value if present.
|
public Pattern(@NotNull
String... lines)
lines - the lines describing the pattern.IllegalArgumentException - if the length of lines is zero.IllegalArgumentException - if the length of a line is not equal to the length of the first line.to get the possibility to create a repeating pattern.public Pattern(boolean wrapAround,
@NotNull
String... lines)
wrapAround - whether the pattern should be repeated if the.lines - the lines describing the pattern.IllegalArgumentException - if the length of lines is zeroIllegalArgumentException - if the length of a line is not equal to the length of the first line@NotNull public @NotNull Pattern<T> attach(char character, @NotNull T object)
character - The key character.object - The object to attach to that character.this for a builder-like usage.@NotNull public @NotNull Optional<T> getObject(int index)
true, and the index is equals or greater than
the amount of individual positions in this pattern, it will continue downwards, and not wrap around sideways.
because of this, it could be unclear what this method does and usage is for code clarity discouraged.index - The index in this pattern.For more detailed information.@NotNull public @NotNull Optional<T> getObject(@NotNull @NotNull SlotPos slot)
getObject(slot.getRow(),
slot.getColumn()),
so all the special cases described in that method will apply to this one.slot - The slot position to extract the row and column from.For the more detailed information.@NotNull public @NotNull Optional<T> getObject(int row, int column)
setDefault(Object) is used.
if wrapAround is set to true and the row or column would be too big or small of the pattern, it will
wrap around and continue on from the other side, like it would be endless.
if not, IndexOutOfBoundsException will be thrown.
row - The row of the key.column - The column of the key.IndexOutOfBoundsException - if wrapAround is false and row or column are negative or not less
that the patterns dimensions.@NotNull public @NotNull Optional<SlotPos> findKey(char character)
Optional is empty.character - The character key to look for.@NotNull public @NotNull List<SlotPos> findAllKeys(char character)
if the key isn't contained in this pattern, the returned list will be empty.
character - The character key to look for.@NotNull public @NotNull Pattern<T> setDefault(@NotNull T defaultValue)
defaultValue - The new default value.this for a builder-like usage.@NotNull public @NotNull Optional<T> getDefaultValue()
setDefault(Object)public int getRowCount()
public int getColumnCount()
public boolean isWrapAround()
true if wrapAround is enabled for this instance.Copyright © 2021. All rights reserved.