Class PBStringUtils
java.lang.Object
com.bonitasoft.processbuilder.extension.PBStringUtils
Utility class providing common String manipulation methods, focusing on
normalization and case formatting.
This class is designed to be non-instantiable and should only be accessed via static methods.
- Since:
- 1.0
- Author:
- Bonitasoft
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringnormalizeTitleCase(String str) Normalizes the input String to Title Case format: the first letter is capitalized, and all subsequent letters are lowercased.static StringresolveTemplateVariables(String template, BiFunction<String, String, String> dataValueResolver) Resolves and replaces all variables in the format{{refStep:dataName}}within a template string.static StringtoLowerSnakeCase(String input) Converts a string from human-readable format (e.g., spaces) tosnake_caseformat.static StringtoUpperSnakeCase(String input) Converts a string from human-readable format (e.g., spaces) tosnake_caseformat.
-
Method Details
-
normalizeTitleCase
Normalizes the input String to Title Case format: the first letter is capitalized, and all subsequent letters are lowercased.This implementation is optimized to minimize intermediate String object creation.
"CATEGORY"becomes"Category""category"becomes"Category""CaTegory"becomes"Category"nullremainsnull""remains"""a"becomes"A"
- Parameters:
str- The string to normalize.- Returns:
- The string in Title Case, or the original string if null or empty.
-
toLowerSnakeCase
Converts a string from human-readable format (e.g., spaces) tosnake_caseformat. The conversion process involves:- Converting the entire string to lowercase.
- Replacing all space characters (' ') with underscores ('_').
"Bonita and delete"becomes"bonita_and_delete""A Long Name"becomes"a_long_name"nullremainsnull
- Parameters:
input- The string to convert.- Returns:
- The string in snake_case format, or the original string if null.
-
toUpperSnakeCase
Converts a string from human-readable format (e.g., spaces) tosnake_caseformat. The conversion process involves:- Converting the entire string to uppercase.
- Replacing all space characters (' ') with underscores ('_').
"Bonita and delete"becomes"BONITA_AND_DELETE""A Long Name"becomes"A_LONG_NAME"nullremainsnull
- Parameters:
input- The string to convert.- Returns:
- The string in snake_case format, or the original string if null.
-
resolveTemplateVariables
public static String resolveTemplateVariables(String template, BiFunction<String, String, String> dataValueResolver) Resolves and replaces all variables in the format{{refStep:dataName}}within a template string. The replacement value is retrieved via a functional interface provided by the caller.- Parameters:
template- The string containing the variables to be resolved.dataValueResolver- A function that takes (refStep, dataName) and returns the corresponding data value as a String. This function encapsulates the DAO lookup logic (e.g., PBDataProcessInstanceDAO.findByStepRefAndDataName).- Returns:
- The template with all variables resolved, or the original template if it's null/empty.
-