Class StringHelper

java.lang.Object
net.simplace.core.service.StringHelper

public final class StringHelper extends Object
Static helper methods for string manipulation, parsing and formatting.
Author:
Andreas Enders
  • Constructor Details

    • StringHelper

      public StringHelper()
  • Method Details

    • arrayToList

      public static List<Object> arrayToList(Object[] aArray)
      Converts an array into an ArrayList.
      Parameters:
      aArray - the array to convert
      Returns:
      a new list with the elements of the array, or null if aArray is null
    • convertLineBreak

      public static String convertLineBreak(String aValue)
      Converts Windows line breaks (CR LF) to Unix line breaks (LF).
      Parameters:
      aValue - string to convert
      Returns:
      the converted string
    • convertEncoding

      public static String convertEncoding(String aContent, String aInputEncoding, String aOutputEncoding) throws UnsupportedEncodingException
      Re-interprets the bytes of a string in another encoding. The string is converted to bytes with the platform default charset and decoded with the input encoding, then again with the output encoding. This can repair strings that were decoded with the wrong charset. Input and/or output encoding can be left empty or null to skip that step.
      Parameters:
      aContent - string to convert
      aInputEncoding - charset for the first decoding step, or empty/null
      aOutputEncoding - charset for the second decoding step, or empty/null
      Returns:
      the converted string
      Throws:
      UnsupportedEncodingException - if a charset is not supported
    • containsAnyCharacter

      public static boolean containsAnyCharacter(String aStringToCheck, String aCharactersToLookFor)
      Checks whether any of the characters in aCharactersToLookFor occurs in aStringToCheck. Note that this method returns true if ANY single character in aCharactersToLookFor is contained in aStringToCheck.
      Parameters:
      aStringToCheck - string to be searched
      aCharactersToLookFor - string containing the characters to look for in aStringToCheck
      Returns:
      true if any of the characters is contained in aStringToCheck; false if either string is empty or null
    • extractDigitsFromString

      public static String extractDigitsFromString(String aString)
      Removes every character that is not a digit 0-9.
      Parameters:
      aString - string to filter
      Returns:
      the digits of the string, or null if aString is null or empty
    • filterLineFeed

      public static String filterLineFeed(String aString)
      Replaces line feed characters with spaces.
      Parameters:
      aString - string to convert
      Returns:
      the converted string, or null if aString is null
    • filterWhiteSpacesAndTabs

      public static String filterWhiteSpacesAndTabs(String aString)
      Replaces sequences of two or more white space characters (spaces, tabs, line breaks) with a single space.
      Parameters:
      aString - string to convert
      Returns:
      the converted string, or null if aString is null
    • getAfterDivider

      public static String getAfterDivider(String aString, String aDivider)
      Returns the part of a string after the last occurrence of a divider.
      Parameters:
      aString - string to split
      aDivider - divider to search for
      Returns:
      the part after the last divider, or the whole string if the divider does not occur
      See Also:
    • getAfterFirstDivider

      public static String getAfterFirstDivider(String aString, String aDivider)
      Returns the part of a string after the first occurrence of a divider.
      Parameters:
      aString - string to split
      aDivider - divider to search for
      Returns:
      the part after the first divider, or the whole string if the divider does not occur
    • getBeforeDivider

      public static String getBeforeDivider(String aString, String aDivider)
      Returns the part of a string before the first occurrence of a divider.
      Parameters:
      aString - string to split
      aDivider - divider to search for
      Returns:
      the part before the first divider, the whole string if the divider does not occur, or null if aString is null
    • getBeforeLastDivider

      public static String getBeforeLastDivider(String aString, String aDivider)
      Returns the part of a string before the last occurrence of a divider.
      Parameters:
      aString - string to split
      aDivider - divider to search for
      Returns:
      the part before the last divider, the whole string if the divider does not occur, or null if aString is null
    • getHead

      public static final String getHead(String aString, int aCount)
      Returns the first characters of a string. If the string is shorter, the whole string is returned.
      Parameters:
      aString - the string
      aCount - number of characters
      Returns:
      the first aCount characters of aString
    • replacePlaceholder

      public static final String replacePlaceholder(String aDocument, String aPlaceholder, String aValue)
      Replaces all occurrences of a placeholder (e.g. $Example$) in a text with a value. The placeholder is matched literally, not as regular expression.
      Parameters:
      aDocument - text containing the placeholder
      aPlaceholder - placeholder to replace
      aValue - replacement value; if null (e.g. an environment variable that is not set), the placeholder stays in the text
      Returns:
      the resulting text, or null if aDocument is null
    • replacePlaceholderAsBuffer

      public static final StringBuffer replacePlaceholderAsBuffer(String aDocument, String aPlaceholder, String aValue)
      Replaces all occurrences of a placeholder (e.g. $Example$) in a text with a value and returns the result as StringBuffer.
      Parameters:
      aDocument - text containing the placeholder
      aPlaceholder - placeholder to replace; must not be empty
      aValue - replacement value
      Returns:
      the resulting text, or null if aDocument is null
    • getInternationalisedString

      public static final String getInternationalisedString(String aInputString)
      Replaces German umlauts and sharp s by their ASCII transcriptions (e.g. ä → ae, ß → ss) and the Euro sign by EUR.
      Parameters:
      aInputString - string to convert
      Returns:
      the converted string, or null if aInputString is null
    • getListFromString

      public static LinkedList<String> getListFromString(String aString, String aDivider)
      Splits a string into a list of trimmed tokens. Empty tokens are kept.
      Parameters:
      aString - string to split
      aDivider - divider; a single character is matched literally, a longer divider is used as regular expression
      Returns:
      the tokens; empty if aString is null
      See Also:
    • getListFromString

      public static LinkedList<String> getListFromString(String aString, String aDivider, boolean doLeaveEmptyStringsOut, boolean doTrim)
      Splits a string into a list of tokens.
      Parameters:
      aString - string to split
      aDivider - divider; a single character is matched literally, a longer divider is used as regular expression
      doLeaveEmptyStringsOut - if true, empty tokens are skipped (after trimming, if doTrim is set)
      doTrim - if true, the tokens are trimmed
      Returns:
      the tokens; empty if aString is null or the divider is empty
    • getMapFromString

      public static Map<String,String> getMapFromString(String aString, String aMapDivider, String aValueDevider)
      Parses a string like {key1=value1, key2=value2} into a map. Surrounding curly braces are removed. Keys and values are not trimmed.
      Parameters:
      aString - string to parse
      aMapDivider - characters separating the entries (used as StringTokenizer delimiters)
      aValueDevider - divider between key and value; the key is the part before the first, the value the part after the last occurrence
      Returns:
      map in the order of the entries; empty if aString is null
    • getLong

      public static Long getLong(String aString)
      Extracts all digits of a string and parses them as long. If there are more than 18 digits, only the first 18 are used (so the value always fits into a long).
      Parameters:
      aString - string to parse
      Returns:
      the digits as long
      Throws:
      NumberFormatException - if the string contains no digits
    • getMatchesFromString

      public static ArrayList<String> getMatchesFromString(String aString, String aPattern)
      Returns all matches of a regular expression in a string.
      Parameters:
      aString - string to search in
      aPattern - regular expression
      Returns:
      the matched substrings; empty if aString is null
    • getNumberFormat

      public static final DecimalFormat getNumberFormat(String aNumberString, int aLenthOfStirng)
      Creates a DecimalFormat matching a number string, i.e. with the same number of decimal places and a total width of the given length. The number must use . as decimal separator.
      Parameters:
      aNumberString - example number, e.g. 12.345
      aLenthOfStirng - total length of the formatted number; used to set the number of # characters
      Returns:
      the number format, or null if aNumberString is null or not a number
    • getTail

      public static final String getTail(String aString, int aCount)
      Returns the last characters of a string. If the string is shorter, the whole string is returned.
      Parameters:
      aString - the string
      aCount - number of characters
      Returns:
      the last aCount characters of aString
    • getTimeString

      public static String getTimeString(Long aTime)
      Formats a point in time as localized date and time (medium style, UTC).
      Parameters:
      aTime - milliseconds since January 1 1970
      Returns:
      the formatted date and time
    • getTimeText

      public static String getTimeText(long aTime)
      Formats a duration as hh:mm:ss, e.g. 08:25:14.
      Parameters:
      aTime - duration in milliseconds
      Returns:
      the formatted duration
    • insertLineBreaks

      public static String insertLineBreaks(String aString, String aLineBreak, int aMaxLength, boolean aCountSpaces)
      Inserts line breaks into a string so that no line is longer than a maximum length. Existing line breaks reset the character count.
      Parameters:
      aString - the string in which the line breaks should be inserted
      aLineBreak - the line break string, e.g. <br> or \n
      aMaxLength - maximum number of characters per line
      aCountSpaces - if false, the character count is reset at each space, so only words longer than aMaxLength are broken
      Returns:
      the string with inserted line breaks
    • isEmpty

      public static boolean isEmpty(Object aValue)
      Checks whether a value is empty. A value counts as empty if it is null, a blank string, the string "null" or LocaleProvider.DEFAULT_EMPTY.
      Parameters:
      aValue - value to check
      Returns:
      true if the value is empty
    • isNumber

      public static boolean isNumber(String aString)
      Checks whether a string consists of digits only. An empty string counts as number.
      Parameters:
      aString - string to check
      Returns:
      true if the string contains only the digits 0-9
    • outputToString

      public static String outputToString(Map<String,?> aMap)
      Formats a map as text with one key : value line per entry (for logging). Entries with null key are skipped.
      Parameters:
      aMap - map to format
      Returns:
      the formatted text
    • pad

      public static String pad(int aStringLength, char aFiller, String aHead, String aTail)
      Builds a string of a given length from a head, filler characters and a tail. Example: pad(6, '0', null, "14") results in "000014".
      Parameters:
      aStringLength - the length of the result string
      aFiller - the character inserted between head and tail
      aHead - the start of the result string; null is treated as empty
      aTail - the end of the result string; null is treated as empty
      Returns:
      the padded string
      Throws:
      IllegalArgumentException - if head and tail together are longer than the requested length
    • parseBoolean

      public static boolean parseBoolean(Object aString)
      Converts a value to a boolean, using false as default.
      Parameters:
      aString - value to convert
      Returns:
      the boolean value, or false if it cannot be determined
      See Also:
    • parseDate

      public static LocalDateTime parseDate(Object aParameterFromMap, LocalDateTime aDefaultValue)
      Converts a value to a date. Supported are LocalDateTime, FWFormattedDate, java.sql.Date, Timestamp, FWSimVariable (its value is used) and strings with at least 6 characters in a format understood by FWFormattedDate.
      Parameters:
      aParameterFromMap - value to convert
      aDefaultValue - value returned if the value is null, of an unsupported type or cannot be parsed
      Returns:
      the date, or aDefaultValue
    • parseBoolean

      public static Boolean parseBoolean(Object aObject, boolean aDefaultValue)
      Converts a value to a boolean.
      • Integer: 1 → true, 0 → false, -1 → null
      • Boolean: returned as is
      • String (case insensitive): true/1/yes/oui/ja/wahr → true, false/0/no/non/nein/falsch → false, null → null
      Parameters:
      aObject - value to convert
      aDefaultValue - value returned for null, unsupported types and unknown values
      Returns:
      the boolean value, null (see above) or aDefaultValue
    • parseParameters

      public static List<String> parseParameters(String aInterceptorString, String aParameterDivider, String aBeginListDivider, String aEndListDivider)
      Extracts a parameter list from a string like name(a,b,c): takes the part between the begin and end divider and splits it.
      Parameters:
      aInterceptorString - string containing the parameter list
      aParameterDivider - divider between the parameters (regular expression)
      aBeginListDivider - divider before the list, e.g. (; the last occurrence is used
      aEndListDivider - divider after the list, e.g. ); the first occurrence after the begin divider is used
      Returns:
      the trimmed parameters
      See Also:
    • parseSeparatedListDouble

      public static ArrayList<Double> parseSeparatedListDouble(String aString, String aDivider)
      Splits a string and parses the elements as doubles. Empty elements are skipped.
      Parameters:
      aString - string to split
      aDivider - characters separating the elements (used as StringTokenizer delimiters)
      Returns:
      the parsed values; empty if aString is null
      Throws:
      NumberFormatException - if an element is not a number
    • removeCharacter

      public static String removeCharacter(String aString, char aChar)
      Removes all occurrences of a character from a string. The result is trimmed.
      Parameters:
      aString - string to filter
      aChar - character to remove
      Returns:
      the filtered string
    • containsSpecialCharacters

      public static boolean containsSpecialCharacters(String aStringToCheck)
      Searches the given string for special characters, i.e. characters other than 0-9 a-z A-Z - _.
      Parameters:
      aStringToCheck - string to be searched for special characters
      Returns:
      true if the string contains special characters; false if it is empty
    • containsProblematicCharacters

      public static boolean containsProblematicCharacters(String aStringToCheck)
      Searches the given string for problematic characters (without checking for HTML entities).
      Parameters:
      aStringToCheck - string to be searched
      Returns:
      true if the string contains problematic characters
      See Also:
    • containsProblematicCharacters

      public static boolean containsProblematicCharacters(String aStringToCheck, boolean aAlsoCheckForHTMLEntity)
      Searches the given string for any of the characters < > $ " ' \ # % and StringHelper.UNICODE.EURO.
      Parameters:
      aStringToCheck - string to be searched
      aAlsoCheckForHTMLEntity - if true, the HTML entities &lt; &gt; &quot; &euro; are checked for as well
      Returns:
      true if one of the characters is found; false for null
    • containsWebEuroSign

      public static boolean containsWebEuroSign(String aStringToCheck)
      Searches the given string for the Euro sign as it is transmitted via the browser, or its HTML entity.
      Parameters:
      aStringToCheck - string to be searched
      Returns:
      true if the string contains the Euro sign
      See Also:
    • containsWebEuroSign

      public static boolean containsWebEuroSign(String aStringToCheck, boolean aAlsoCheckForHTMLEntity)
      Searches the given string for the Euro sign as it is transmitted via the browser (FWFrameworkHelper.WEBEUROSIGN).
      Parameters:
      aStringToCheck - string to be searched
      aAlsoCheckForHTMLEntity - if true, the HTML entity &euro; is checked for as well
      Returns:
      true if the string contains the Euro sign; false for null
    • cutString

      public static String cutString(String aString, int aMaxLength)
      Shortens a string to a maximum length, replacing the end with ... if it is too long.
      Parameters:
      aString - string to shorten
      aMaxLength - maximum length including the dots; must be larger than 3
      Returns:
      the shortened string
    • findMatches

      public static Iterable<MatchResult> findMatches(String pattern, CharSequence s)
      Finds all matches of a regular expression in a character sequence.
      Parameters:
      pattern - regular expression
      s - character sequence to search in
      Returns:
      the match results in order of occurrence
    • replaceNullWithEmptyString

      public static String replaceNullWithEmptyString(String aString)
      Replaces null with an empty string.
      Parameters:
      aString - the string
      Returns:
      aString, or "" if it is null
    • parseSeparatedListString

      public static List<String> parseSeparatedListString(String aString, String aDivider)
      Splits a string into trimmed elements. Empty elements are kept.
      Parameters:
      aString - string to split
      aDivider - divider (used as regular expression)
      Returns:
      the elements; empty if aString is null
    • parseSeparatedListInteger

      public static ArrayList<Integer> parseSeparatedListInteger(String aString, String aDivider)
      Splits a string and parses the elements as integers. Empty elements are skipped.
      Parameters:
      aString - string to split
      aDivider - characters separating the elements (used as StringTokenizer delimiters)
      Returns:
      the parsed values; empty if aString is null
      Throws:
      NumberFormatException - if an element is not an integer
    • unParseParameters

      public static String unParseParameters(Collection<?> aElementCollection, String aParameterDivider)
      Joins the elements of a collection into a string. null elements become empty strings.
      Parameters:
      aElementCollection - elements to join
      aParameterDivider - divider inserted between the elements
      Returns:
      the joined string
    • replaceHTMLEntities

      public static String replaceHTMLEntities(String aHTML)
      Replaces German umlauts and sharp s by their HTML entities.
      Parameters:
      aHTML - text to convert
      Returns:
      the converted text
      See Also:
    • replaceHTMLEntities

      public static String replaceHTMLEntities(String aHTML, boolean aReplaceHTMLChars)
      Replaces German umlauts and sharp s by their HTML entities. Optionally, also HTML special characters and line breaks are converted.
      Parameters:
      aHTML - text to convert
      aReplaceHTMLChars - if true, & < > " and the Euro sign are replaced by entities and line breaks by <br>
      Returns:
      the converted text; null or empty input is returned unchanged
    • replaceAll

      public static String replaceAll(String aString, Map aSubstitutionMap)
      Replaces all occurrences of each key of a map by its value (literally, in map iteration order). Entries with empty key or null value are skipped.
      Parameters:
      aString - text to convert
      aSubstitutionMap - map from search string to replacement
      Returns:
      the resulting text; aString unchanged if it or the map is null
    • transformDataType

      public static Object transformDataType(String aString, FWSimVariable<?> aVariable)
      Converts a string to the data type of a simulation variable.
      Parameters:
      aString - string to convert
      aVariable - variable whose data type is used; its default value is used for unparsable dates
      Returns:
      the converted value (Boolean, LocalDateTime, Double, Integer or an array), or aString for character data
      Throws:
      NumberFormatException - if a numeric value cannot be parsed
    • toIntArray

      public static Integer[] toIntArray(String aString)
      Parses an array string like {1,2,3} or [1,2,3] into integers.
      Parameters:
      aString - array string
      Returns:
      the parsed values
      See Also:
    • toIntArray

      public static Integer[] toIntArray(String[] aArray)
      Parses split array elements as integers. With a single element, surrounding square brackets are removed. With several elements, a leading empty element (from an opening {) is skipped and square brackets are removed, so {1,2,3}, [1,2,3] (split at {,}) and plain elements give the same values. Empty elements become null; other unparsable elements are logged and left null.
      Parameters:
      aArray - array elements as strings, e.g. the result of splitting {1,2,3} at {,}
      Returns:
      the parsed values
    • toIntArray

      public static Integer[] toIntArray(int[] aArray)
      Converts a primitive int array into an Integer array.
      Parameters:
      aArray - array to convert
      Returns:
      the boxed values
    • toDoubleArray

      public static Double[] toDoubleArray(String aString)
      Parses an array string like {1.0,2.5,3} into doubles.
      Parameters:
      aString - array string
      Returns:
      the parsed values
      See Also:
    • toDateArray

      public static LocalDateTime[] toDateArray(String aValueText)
      Parses a comma separated list of dates, optionally enclosed in braces or square brackets, e.g. {01.01.2000,15.03.2000}; spaces around the dates are ignored, an empty list gives an empty array.
      Parameters:
      aValueText - comma separated dates in a format understood by FWFormattedDate
      Returns:
      the parsed dates
      See Also:
    • toDateArray

      public static LocalDateTime[] toDateArray(String[] aValueText)
      Parses an array of date strings. Unparsable dates are logged.
      Parameters:
      aValueText - dates in a format understood by FWFormattedDate
      Returns:
      the parsed dates
    • toDoubleMatrix

      public static Double[][] toDoubleMatrix(String aValueText)
      Parses a matrix string like {{1,2},{3,4}} into doubles. Rows are separated by } and { with any non-digit characters in between; values within a row by commas. Empty values become null.
      Parameters:
      aValueText - matrix string
      Returns:
      the parsed matrix; rows may have different lengths
    • toDoubleArray

      public static Double[] toDoubleArray(String[] aArray)
      Parses split array elements as doubles. With a single element, surrounding square brackets are removed. With several elements, a leading empty element (from an opening {) is skipped. Empty elements become null; other unparsable elements are logged and left null.
      Parameters:
      aArray - array elements as strings
      Returns:
      the parsed values, or null if aArray is empty
    • toDoubleArray

      public static Double[] toDoubleArray(int[] aArray)
      Converts a primitive int array into a Double array.
      Parameters:
      aArray - array to convert
      Returns:
      the converted values
    • toDoubleArray

      public static Double[] toDoubleArray(double[] aArray)
      Converts a primitive double array into a Double array.
      Parameters:
      aArray - array to convert
      Returns:
      the boxed values
    • toDoubleMatrix

      public static Double[][] toDoubleMatrix(String[][] aObject)
      Parses a matrix of strings row by row into doubles.
      Parameters:
      aObject - matrix of number strings
      Returns:
      the parsed matrix
      See Also:
    • toStringArray

      public static String[] toStringArray(String aString)
      Parses an array string like {a,b,c} into strings. The elements are trimmed and cleaned with returnValidString(String).
      Parameters:
      aString - array string
      Returns:
      the elements, or null if aString is null
    • returnValidString

      public static final String returnValidString(String aUncheckedString)
      Removes characters that may cause problems, e.g. in file names or array strings: [ ] < > ? " | ! ^ ; + ', carriage returns, line feeds and tabs. Backslashes are replaced by slashes and double spaces by single spaces.

      If you add or remove characters, also change IOHelper.isValidFilename/getInvalidFilenameCharacters.

      Parameters:
      aUncheckedString - string to clean
      Returns:
      the cleaned string
    • toStringForm

      public static String toStringForm(Double[] value)
      Formats an array as {v1,v2,...}.
      Parameters:
      value - array to format; must not be empty
      Returns:
      the formatted string
    • toStringForm

      public static String toStringForm(Double[][] matrix)
      Formats a matrix as {{v11,v12}{v21,v22}} (rows are not separated by commas).
      Parameters:
      matrix - matrix to format
      Returns:
      the formatted string
    • toStringForm

      public static String toStringForm(Integer[] value)
      Formats an array as {v1,v2,...}.
      Parameters:
      value - array to format; must not be empty
      Returns:
      the formatted string
    • toStringForm

      public static String toStringForm(String[] value)
      Formats an array as {v1,v2,...}. The values are not quoted or escaped.
      Parameters:
      value - array to format; must not be empty
      Returns:
      the formatted string
    • fullTrim

      public static String fullTrim(String aBeforePart)
      Removes all tabs and surrounding white space (see removeCharacter(String, char)).
      Parameters:
      aBeforePart - string to trim
      Returns:
      the trimmed string
    • splitBySize

      public static String[] splitBySize(String aStringToSplit, int i)
      Splits a string into chunks of a given size; the last chunk may be shorter.
      Parameters:
      aStringToSplit - string to split
      i - chunk size
      Returns:
      the chunks
    • parseIntegerPart

      public static Integer parseIntegerPart(String aLineString)
      Returns the first space separated word of a string that can be parsed as integer.
      Parameters:
      aLineString - string to search
      Returns:
      the first integer found, or null if there is none
    • parseFloatPart

      public static Float parseFloatPart(String aLineString)
      Returns the first space separated word of a string that can be parsed as float.
      Parameters:
      aLineString - string to search
      Returns:
      the first float found, or null if there is none
    • parseIntegerToArray

      public static Integer[] parseIntegerToArray(String aIndexString, boolean aConvertIndizes0To1)
      Parses an index list like 1,3,5-8,10- into a sorted set of indices. Supported elements are single numbers, ranges a-b, open ranges a- (up to 99999) and, as the only element, first (0) or last (99999).
      Parameters:
      aIndexString - comma separated index list
      aConvertIndizes0To1 - if true, the given indices are 1-based and are converted to 0-based by subtracting 1
      Returns:
      the sorted, distinct indices
    • fitString

      public static String fitString(String aUserName, int aLength)
      Brings a string to a fixed length: longer strings are shortened with ..., shorter strings are padded with spaces. null is formatted as "null".
      Parameters:
      aUserName - string to fit
      aLength - target length; must be larger than 3
      Returns:
      the fitted string
    • round

      public static double round(double aValue, int aPlaces)
      Rounds a double to a number of decimal places (half up).
      Parameters:
      aValue - value to round
      aPlaces - number of decimal places
      Returns:
      the rounded value
      Throws:
      IllegalArgumentException - if aPlaces is negative
    • arrayToString

      public static <T> String arrayToString(T[][] aSumOfCutValues, String aSeperator) throws IOException
      Formats a matrix as text: values separated by the separator, each row ending with CR LF.
      Type Parameters:
      T - element type
      Parameters:
      aSumOfCutValues - matrix to format
      aSeperator - separator between the values; should be a single character, as the last one of each row is replaced by the line break
      Returns:
      the formatted text
      Throws:
      IOException - declared but never thrown
    • arrayToString

      public static String arrayToString(String[] aSplit, String aSeparator)
      Joins the elements of an array with a separator.
      Parameters:
      aSplit - elements to join; must not be empty
      aSeparator - separator inserted between the elements
      Returns:
      the joined string
    • convertStringToLines

      public static Vector<String> convertStringToLines(String aString, Integer[] aLinesToRead)
      Splits a text into trimmed lines. CR LF, LF and CR line breaks are recognised. The lines are selected like IOHelper.readLinesOfStream(java.io.InputStream, Integer[], String) does for files: the first line (header) is always returned, followed by the selected data lines.
      Parameters:
      aString - text to split
      aLinesToRead - indices of the data lines to return after the header (the first data line has index 1), or null for all lines
      Returns:
      the trimmed lines
    • convertLinesToStringarray

      public static String[][] convertLinesToStringarray(Vector<String> aLinesVector, String aDivider)
      Splits lines into columns. Double quotes are removed and the values are trimmed. The number of columns is taken from the first line; surplus columns in later lines are logged.
      Parameters:
      aLinesVector - lines to split
      aDivider - column divider (used as regular expression)
      Returns:
      the values as rows and columns, or null if there are no lines
    • logFormat

      public static String logFormat(String aContent, int aStringMaxLength)
      Prepares a text for a single log line: shortens it and replaces line breaks with following white space by a single space.
      Parameters:
      aContent - text to format; null is formatted as NULL
      aStringMaxLength - maximum length; must be larger than 3
      Returns:
      the formatted text
    • convertFromString

      public static <T> T convertFromString(String aValue, Class<? extends T> aType)
      Converts a string into an instance of a base type (string, character, number or boolean, also the primitive types).
      Type Parameters:
      T - the destination type
      Parameters:
      aValue - the string
      aType - the destination type
      Returns:
      the converted value; the string itself for String; null if the type is no base type or (for all types except String) the string is null or empty
      Throws:
      NumberFormatException - if the string is not a valid number of the destination type
    • replaceTabulators

      public static String replaceTabulators(String aString, int aTabLength)
      Replaces tabulators by spaces, so that the following text starts at the next tab stop.
      Parameters:
      aString - the string
      aTabLength - distance of the tab stops
      Returns:
      the string without tabulators