Package jme3utilities

Class MyString

java.lang.Object
jme3utilities.MyString

public final class MyString extends Object
Utility methods for char sequences, strings, and collections of strings.
  • Method Details

    • addMatchPrefix

      public static List<String> addMatchPrefix(Collection<String> collection, String prefix, List<String> addResult)
      Find all strings in the input collection that begin with the specified prefix and add them to the result.
      Parameters:
      collection - input collection (not null, unaffected)
      prefix - (not null)
      addResult - (added to if not null)
      Returns:
      an expanded list (either addResult or a new instance)
    • axisIndex

      public static int axisIndex(String axisName)
      Determine the index of the named coordinate axis.
      Parameters:
      axisName - the name of the axis (not null, not empty)
      Returns:
      the index of the axis: 0→X, 1→Y, 2→Z
      See Also:
    • axisName

      public static String axisName(int axisIndex)
      Describe a coordinate axis.
      Parameters:
      axisIndex - the index of the axis: 0→X, 1→Y, 2→Z
      Returns:
      a textual description (not null, not empty)
      See Also:
    • dedup

      public static void dedup(List<String> list, String separator)
      De-duplicate a list of strings by appending distinguishing suffixes as needed. The number of strings and their order remains unchanged.
      Parameters:
      list - input (not null, modified)
      separator - text to separate original name from suffix (not null)
    • describe

      public static String describe(float fValue)
      Generate a textual description of a single-precision floating-point value.
      Parameters:
      fValue - the value to describe
      Returns:
      a description (not null, not empty)
    • describeAngle

      public static String describeAngle(float fValue)
      Generate a textual description of a single-precision floating-point value using at most 2 decimal places.
      Parameters:
      fValue - the value to describe
      Returns:
      a description (not null, not empty)
    • describeFraction

      public static String describeFraction(float fValue)
      Generate a textual description of a single-precision floating-point value using at most 3 decimal places.
      Parameters:
      fValue - the value to describe
      Returns:
      a description (not null, not empty)
    • describeMatrix

      public static String describeMatrix(com.jme3.math.Matrix3f matrix)
      Generate a textual description of a Matrix3f value.
      Parameters:
      matrix - the value to describe (may be null, unaffected)
      Returns:
      a description (not null, not empty)
    • escape

      public static String escape(CharSequence unescaped)
      Replace all tab, quote, newline, and backslash characters in the specified text with escape sequences.
      Parameters:
      unescaped - the input text to escape (not null)
      Returns:
      the escaped text (not null)
      See Also:
    • findIndex

      public static int findIndex(String[] array, String value)
      Find the specified string value in an array, using a linear search. Unlike Arrays.binarySearch(java.lang.Object[], java.lang.Object), the array need not be sorted.
      Parameters:
      array - the array to search (not null, unaffected)
      value - the value to find (not null)
      Returns:
      the index of the first match (≥0, <length) or -1 if not found
    • findLongestPrefix

      public static String findLongestPrefix(Collection<String> collection)
      Find the longest repeated prefix in a collection of strings.
      Parameters:
      collection - (not null, unaffected)
      Returns:
      prefix (not null)
    • firstToLower

      public static String firstToLower(String input)
      Convert the first character of the specified text to lower case.
      Parameters:
      input - the input text to convert (not null)
      Returns:
      the converted text (not null)
    • invert

      public static Map<String,String> invert(Map<String,String> input)
      Invert the specified String-to-String map.
      Parameters:
      input - (not null, unaffected)
      Returns:
      a new String-to-String map
    • isSorted

      public static boolean isSorted(List<String> list)
      Test whether the specified List is lexicographically sorted in ascending order with no duplicates.
      Parameters:
      list - the List to analyze (not null, unaffected)
      Returns:
      true if sorted, otherwise false
    • join

      public static String join(CharSequence separator, Iterable objects)
      Join a collection of objects into a text string using the specified separator, ignoring any empties/nulls. Note that Java 8 provides String.join(java.lang.CharSequence, java.lang.Iterable), which doesn't ignore nulls.
      Parameters:
      separator - text string (not null)
      objects - objects to join (not null, unaffected, may contain nulls)
      Returns:
      joined string (not null)
    • join

      public static String join(Iterable objects)
      Join a collection of objects into a text string using spaces for separators and ignoring any empties/nulls.

      Note that Java 8 provides String.join(java.lang.CharSequence, java.lang.Iterable), which doesn't ignore nulls.

      Parameters:
      objects - objects to join (not null, unaffected, may contain nulls)
      Returns:
      joined string (not null)
    • join

      public static String join(Object[] array)
      Join an array of objects into a text string using spaces for separators and ignoring any empties/nulls.
      Parameters:
      array - objects to join (not null, unaffected, may contain nulls)
      Returns:
      joined string (not null)
    • matchPrefix

      public static void matchPrefix(Collection<String> collection, String prefix)
      Filter a collection of strings, keeping only those that begin with the specified prefix.
      Parameters:
      collection - collection to filter (not null, modified)
      prefix - (not null)
    • quote

      public static String quote(CharSequence text)
      Enclose the specified text in quotation marks and escape all tab, quote, newline, and backslash characters.
      Parameters:
      text - the input text to quote
      Returns:
      the quoted text, or "null" if the input was null
    • quoteName

      public static String quoteName(CharSequence name)
      Enclose the specified name in quotation marks and escape all tab, quote, newline, and backslash characters.
      Parameters:
      name - the name to quote
      Returns:
      a quoted string, or "(no name)" if the name was null
    • reduce

      public static void reduce(Collection<String> collection, int sizeGoal)
      Reduce a collection of strings using common prefixes.
      Parameters:
      collection - (not null, modified)
      sizeGoal - (>0)
    • remainder

      public static String remainder(String input, String prefix)
      Extract the remainder of the specified string after removing the specified prefix.
      Parameters:
      input - the input string (not null)
      prefix - the prefix string (not null)
      Returns:
      the remainder of the input (not null)
    • removeSuffix

      public static String removeSuffix(String input, String suffix)
      Extract the remainder of the specified string after removing the specified suffix.
      Parameters:
      input - the input string (not null)
      suffix - the suffix string (not null)
      Returns:
      the remainder of the input (not null)
    • repeat

      public static String repeat(CharSequence sequence, int numTimes)
      Generate a String consisting of a specified character sequence repeated a specified number of times.
      Parameters:
      sequence - the sequence to use (not null)
      numTimes - the number of times (≥0)
      Returns:
      a repetitious String
    • sharedPrefixLength

      public static int sharedPrefixLength(CharSequence s1, CharSequence s2)
      Find the length of the shared prefix of 2 text sequences.
      Parameters:
      s1 - the first string (not null)
      s2 - the 2nd string (not null)
      Returns:
      number of characters in shared prefix (≥0)
    • toArray

      public static String[] toArray(Collection<String> collection)
      Convert a collection of strings into an array. This is more convenient than Collection.toArray() because the elements of the resulting array will all be strings.
      Parameters:
      collection - the collection to convert (not null)
      Returns:
      a new array containing the same strings in the same order
    • trimFloat

      public static String trimFloat(String input)
      Trim any trailing zeros and one trailing decimal point from a string representation of a float. Also remove any leading minus sign from zero.
      Parameters:
      input - the String to trim (not null)
      Returns:
      a trimmed String (not null)
    • unEscape

      public static String unEscape(CharSequence escaped)
      Undo character escape sequences added by escape(CharSequence).
      Parameters:
      escaped - the input sequence (not null)
      Returns:
      an unescaped string (not null)