Interface CharacterManager
A CharacterManager allows you to register custom characters with specific widths,
retrieve character information, remove characters, and align strings based on character widths.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharacterInfoThe default character information used when no specific info is found. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCharacter(char c, int length) Registers a custom character with its associated visual length.default voidaddCharacter(String string, int length) Registers a custom character from a string with its associated visual length.Aligns a string based on a specified limit using character information.default StringAligns a string based on a default width limit.getInfo(char c) Retrieves theCharacterInfofor the given character.default CharacterInfoRetrieves theCharacterInfofor the first character of the provided string.voidremoveCharacters(Character... chars) Removes the specified characters from the manager.default voidremoveCharacters(String... strings) Removes characters specified by strings from the manager.static @Nullable CharactertoCharacter(String string) Converts a string into aCharacterif it contains exactly one character.
-
Field Details
-
DEFAULT_INFO
The default character information used when no specific info is found. Defaults to the character 'a' with a base length of 5.
-
-
Method Details
-
getInfo
Retrieves theCharacterInfofor the given character.- Parameters:
c- the character for which to retrieve information- Returns:
- the
CharacterInfocorresponding to the character
-
getInfo
Retrieves theCharacterInfofor the first character of the provided string.If the input string is null, empty, or contains more than one character, the default character information is returned.
- Parameters:
string- the string representing the character (should be of length 1)- Returns:
- the
CharacterInfofor the character, orDEFAULT_INFOif invalid
-
addCharacter
void addCharacter(char c, int length) Registers a custom character with its associated visual length.This allows the
CharacterManagerto handle custom formatting based on character widths.- Parameters:
c- the character to addlength- the visual length (width) of the character
-
addCharacter
Registers a custom character from a string with its associated visual length.The string should contain exactly one character; otherwise, the operation is ignored.
- Parameters:
string- the string representing the character to addlength- the visual length (width) of the character
-
removeCharacters
Removes the specified characters from the manager.- Parameters:
chars- the characters to remove
-
removeCharacters
Removes characters specified by strings from the manager.Each string should contain exactly one character; if not, it is ignored.
- Parameters:
strings- an array of strings representing the characters to remove
-
align
Aligns a string based on a specified limit using character information.This method adjusts the string's layout so that it fits within a given visual width (limit), using the character lengths defined in the manager.
- Parameters:
limit- the maximum allowed width for the stringstring- the string to be aligned- Returns:
- the aligned string
-
align
Aligns a string based on a default width limit.The default limit is set to 154. This method provides a convenient overload if no custom limit is required.
- Parameters:
string- the string to be aligned- Returns:
- the aligned string using the default width limit
-
toCharacter
Converts a string into aCharacterif it contains exactly one character.If the input string is blank or contains more than one character,
nullis returned.- Parameters:
string- the string to convert- Returns:
- the
Characterif the string is valid; otherwise,null
-