Class PBStringUtils

java.lang.Object
com.bonitasoft.processbuilder.extension.PBStringUtils

public final class PBStringUtils extends Object
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 Details

    • normalizeTitleCase

      public static String normalizeTitleCase(String str)
      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"
      • null remains null
      • "" 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

      public static String toLowerSnakeCase(String input)
      Converts a string from human-readable format (e.g., spaces) to snake_case format. 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"
      • null remains null
      Parameters:
      input - The string to convert.
      Returns:
      The string in snake_case format, or the original string if null.
    • toUpperSnakeCase

      public static String toUpperSnakeCase(String input)
      Converts a string from human-readable format (e.g., spaces) to snake_case format. 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"
      • null remains null
      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.