Class GStrings

java.lang.Object
com.glitchybyte.glib.GStrings

public final class GStrings extends Object
String utilities.
  • Field Details

    • NEW_LINE

      public static final String NEW_LINE
      System new line separator.
    • SPACE_TAB

      public static final String SPACE_TAB
      Spaces for indentation.
      See Also:
  • Method Details

    • isNullOrEmpty

      public static boolean isNullOrEmpty(String str)
      Convenience for common test of a null or empty string.
      Parameters:
      str - String to test.
      Returns:
      True, if the string is null or empty.
    • indent

      public static String indent(String str)
      Indents the string. It will correctly indent multiple lines as long as they have system line separators.

      Unlike String.indent, this function does not add a new line if it doesn't exist.

      Parameters:
      str - String to indent.
      Returns:
      Indented string.
    • format

      public static String format(String format, Object... args)
      Convenience replacement for String.format that already includes US locale.
      Parameters:
      format - A format string.
      args - Arguments for format.
      Returns:
      Formatted string.
    • toLowerCase

      public static String toLowerCase(String str)
      Convenience replacement for String.toLowerCase that already includes US locale.
      Parameters:
      str - String to convert.
      Returns:
      Converted string.
    • toUpperCase

      public static String toUpperCase(String str)
      Convenience replacement for String.toUpperCase that already includes US locale.
      Parameters:
      str - String to convert.
      Returns:
      Converted string.
    • fromDouble

      public static String fromDouble(double value)
      Convenience double to String formatter with human minimal representation.
      Parameters:
      value - Double to format into a String.
      Returns:
      Minimal String representation of the value.
    • fromFloat

      public static String fromFloat(float value)
      Convenience float to String formatter with human minimal representation.
      Parameters:
      value - Float to format into a String.
      Returns:
      Minimal String representation of the value.
    • fromInt

      public static String fromInt(int value)
      Convenience int to String formatter with human minimal representation.
      Parameters:
      value - Int to format into a String.
      Returns:
      Minimal String representation of the value.
    • fromLong

      public static String fromLong(long value)
      Convenience long to String formatter with human minimal representation.
      Parameters:
      value - Long to format into a String.
      Returns:
      Minimal String representation of the value.
    • fromCollection

      public static <T> String fromCollection(Collection<T> collection, String delimiter)
      Convenience Collection to String representation.
      Type Parameters:
      T - Type of elements in the collection.
      Parameters:
      collection - Collection to represent as String.
      delimiter - Delimiter to use between elements.
      Returns:
      A String representing the collection.
    • fromCollection

      public static <T> String fromCollection(Collection<T> collection)
      Convenience Collection to String representation with default comma delimiter.
      Type Parameters:
      T - Type of elements in the collection.
      Parameters:
      collection - Collection to represent as String.
      Returns:
      A String representing the collection.
    • base64Encode

      public static String base64Encode(String message)
      Convenience base64 encoder. Assumes UTF-8 charset.
      Parameters:
      message - Message to encode.
      Returns:
      Encoded message.
    • base64Decode

      public static String base64Decode(String encoded)
      Convenience base64 decoder. Assumes UTF-8 charset.
      Parameters:
      encoded - Encoded message.
      Returns:
      Decoded message.
    • bytesToGroupUnit

      public static String bytesToGroupUnit(long bytes)
      Converts a number of bytes to its most reasonable grouping representation.
      Parameters:
      bytes - Quantity of bytes.
      Returns:
      A string representing those bytes in human-readable form.
    • indexOfAny

      public static int indexOfAny(String str, Set<Character> characterSet, int offset)
      Returns the index of the 1st character in the set found in the string.
      Parameters:
      str - Input string.
      characterSet - Characters to find.
      offset - Offset from the beginning of the string.
      Returns:
      The index of the 1st character in the set found in the string, or -1 of not found.
    • indexOfAny

      public static int indexOfAny(String str, Set<Character> characterSet)
      Returns the index of the 1st character in the set found in the string.
      Parameters:
      str - Input string.
      characterSet - Characters to find.
      Returns:
      The index of the 1st character in the set found in the string, or -1 of not found.