Package me.hsgamer.hscore.common
Interface StringReplacer
- All Known Implementing Classes:
VariableManager
public interface StringReplacer
A simple interface for String replacement
-
Field Summary
Modifier and TypeFieldDescriptionstatic final StringReplacer
The dummy replacer that does nothing -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull StringReplacer
combine
(@NotNull Collection<? extends StringReplacer> stringReplacers) Combine multiple string replacersstatic @NotNull StringReplacer
combine
(@NotNull StringReplacer... stringReplacers) Combine multiple string replacersstatic @NotNull StringReplacer
of
(@NotNull BiFunction<String, UUID, String> function) static @NotNull StringReplacer
of
(@NotNull UnaryOperator<String> operator) static @NotNull StringReplacer
of
(@NotNull UnaryOperator<String> operator, @NotNull BiFunction<String, UUID, String> function) Create a newStringReplacer
from aUnaryOperator
asreplace(String)
and aBiFunction
asreplace(String, UUID)
@Nullable String
Replace a stringdefault @Nullable String
Replace a string based on the unique iddefault String
replaceOrDefault
(@NotNull String original, @Nullable UUID uuid, @NotNull String def) Replace a string or return the default valuedefault String
replaceOrOriginal
(@NotNull String original, @Nullable UUID uuid) Replace a string or return the original valuedefault @Nullable String
tryReplace
(@NotNull String original, @Nullable UUID uuid) Try to replace a string based on the unique id.
-
Field Details
-
DUMMY
The dummy replacer that does nothing
-
-
Method Details
-
combine
@NotNull static @NotNull StringReplacer combine(@NotNull @NotNull Collection<? extends StringReplacer> stringReplacers) Combine multiple string replacers- Parameters:
stringReplacers
- the string replacers- Returns:
- the combined string replacer
-
combine
@NotNull static @NotNull StringReplacer combine(@NotNull @NotNull StringReplacer... stringReplacers) Combine multiple string replacers- Parameters:
stringReplacers
- the string replacers- Returns:
- the combined string replacer
-
of
@NotNull static @NotNull StringReplacer of(@NotNull @NotNull UnaryOperator<String> operator, @NotNull @NotNull BiFunction<String, UUID, String> function) Create a newStringReplacer
from aUnaryOperator
asreplace(String)
and aBiFunction
asreplace(String, UUID)
- Parameters:
operator
- theUnaryOperator
function
- theBiFunction
- Returns:
- the
StringReplacer
-
of
- Parameters:
operator
- theUnaryOperator
- Returns:
- the
StringReplacer
-
of
@NotNull static @NotNull StringReplacer of(@NotNull @NotNull BiFunction<String, UUID, String> function) - Parameters:
function
- theBiFunction
- Returns:
- the
StringReplacer
-
replace
Replace a string- Parameters:
original
- the original string- Returns:
- the replaced string
-
replace
@Nullable default @Nullable String replace(@NotNull @NotNull String original, @NotNull @NotNull UUID uuid) Replace a string based on the unique id- Parameters:
original
- the original stringuuid
- the unique id- Returns:
- the replaced string
-
tryReplace
@Nullable default @Nullable String tryReplace(@NotNull @NotNull String original, @Nullable @Nullable UUID uuid) Try to replace a string based on the unique id. If the unique id is null, it will usereplace(String)
. Otherwise, it will usereplace(String, UUID)
.- Parameters:
original
- the original stringuuid
- the unique id- Returns:
- the replaced string
-
replaceOrDefault
default String replaceOrDefault(@NotNull @NotNull String original, @Nullable @Nullable UUID uuid, @NotNull @NotNull String def) Replace a string or return the default value- Parameters:
original
- the original stringuuid
- the unique iddef
- the default value- Returns:
- the replaced string or the default value
-
replaceOrOriginal
Replace a string or return the original value- Parameters:
original
- the original string- Returns:
- the replaced string or the original value
-