Class EmbeddedParameterUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProvides options.static classDesignates an exception which occurs because the format of an argument string is wrong.static classDesignates an exception which occurs because the format of an argument string is wrong. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetParameterReplacedString(String string, String startSymbol, String endSymbol, Function<String, String> valueGetterFromKey) Returns string with embedded parameters replaced.static StringgetParameterReplacedString(String string, String startSymbol, String endSymbol, Function<String, String> valueGetterFromKey, EmbeddedParameterUtil.Options options) Returns string with embedded parameters replaced.static StringgetParameterReplacedString(String string, String startSymbol, String endSymbol, Map<String, String> parameterMap) Returns string with embedded parameters replaced.static StringgetParameterReplacedString(String string, String startSymbol, String endSymbol, Map<String, String> parameterMap, EmbeddedParameterUtil.Options options) Returns string with embedded parameters replaced.getPartList(String string, String[] startSymbols, String endSymbol) Divides the argument string into simple string and parameter parts and Returns list of them.getPartList(String string, String[] startSymbols, String endSymbol, EmbeddedParameterUtil.Options options) Divides the argument string into simple string and parameter parts and Returns list of them.
-
Method Details
-
getPartList
@Nonnull public static List<org.apache.commons.lang3.tuple.Pair<String,String>> getPartList(@RequireNonnull String string, @RequireNonnull @RequireSizeNonzero @RequireElementNonempty String[] startSymbols, @RequireNonempty String endSymbol, @Nullable EmbeddedParameterUtil.Options options) throws EmbeddedParameterUtil.StringFormatIncorrectException, MultipleAppException Divides the argument string into simple string and parameter parts and Returns list of them.When you replace embedded parameter into strings, the following logic is not good: search 1st parameter -> replace 1st parameter -> search 2nd parameter -> ... because if 1st parameter constains start or end symbol, 2nd parameter cannot be found.
The logic must be like this: search all parameters -> replace all parameters
This method is in charge of the former part. It searches and divides all the parameters and strings.
In the case that there are multiple start symbols, it's passed as String[].
- Returns:
- Pair of String, String. The left side of the pair is the startSymbol, and the right parameter name when param exists. And {null, "string"} when it's simple string. It returns list with size zero when the argument string is blank("").
- Throws:
MultipleAppException- MultipleAppExceptionEmbeddedParameterUtil.StringFormatIncorrectException- StringFormatIncorrectException
-
getPartList
@Nonnull public static List<org.apache.commons.lang3.tuple.Pair<String,String>> getPartList(@RequireNonnull String string, @RequireNonnull @RequireSizeNonzero @RequireElementNonempty String[] startSymbols, @RequireNonempty String endSymbol) throws AppException Divides the argument string into simple string and parameter parts and Returns list of them.When you replace embedded parameter into strings, the following logic is not good: search 1st parameter -> replace 1st parameter -> search 2nd parameter -> ... because if 1st parameter constains start or end symbol, 2nd parameter cannot be found.
The logic must be like this: search all parameters -> replace all parameters
This method is in charge of the former part. It searches and divides all the parameters and strings.
In the case that there are multiple start symbols, it's passed as String[].
- Returns:
- Pair of String, String. The left side of the pair is the startSymbol, and the right parameter name when param exists. And {null, "string"} when it's simple string. It returns list with size zero when the argument string is blank("").
- Throws:
AppException- AppException
-
getParameterReplacedString
public static String getParameterReplacedString(@RequireNonnull String string, @RequireNonempty String startSymbol, @RequireNonempty String endSymbol, @RequireNonnull Function<String, String> valueGetterFromKey, @Nullable EmbeddedParameterUtil.Options options) throws EmbeddedParameterUtil.StringFormatIncorrectException, MultipleAppException, EmbeddedParameterUtil.ParameterNotFoundExceptionReturns string with embedded parameters replaced.- Parameters:
string- string with parameters embeddedstartSymbol- left-side symbol enclosing parametersendSymbol- right-side symbol enclosing parametersvalueGetterFromKey- Function which obtains value from key.options- options- Returns:
- string with embedded parameters replaced
- Throws:
MultipleAppException- MultipleAppExceptionEmbeddedParameterUtil.StringFormatIncorrectException- StringFormatIncorrectExceptionEmbeddedParameterUtil.ParameterNotFoundException- StringFormatIncorrectException
-
getParameterReplacedString
public static String getParameterReplacedString(@RequireNonnull String string, @RequireNonempty String startSymbol, @RequireNonempty String endSymbol, @RequireNonnull Function<String, String> valueGetterFromKey) throws EmbeddedParameterUtil.StringFormatIncorrectException, MultipleAppException, EmbeddedParameterUtil.ParameterNotFoundExceptionReturns string with embedded parameters replaced.- Parameters:
string- string with parameters embeddedstartSymbol- left-side symbol enclosing parametersendSymbol- right-side symbol enclosing parametersvalueGetterFromKey- Function which obtains value from key.- Returns:
- string with embedded parameters replaced
- Throws:
MultipleAppException- MultipleAppExceptionEmbeddedParameterUtil.StringFormatIncorrectException- StringFormatIncorrectExceptionEmbeddedParameterUtil.ParameterNotFoundException- StringFormatIncorrectException
-
getParameterReplacedString
public static String getParameterReplacedString(@RequireNonnull String string, @RequireNonempty String startSymbol, @RequireNonempty String endSymbol, @RequireNonnull Map<String, String> parameterMap, @Nullable EmbeddedParameterUtil.Options options) throws EmbeddedParameterUtil.StringFormatIncorrectException, MultipleAppException, EmbeddedParameterUtil.ParameterNotFoundExceptionReturns string with embedded parameters replaced.- Parameters:
string- string with parameters embeddedstartSymbol- left-side symbol enclosing parametersendSymbol- right-side symbol enclosing parametersparameterMap- It stores parameter keys and those values.options- options- Returns:
- string with embedded parameters replaced
- Throws:
MultipleAppException- MultipleAppExceptionEmbeddedParameterUtil.StringFormatIncorrectException- StringFormatIncorrectExceptionEmbeddedParameterUtil.ParameterNotFoundException- StringFormatIncorrectException
-
getParameterReplacedString
public static String getParameterReplacedString(@RequireNonnull String string, @RequireNonempty String startSymbol, @RequireNonempty String endSymbol, @RequireNonnull Map<String, String> parameterMap) throws EmbeddedParameterUtil.StringFormatIncorrectException, MultipleAppException, EmbeddedParameterUtil.ParameterNotFoundExceptionReturns string with embedded parameters replaced.- Parameters:
string- string with parameters embeddedstartSymbol- left-side symbol enclosing parametersendSymbol- right-side symbol enclosing parametersparameterMap- It stores parameter keys and those values.- Returns:
- string with embedded parameters replaced
- Throws:
MultipleAppException- MultipleAppExceptionEmbeddedParameterUtil.StringFormatIncorrectException- StringFormatIncorrectExceptionEmbeddedParameterUtil.ParameterNotFoundException- ParameterNotFoundException
-