jv.number

## Class PuString

- java.lang.Object
- - jv.number.PuString

-     public abstract class PuString
      extends java.lang.Object

  Utility functions comparing and operating with strings.
  Author:
    Konrad Polthier
  Version:
    14.12.04, 2.00 revised (kp) New method replace().
    26.10.03, 1.90 revised (kp) New method to merge an array of strings.
    09.02.02, 1.80 revised (kp) New methods to write double and float values in non-exponential form to string.
    12.02.01, 1.70 revised (kp) New method mergeStrings() added.
    17.11.00, 1.60 revised (kp) Method for cloning of strings added.
    08.11.00, 1.50 revised (kp) Number formatting methods added.
    30.10.99, 1.00 created (kp)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `m_bConvertDoubleToFloat` HACK: flag if methods PuString.toString(double ..) convert doubles to floats in order to reduce file size.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PuString()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `bracketedString(java.lang.String str, char leftDelim, char rightDelim)` Get part of string which is bracketed by two given characters.
    `static java.lang.String[][]` | `clone(java.lang.String[][] src)` Duplicate array and all entries by recursively cloning all instance variables except inspector panels and lists of registered listeners.
    `static int` | `commonInitials(java.lang.String str1, java.lang.String str2)` Returns the length of the initial segment of str1 that equals str2.
    `static int` | `containsChars(java.lang.String str, char c)` Returns the number of times the given character appears in the string.
    `static java.lang.String` | `doubleToString(double d, int mantissa)` Converts a double to a String with given number of mantissa digits in exponential form '-d.dddddEdd' or ' d.dddddEdd'.
    `static java.lang.String` | `doubleToString(double d, int mantissa, int width)` Converts a double to a string with given number of mantissa digits in non exponential form.
    `static int` | `fromCharSet(java.lang.String str, java.lang.String charSet, int fromIdx)` Returns the length of the initial segment of str which consists entirely of characters from charSet, starting at the given index.
    `static int` | `indexOfString(java.lang.String[] strings, java.lang.String string)` Locates a String in an array of Strings.
    `static int` | `indexOfStringIgnoreCase(java.lang.String[] strings, java.lang.String string)` Locates a String in an array of Strings, ignoring case.
    `static java.lang.String` | `intToString(int i, int width)` Converts an integer to a string with given width of the string.
    `static boolean` | `isEmpty(java.lang.String str)` Check if string is empty or consists of empty string.
    `static boolean` | `matchPattern(java.lang.String string, java.lang.String pattern)` Checks whether a string matches a given wildcard pattern.
    `static java.lang.String` | `mergeStrings(java.lang.String[] str, char delim)` Merges an array of strings into a single string separated by the specified delimiter.
    `static java.lang.String` | `mergeStrings(java.lang.String[] str, java.lang.String delim)` Merges an array of strings into a single string separated by the specified delimiter.
    `static java.lang.String` | `millisToString(long millis)` Get a string representation of the time argument specified in milliseconds.
    `static int` | `notFromCharSet(java.lang.String str, java.lang.String charSet, int fromIdx)` Returns the length of the initial segment of str which consists entirely of characters NOT from charSet, starting at the given index.
    `static int` | `numSplitStrings(java.lang.String str, char delim)` Turns a string into an array of strings, by splitting it at the specified character.
    `static java.lang.String` | `replace(java.lang.String str, java.lang.String sub, java.lang.String newSub)` Replaces all substrings one after another with new substring.
    `static java.lang.String` | `replaceTab(java.lang.String str, int numSpaces)` Replaces all TAB ('\t') characters by the given number of spaces.
    `static java.lang.String` | `shortCutString(java.lang.String s, int numChars)` Abbreviates a given string to numChars characters.
    `static void` | `sort(java.lang.String[] strings)` Sorts an array of Strings and modifies array in place.
    `static java.lang.String[]` | `sort(java.lang.String[] origStrings, int[] index)` Sorts an array of Strings without modifying the original array.
    `static java.lang.String[]` | `splitString(java.lang.String str, char delim)` Turns a string into an array of strings, by splitting it at the specified character.
    `static java.lang.String[]` | `splitString(java.lang.String str, int maxCharsPerString)` Tries to split the given string into segments at most `maxCharsPerString` long.
    `static java.lang.String[]` | `splitString(java.lang.String str, int maxWidth, java.awt.FontMetrics fm)` Tries to split the given string into segments at most `maxWidth` pixels long w.r.t. the given FontMetrics.
    `static java.lang.String` | `timeToString(long time)` Formats a given time (in ms) as String.
    `static java.lang.String` | `toString(double d)` Converts a double to a string in non exponential form.
    `static java.lang.String` | `toString(double[] data)` Create single line string of double array where components are separated by blanks.
    `static java.lang.String` | `toString(double[] data, boolean bExp)` Create single line string of double array where components are separated by blanks.
    `static java.lang.String` | `toString(double[] data, boolean bFloat, boolean bExp)` Create single line string of double array where components are separated by blanks.
    `static java.lang.String` | `toString(double d, int digits)` Returns a string representation of a double number in a non-exponential form.
    `static java.lang.String` | `toString(float d)` Converts a float to a string in non exponential form.
    `static java.lang.String` | `toString(float[] data)` Create single line string of float array where components are separated by blanks.
    `static java.lang.String` | `toString(float[] data, boolean bExp)` Create single line string of float array where components are separated by blanks.
    `static java.lang.String` | `toString(int[] data)` Create single line string of integer array where components are separated by blanks.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### m_bConvertDoubleToFloat

          public static boolean m_bConvertDoubleToFloat

      HACK: flag if methods PuString.toString(double ..) convert doubles to floats in order to reduce file size.

  - ### Constructor Detail

    - #### PuString

          public PuString()

  - ### Method Detail

    - #### clone

          public static java.lang.String[][] clone(java.lang.String[][] src)

      Duplicate array and all entries by recursively cloning all instance variables except inspector panels and lists of registered listeners. The parent relationship is maintained only within this class but not to external classes. In general, all links of the clone to external objects are set to `null`.
      Version:
        23.08.03, 1.10 revised (kp) Check for null entries.
        05.07.00, 1.00 created (kp)

    - #### fromCharSet

          public static int fromCharSet(java.lang.String str,
                                        java.lang.String charSet,
                                        int fromIdx)

      Returns the length of the initial segment of str which consists entirely of characters from charSet, starting at the given index.

    - #### notFromCharSet

          public static int notFromCharSet(java.lang.String str,
                                           java.lang.String charSet,
                                           int fromIdx)

      Returns the length of the initial segment of str which consists entirely of characters NOT from charSet, starting at the given index.

    - #### matchPattern

          public static boolean matchPattern(java.lang.String string,
                                             java.lang.String pattern)

      Checks whether a string matches a given wildcard pattern. Only does ? and *, and multiple patterns separated by |.

    - #### commonInitials

          public static int commonInitials(java.lang.String str1,
                                           java.lang.String str2)

      Returns the length of the initial segment of str1 that equals str2.

    - #### containsChars

          public static int containsChars(java.lang.String str,
                                          char c)

      Returns the number of times the given character appears in the string.

    - #### isEmpty

          public static boolean isEmpty(java.lang.String str)

      Check if string is empty or consists of empty string.
      Returns:
        `true` if string is empty or consists of empty string.
      Since:
        JavaView 3.54.000
      Version:
        28.08.04, 1.00 created (kp)

    - #### bracketedString

          public static java.lang.String bracketedString(java.lang.String str,
                                                         char leftDelim,
                                                         char rightDelim)

      Get part of string which is bracketed by two given characters. Method looks for left most appearance of leftDelim, and right most appearance of rightDelim. To avoid ambiguous situations, both characters should appear only once inside the full string.

      Method issues a warning if only one delimiter is found.

      Parameters:
        `str` - String containing bracketed substring.
        `leftDelim` - left bracket character
        `rightDelim` - right bracket character
      Returns:
        part of string between both brackets, `null` if delimiter no found.
      Version:
        27.08.01, 1.10 revised (kp) Do not issue warning if neither delimiter is found.

    - #### splitString

          public static java.lang.String[] splitString(java.lang.String str,
                                                       char delim)

      Turns a string into an array of strings, by splitting it at the specified character. This does not use StringTokenizer, and therefore can handle empty fields.

      If argument string ends with the delimiter then delimiter is ignored.

      If delimiter is blank then consecutive sequences of blanks are identified to a single blank. This identification is not performed with other delimiters.

      If string does not contain the delimiter, then the string is returned as array of length 1. Unless the delimiter is blank or appears at the end of the original string, the original string can always be reconstructed from the returned array.

      If the string is null then null is return.

      Parameters:
        `str` - Delimiter separated strings to split.
        `delim` - Character delimiter.
      Returns:
        Array with strings obtained from splitting
      Version:
        01.11.05, 1.20 revised (kp) Instead of null, now return string as array if no delim found.
        29.10.00, 1.10 revised (kp) Ignore trailing delimiters.

    - #### numSplitStrings

          public static int numSplitStrings(java.lang.String str,
                                            char delim)

      Turns a string into an array of strings, by splitting it at the specified character. This does not use StringTokenizer, and therefore can handle empty fields.

      If argument string ends with the delimiter then delimiter is ignored.

      If delimiter is blank then consecutive sequences of blanks are identified to a single blank. This identification is not performed with other delimiters.

      Parameters:
        `str` - Delimiter separated strings to split.
        `delim` - Character delimiter.
      Returns:
        Array with strings obtained from splitting
      Version:
        29.10.00, 1.10 revised (kp) Ignore trailing delimiters

    - #### splitString

          public static java.lang.String[] splitString(java.lang.String str,
                                                       int maxCharsPerString)

      Tries to split the given string into segments at most `maxCharsPerString` long. Connected (non-whitespace ' \t\n') characters are not split up into different Strings. A '\n' forces a new string (and is removed afterwards). A '\n' at the end of the original string is ignored. If two words are split, then all whitespace at the beginning of the next part are removed. This does not happen if the split was forced by a '\n'. A '\t' counts as 4x' '.
      Parameters:
        `str` - the string to be split
        `maxCharsPerString` - the maximum number of characters a single result string shall contain
      Returns:
        array with strings obtained from splitting
      Version:
        17.01.02, 1.00 created (ep)

    - #### splitString

          public static java.lang.String[] splitString(java.lang.String str,
                                                       int maxWidth,
                                                       java.awt.FontMetrics fm)

      Tries to split the given string into segments at most `maxWidth` pixels long w.r.t. the given FontMetrics. Connected (non-whitespace ' \t\n') characters are not split up into different Strings. A '\n' forces a new string (and is removed afterwards). A '\n' at the end of the original string is ignored. If two words are split, then all whitespace at the beginning of the next part are removed. This does not happen if the split was forced by a '\n'. A '\t' counts as 4x' '.
      Parameters:
        `str` - the string to be split
        `maxWidth` - the maximum number of pixels a single result string shall contain
        `fm` - font metrics that represents the font w.r.t. the system
      Returns:
        array with strings obtained from splitting
      Version:
        17.01.02, 1.00 created (ep)

    - #### replaceTab

          public static java.lang.String replaceTab(java.lang.String str,
                                                    int numSpaces)

      Replaces all TAB ('\t') characters by the given number of spaces.
      Parameters:
        `str` - the string to be converted
        `numSpaces` - number of ' '-characters that replace one '\t'
      Returns:
        string without tabs but sequences of ' ' instead
      Version:
        17.01.02, 1.00 created (ep)

    - #### replace

          public static java.lang.String replace(java.lang.String str,
                                                 java.lang.String sub,
                                                 java.lang.String newSub)

      Replaces all substrings one after another with new substring.
      Parameters:
        `str` - the string to be converted
        `sub` - substring to be replaced
        `newSub` - replacement substring
      Returns:
        modified string
      Since:
        JavaView v.3.64.001
      Version:
        14.12.04, 1.00 created (kp)

    - #### mergeStrings

          public static java.lang.String mergeStrings(java.lang.String[] str,
                                                      char delim)

      Merges an array of strings into a single string separated by the specified delimiter.

      If the array is null, then an empty string is returned. Otherwise, the number of delimiters in the resulting string is equal to str.length-1. Missing strings are considered empty strings.

      If the delimiter is the empty string, then strings are concatenated.

      Parameters:
        `str` - Array with strings to merge.
        `delim` - Character to separate merged strings.
      Returns:
        merged string with entries separated by the specified delimiter
      Version:
        26.10.03, 1.20 revised (kp) Allow empty string as delimiter for concatenation.
        12.02.01, 1.00 created (kp)

    - #### mergeStrings

          public static java.lang.String mergeStrings(java.lang.String[] str,
                                                      java.lang.String delim)

      Merges an array of strings into a single string separated by the specified delimiter.

      If the array is null, then an empty string is returned. Otherwise, the number of delimiters in the resulting string is equal to str.length-1. Missing strings are considered empty strings.

      If the delimiter is the empty string, then strings are concatenated.

      Parameters:
        `str` - Array with strings to merge.
        `delim` - String to separate merged strings.
      Returns:
        merged string with entries separated by the specified delimiter
      Since:
        JavaView 2.99.035
      Version:
        26.10.03, 1.00 created (kp)

    - #### sort

          public static void sort(java.lang.String[] strings)

      Sorts an array of Strings and modifies array in place.

    - #### sort

          public static java.lang.String[] sort(java.lang.String[] origStrings,
                                                int[] index)

      Sorts an array of Strings without modifying the original array. Returns an index vector and the sorted array.

    - #### indexOfString

          public static int indexOfString(java.lang.String[] strings,
                                          java.lang.String string)

      Locates a String in an array of Strings. Returns -1 if the String is not found.

    - #### indexOfStringIgnoreCase

          public static int indexOfStringIgnoreCase(java.lang.String[] strings,
                                                    java.lang.String string)

      Locates a String in an array of Strings, ignoring case. Returns -1 if the String is not found.

    - #### intToString

          public static java.lang.String intToString(int i,
                                                     int width)

      Converts an integer to a string with given width of the string. If integer is positive then string contains a leading white space.

      If string is too small then string is filled with '9' and a warning message issued.

      Parameters:
        `i` - the integer to be converted
        `width` - width of the returned string including leading ' ' resp. '-'.
      Returns:
        integer converted into a string
      Author:
        Samy Khadem-Al-Charieh 08.11.00, 1.20 revised (kp) Method moved here from jv.loader.PgByuLoader.
        14.10.99, 1.00 created (sk)

    - #### toString

          public static java.lang.String toString(double d)

      Converts a double to a string in non exponential form.

      If d is in the range `10^-3 <= |d| <=10^7`, then the result coincides with the result of Double.toString(double), i.e. the result is a string in the style [-]ddd.ddd.

      Otherwise, the result of Double.toString(double) is postprocessed to obtain a non-exponential form. There is always a minimum of one digit after the decimal point. The number of digits is the minimum needed to uniquely distinguish the argument value from adjacent values of type double.

      Parameters:
        `d` - the double
      Returns:
        the string representation of the double value
      Author:
        Konrad Polthier
      Version:
        09.02.02, 1.00 created (kp)

    - #### toString

          public static java.lang.String toString(double d,
                                                  int digits)

      Returns a string representation of a double number in a non-exponential form. The number of digits behind the decimal point can be specified.
      Parameters:
        `d` - the double to convert.
        `digits` - number of decimal places.
      Author:
        Matthias Nieser
      Version:
        16.08.06, 1.00 created(mn)

    - #### toString

          public static java.lang.String toString(double[] data,
                                                  boolean bExp)

      Create single line string of double array where components are separated by blanks.
      Parameters:
        `data` - array of double number to be printed.
        `bExp` - if false, then use non-exponential representation
      Returns:
        single-line string, or empty string.
      Author:
        Konrad Polthier
      Version:
        06.03.02, 1.00 created (kp)

    - #### toString

          public static java.lang.String toString(double[] data,
                                                  boolean bFloat,
                                                  boolean bExp)

      Create single line string of double array where components are separated by blanks.
      Parameters:
        `data` - array of double number to be printed.
        `bFloat` - if true, then convert to float before saving
        `bExp` - if false, then use non-exponential representation
      Returns:
        single-line string, or empty string.
      Author:
        Konrad Polthier
      Version:
        29.11.03, 1.10 revised (kp) Convert infinity to numbers.
        09.02.02, 1.00 created (kp)

    - #### toString

          public static java.lang.String toString(double[] data)

      Create single line string of double array where components are separated by blanks. Do not convert to float and use exponential form.
      Parameters:
        `data` - array of double number to be printed.
      Returns:
        single-line string, or empty string.
      Author:
        Konrad Polthier
      Version:
        09.02.02, 1.00 created (kp)

    - #### toString

          public static java.lang.String toString(float d)

      Converts a float to a string in non exponential form.

      If d is in the range `10^-3 <= |d| <=10^7`, then the result coincides with the result of Double.toString(double), i.e. the result is a string in the style [-]ddd.ddd.

      Otherwise, the result of Double.toString(double) is postprocessed to obtain a non-exponential form. There is always a minimum of one digit after the decimal point. The number of digits is the minimum needed to uniquely distinguish the argument value from adjacent values of type double.

      Parameters:
        `d` - the double
      Returns:
        the string representation of the double value
      Author:
        Konrad Polthier
      Version:
        09.02.02, 1.00 created (kp)

    - #### toString

          public static java.lang.String toString(float[] data,
                                                  boolean bExp)

      Create single line string of float array where components are separated by blanks.
      Parameters:
        `data` - array of float number to be printed.
        `bExp` - if false, then use non-exponential representation
      Returns:
        single-line string, or empty string.
      Author:
        Konrad Polthier
      Version:
        09.02.02, 1.00 created (kp)

    - #### toString

          public static java.lang.String toString(float[] data)

      Create single line string of float array where components are separated by blanks.
      Parameters:
        `data` - array of float number to be printed.
      Returns:
        single-line string, or empty string.
      Author:
        Konrad Polthier
      Version:
        09.02.02, 1.00 created (kp)

    - #### doubleToString

          public static java.lang.String doubleToString(double d,
                                                        int mantissa,
                                                        int width)

      Converts a double to a string with given number of mantissa digits in non exponential form. The length of the returned String can be specified. If the representation of the number is smaller, then the String will start with blanks.

      The passed number of mantissa digits must be greater or equal to one and the difference between mantissa and width must be greater or equal to three, otherwise `""` is returned.

      Parameters:
        `d` - the double
        `mantissa` - an int with the number of mantissa digits
        `width` - an int with the width of the returned string
      Returns:
        the string, or `""` if `mantissa<1` or `width-mantissa<3`.
      Author:
        Samy Khadem-Al-Charieh
      Version:
        08.11.00, 1.20 revised (kp) Method moved here from jv.loader.PgByuLoader.
        14.10.99, 1.00 created (sk)

    - #### doubleToString

          public static java.lang.String doubleToString(double d,
                                                        int mantissa)

      Converts a double to a String with given number of mantissa digits in exponential form '-d.dddddEdd' or ' d.dddddEdd'. The passed number of mantissa digits must be greater or equal to one, otherwise null is returned.
      Parameters:
        `d` - the double
        `mantissa` - an int with the number of digits behind the period
      Returns:
        the string, or `""` if `mantissa<1`.
      Author:
        Samy Khadem-Al-Charieh
      Version:
        08.11.00, 1.20 revised (kp) Method moved here from jv.loader.PgByuLoader.
        14.10.99, 1.00 created (sk)

    - #### toString

          public static java.lang.String toString(int[] data)

      Create single line string of integer array where components are separated by blanks.
      Parameters:
        `data` - array of integer number to be printed.
      Returns:
        single-line string, or null of argument==null or zero length.

    - #### timeToString

          public static java.lang.String timeToString(long time)

      Formats a given time (in ms) as String.
      Author:
        Matthias Nieser
      Version:
        05.03.15, 2.00 revised (kp) Move to jv.number.PuString from dev.number.
        28.04.09, 1.00 created (mn)

    - #### millisToString

          public static java.lang.String millisToString(long millis)

      Get a string representation of the time argument specified in milliseconds.
      Author:
        Felix Kaelberer
      Version:
        05.03.15, 2.00 revised (kp) Move to jv.number.PuString from dev.number.
        12.06.06, 1.00 created (fk).

    - #### shortCutString

          public static java.lang.String shortCutString(java.lang.String s,
                                                        int numChars)

      Abbreviates a given string to numChars characters.
      Parameters:
        `s` - given string.
        `numChars` - number of destination characters, must be `>= 6`.
      Returns:
        abbreviated string.
      Author:
        Matthias Nieser
      Version:
        05.03.15, 2.00 revised (kp) Move to jv.number.PuString from dev.number.
        12.02.08, 1.10 revised (mn) Moved to dev.
        xx.xx.xx, 1.00 created (mn)

"

The software JavaView? is copyright protected. All Rights Reserved.
"