Class Strings


  • public final class Strings
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Strings()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isNullOrBlank​(java.lang.String aString)
      Checks if a string is null or blank
      static java.lang.String randomString​(int targetStringLength)  
      static java.util.List<java.lang.String> split​(java.lang.String s)
      Safely converts a string of comma separated strings into an array of strings Returns empty list if the string is null or empty
      static java.util.List<java.lang.String> split​(java.lang.String s, java.lang.String delimiter)
      Safely converts a string of 'delimiter' separated strings into an array of strings Returns empty list if the string is null or empty
      static java.lang.String substitute​(java.lang.String template, java.util.function.Function<java.lang.String,​java.lang.String> context)
      Replaces keys within the template with values using context function Throws IllegalArgumentException if the key found in the template has no corresponding value
      static java.lang.String substitute​(java.lang.String template, java.util.Map<java.lang.String,​java.lang.String> context)
      Replaces keys within the template with values using context map Throws IllegalArgumentException if the key found in the template has no corresponding value
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Strings

        public Strings()
    • Method Detail

      • substitute

        public static java.lang.String substitute​(java.lang.String template,
                                                  java.util.function.Function<java.lang.String,​java.lang.String> context)
        Replaces keys within the template with values using context function Throws IllegalArgumentException if the key found in the template has no corresponding value
        Parameters:
        template - template to use
        context - context to get values from
        Returns:
        resulting string with keys replaced with corresponding values
      • substitute

        public static java.lang.String substitute​(java.lang.String template,
                                                  java.util.Map<java.lang.String,​java.lang.String> context)
        Replaces keys within the template with values using context map Throws IllegalArgumentException if the key found in the template has no corresponding value
        Parameters:
        template - template to use
        context - context to get values from
        Returns:
        resulting string with keys replaced with corresponding values
      • split

        public static java.util.List<java.lang.String> split​(java.lang.String s)
        Safely converts a string of comma separated strings into an array of strings Returns empty list if the string is null or empty
        Parameters:
        s - a string that contains comma separated strings
        Returns:
        a list of strings
      • split

        public static java.util.List<java.lang.String> split​(java.lang.String s,
                                                             java.lang.String delimiter)
        Safely converts a string of 'delimiter' separated strings into an array of strings Returns empty list if the string is null or empty
        Parameters:
        s - a string that contains 'delimiter' separated strings
        delimiter - delimiter used
        Returns:
        a list of strings
      • isNullOrBlank

        public static boolean isNullOrBlank​(java.lang.String aString)
        Checks if a string is null or blank
        Parameters:
        aString - String to check
        Returns:
        if string is null or blank
      • randomString

        public static java.lang.String randomString​(int targetStringLength)