Class ReplaceUtils

java.lang.Object
me.croabeast.common.util.ReplaceUtils

public class ReplaceUtils extends Object
A utility class that provides methods for replacing placeholders in strings with corresponding values.
  • Constructor Details

    • ReplaceUtils

      public ReplaceUtils()
  • Method Details

    • replace

      public String replace(String key, Object value, String string, boolean sensitive)
      Replaces occurrences of a key in a string with a specified value.
      Parameters:
      key - The key string to be replaced
      value - The value to replace the key with
      string - The input string
      sensitive - A boolean flag indicating whether the replacement should be case-sensitive
      Returns:
      The modified string after replacement
    • replace

      public String replace(String key, Object value, String string)
      Replaces occurrences of a key in a string with a specified value. The replacement is case-insensitive.
      Parameters:
      key - The key string to be replaced
      value - The value to replace the key with
      string - 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 array
      B - The type of elements in the value array
      Parameters:
      as - The array of keys
      bs - The array of values
      Returns:
      True if the arrays are applicable for replacement, false otherwise
    • replaceEach

      public String replaceEach(String[] keys, Object[] values, String string, boolean sensitive)
      Replaces each occurrence of a set of keys in a string with their corresponding values.
      Parameters:
      keys - The array of keys to be replaced
      values - The array of values to replace the keys with
      string - The input string
      sensitive - A boolean flag indicating whether the replacement should be case-sensitive
      Returns:
      The modified string after replacement
    • replaceEach

      public String replaceEach(String[] keys, Object[] values, String string)
      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 replaced
      values - The array of values to replace the keys with
      string - 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 replaced
      values - The collection of values to replace the keys with
      string - The input string
      sensitive - A boolean flag indicating whether the replacement should be case-sensitive
      Returns:
      The modified string after replacement
    • replaceEach

      public String replaceEach(Collection<String> keys, Collection<Object> values, String string)
      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 replaced
      values - The collection of values to replace the keys with
      string - 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 replaced
      R - The type of the new values
      Parameters:
      map - The map of keys to their corresponding values
      function - The function to apply to each value before replacement
      string - The input string
      sensitive - A boolean flag indicating whether the replacement should be case-sensitive
      Returns:
      The modified string after replacement
    • replaceEach

      public <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. The replacement is case-insensitive.
      Type Parameters:
      T - The type of the values to be replaced
      R - The type of the new values
      Parameters:
      map - The map of keys to their corresponding values
      function - The function to apply to each value before replacement
      string - The input string
      Returns:
      The modified string after replacement
    • replaceEach

      public <T> String replaceEach(Map<String,? extends T> map, 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 replaced
      Parameters:
      map - The map of keys to their corresponding values
      string - The input string
      sensitive - A boolean flag indicating whether the replacement should be case-sensitive
      Returns:
      The modified string after replacement
    • replaceEach

      public <T> String replaceEach(Map<String,? extends T> map, String string)
      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 values
      string - The input string
      Returns:
      The modified string after replacement