Package me.croabeast.common.util
Class ReplaceUtils
java.lang.Object
me.croabeast.common.util.ReplaceUtils
A utility class that provides methods for replacing placeholders in strings
with corresponding values.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<A,B> boolean isApplicable(A[] as, B[] bs) Checks if an array of keys is applicable for replacement with an array of values.Replaces occurrences of a key in a string with a specified value.Replaces occurrences of a key in a string with a specified value.replaceEach(String[] keys, Object[] values, String string) Replaces each occurrence of a set of keys in a string with their corresponding values.replaceEach(String[] keys, Object[] values, String string, boolean sensitive) Replaces each occurrence of a set of keys in a string with their corresponding values.replaceEach(Collection<String> keys, Collection<Object> values, String string) Replaces each occurrence of a set of keys in a string with their corresponding values.replaceEach(Collection<String> keys, Collection<Object> values, String string, boolean sensitive) Replaces each occurrence of a set of keys in a string with their corresponding values.<T> StringreplaceEach(Map<String, ? extends T> map, String string) Replaces each occurrence of a set of keys in a string with their corresponding values.<T> StringreplaceEach(Map<String, ? extends T> map, String string, boolean sensitive) Replaces each occurrence of a set of keys in a string with their corresponding values.<T,R> String replaceEach(Map<String, T> map, Function<T, R> function, String string) Replaces each occurrence of a set of keys in a string with their corresponding values.<T,R> String replaceEach(Map<String, T> map, Function<T, R> function, String string, boolean sensitive) Replaces each occurrence of a set of keys in a string with their corresponding values.
-
Constructor Details
-
ReplaceUtils
public ReplaceUtils()
-
-
Method Details
-
replace
Replaces occurrences of a key in a string with a specified value.- Parameters:
key- The key string to be replacedvalue- The value to replace the key withstring- The input stringsensitive- A boolean flag indicating whether the replacement should be case-sensitive- Returns:
- The modified string after replacement
-
replace
Replaces occurrences of a key in a string with a specified value. The replacement is case-insensitive.- Parameters:
key- The key string to be replacedvalue- The value to replace the key withstring- The input string- Returns:
- The modified string after replacement
-
isApplicable
public <A,B> boolean isApplicable(A[] as, B[] bs) Checks if an array of keys is applicable for replacement with an array of values.- Type Parameters:
A- The type of elements in the key arrayB- The type of elements in the value array- Parameters:
as- The array of keysbs- The array of values- Returns:
- True if the arrays are applicable for replacement, false otherwise
-
replaceEach
Replaces each occurrence of a set of keys in a string with their corresponding values.- Parameters:
keys- The array of keys to be replacedvalues- The array of values to replace the keys withstring- The input stringsensitive- A boolean flag indicating whether the replacement should be case-sensitive- Returns:
- The modified string after replacement
-
replaceEach
Replaces each occurrence of a set of keys in a string with their corresponding values. The replacement is case-insensitive.- Parameters:
keys- The array of keys to be replacedvalues- The array of values to replace the keys withstring- The input string- Returns:
- The modified string after replacement
-
replaceEach
public String replaceEach(Collection<String> keys, Collection<Object> values, String string, boolean sensitive) Replaces each occurrence of a set of keys in a string with their corresponding values.- Parameters:
keys- The collection of keys to be replacedvalues- The collection of values to replace the keys withstring- The input stringsensitive- A boolean flag indicating whether the replacement should be case-sensitive- Returns:
- The modified string after replacement
-
replaceEach
Replaces each occurrence of a set of keys in a string with their corresponding values. The replacement is case-insensitive.- Parameters:
keys- The collection of keys to be replacedvalues- The collection of values to replace the keys withstring- The input string- Returns:
- The modified string after replacement
-
replaceEach
public <T,R> String replaceEach(Map<String, T> map, Function<T, R> function, String string, boolean sensitive) Replaces each occurrence of a set of keys in a string with their corresponding values.- Type Parameters:
T- The type of the values to be replacedR- The type of the new values- Parameters:
map- The map of keys to their corresponding valuesfunction- The function to apply to each value before replacementstring- The input stringsensitive- A boolean flag indicating whether the replacement should be case-sensitive- Returns:
- The modified string after replacement
-
replaceEach
Replaces each occurrence of a set of keys in a string with their corresponding values. The replacement is case-insensitive.- Type Parameters:
T- The type of the values to be replacedR- The type of the new values- Parameters:
map- The map of keys to their corresponding valuesfunction- The function to apply to each value before replacementstring- The input string- Returns:
- The modified string after replacement
-
replaceEach
Replaces each occurrence of a set of keys in a string with their corresponding values.- Type Parameters:
T- The type of the values to be replaced- Parameters:
map- The map of keys to their corresponding valuesstring- The input stringsensitive- A boolean flag indicating whether the replacement should be case-sensitive- Returns:
- The modified string after replacement
-
replaceEach
Replaces each occurrence of a set of keys in a string with their corresponding values. The replacement is case-insensitive.- Type Parameters:
T- The type of the values to be replaced- Parameters:
map- The map of keys to their corresponding valuesstring- The input string- Returns:
- The modified string after replacement
-