Class StringUtil

java.lang.Object
com.brightcove.player.util.StringUtil

public class StringUtil extends Object
Some assorted utility methods for dealing with Strings.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Format string used for long time expressions which include hours.
    static final String
    Format string used for short time expressions which are less than an hour.
    static final String
    Format string used for short time expressions which are less than ten minutes.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Determines if given string is empty or null.
    static String
    join(String[] stringsToJoin, String separator)
    Joins the Strings in the given array together into a single String using the specified separator String.
    static String
    join(List<String> stringsToJoin, String separator)
    Joins the Strings in the given List together into a single String using the specified separator String.
    replaceAll(CharSequence template, String[] sources, CharSequence[] destinations)
    This method is based on Android's TextUtils.replace(CharSequence, String[], CharSequence[]) and extends its functionality by replacing all instances of each String specified in the sources parameter with the associated destination CharSequence.
    static String
    stringForTime(long milliseconds)
    Formats the given time duration value (in milliseconds) as a time string in one of the following formats: HH:MM:SS where the timeframe is greater than 1 hour MM:SS where the timeframe is less than an hour M:SS where the timeframe is less than ten minutes

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LONG_TIME_FORMAT

      public static final String LONG_TIME_FORMAT
      Format string used for long time expressions which include hours.
      See Also:
    • SHORT_TIME_FORMAT

      public static final String SHORT_TIME_FORMAT
      Format string used for short time expressions which are less than an hour.
      See Also:
    • SHORTER_TIME_FORMAT

      public static final String SHORTER_TIME_FORMAT
      Format string used for short time expressions which are less than ten minutes.
      See Also:
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • isEmpty

      public static boolean isEmpty(String str)
      Determines if given string is empty or null.
      Parameters:
      str - the String to evaluate
      Returns:
      true if the String is null or contains only whitespace, false otherwise
    • join

      public static String join(List<String> stringsToJoin, String separator)
      Joins the Strings in the given List together into a single String using the specified separator String.
      Parameters:
      stringsToJoin - the List of Strings to join
      separator - the String to be inserted between each element of the array
      Returns:
      the concatenated String
    • stringForTime

      public static String stringForTime(long milliseconds)
      Formats the given time duration value (in milliseconds) as a time string in one of the following formats:
      • HH:MM:SS where the timeframe is greater than 1 hour
      • MM:SS where the timeframe is less than an hour
      • M:SS where the timeframe is less than ten minutes
      Parameters:
      milliseconds - the time duration to format, in milliseconds
      Returns:
      the formatted string expression for the given time duration
    • join

      public static String join(String[] stringsToJoin, String separator)
      Joins the Strings in the given array together into a single String using the specified separator String.
      Parameters:
      stringsToJoin - the array of Strings to join
      separator - the String to be inserted between each element of the array
      Returns:
      the concatenated String
    • replaceAll

      public static CharSequence replaceAll(CharSequence template, String[] sources, CharSequence[] destinations)
      This method is based on Android's TextUtils.replace(CharSequence, String[], CharSequence[]) and extends its functionality by replacing all instances of each String specified in the sources parameter with the associated destination CharSequence. It is important to note that this exists for CharSequences (which are not necessarily Strings) that have Spanned portions and for which the relevant spans must be maintained. If we were to use String.replaceAll(String, String) in cases such as these, the span information would be lost.
      Parameters:
      template - the CharSequence on which we should perform replacements
      sources - an Array of Strings to find and replace in template
      destinations - an Array of CharSequences corresponding to the sources strings which will serve as replacements
      Returns:
      the CharSequence with all replacements applied
      See Also:
      • TextUtils.replace(CharSequence, String[], CharSequence[])