Class StringHelper

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

public final class StringHelper extends Object
Author:
Andreas Enders
  • Constructor Details

    • StringHelper

      public StringHelper()
  • Method Details

    • arrayToList

      public static List<Object> arrayToList(Object[] aArray)
      Turns an array into a (Array-)list.
      Parameters:
      aArray -
      Returns:
      a (Array-)list
    • convertLineBreak

      public static String convertLineBreak(String aValue)
      Replaces the extensive line break with the simple one.
      Parameters:
      aValue -
      Returns:
      converted String
    • convertEncoding

      public static String convertEncoding(String aContent, String aInputEncoding, String aOutputEncoding) throws UnsupportedEncodingException
      Gets String with one encoding and returns one with another encoding. Input and/or OutputEncoding can be left empty or null for no changes.
      Parameters:
      aContent -
      aInputEncoding -
      aOutputEncoding -
      Returns:
      String with another encoding
      Throws:
      UnsupportedEncodingException
    • containsAnyCharacter

      public static boolean containsAnyCharacter(String aStringToCheck, String aCharactersToLookFor)
      Checks, whether any of the characters in aCharactersContained occurs in aStringToCheck. Note that this method returns true, if ANY single character in aCharactersContained 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 in aCharactersContained is contained in aStringToCheck
    • extractDigitsFromString

      public static String extractDigitsFromString(String aString)
      discards every non digit from the passed string
      Parameters:
      aString -
      Returns:
      NULL on error
    • filterLineFeed

      public static String filterLineFeed(String aString)
      Replaces line feed characters with whitespaces.
      Parameters:
      aString -
      Returns:
      converted String
    • filterWhiteSpacesAndTabs

      public static String filterWhiteSpacesAndTabs(String aString)
      Replaces several white spaces characters with one.
      Parameters:
      aString -
      Returns:
      converted String
    • getAfterDivider

      public static String getAfterDivider(String aString, String aDivider)
      Returns the part of aString after aDivider.
      Parameters:
      aString -
      aDivider -
      Returns:
      the part of aString after aDivider
    • getAfterFirstDivider

      public static String getAfterFirstDivider(String aString, String aDivider)
      Returns the part of aString after aDivider.
      Parameters:
      aString -
      aDivider -
      Returns:
      the part of aString after aDivider
    • getBeforeDivider

      public static String getBeforeDivider(String aString, String aDivider)
      Returns the part of aString before aDivider.
      Parameters:
      aString -
      aDivider -
      Returns:
      value before divider
    • getBeforeLastDivider

      public static String getBeforeLastDivider(String aString, String aDivider)
      Returns the part of aString before the last Divider.
      Parameters:
      aString -
      aDivider -
      Returns:
      the part of aString before the last Divider
    • getHead

      public static final String getHead(String aString, int aCount)
      Returns a string containing the first aCharCount characters of aString. if the string is smaller the whole string is returned.
      Parameters:
      aString -
      aCount -
      Returns:
      a string containing the first aCharCount characters of aString
    • replacePlaceholder

      public static final String replacePlaceholder(String aDocument, String aPlaceholder, String aValue)
      Replaces a String ($Example$) in a document by taking the Value.
      Parameters:
      aDocument -
      aPlaceholder -
      aValue -
      Returns:
      converted String
    • replacePlaceholderAsBuffer

      public static final StringBuffer replacePlaceholderAsBuffer(String aDocument, String aPlaceholder, String aValue)
      Replaces a StringBuffer ($Example$) in a document by taking the Value.
      Parameters:
      aDocument -
      aPlaceholder -
      aValue -
      Returns:
      StringBuffer
    • getInternationalisedString

      public static final String getInternationalisedString(String aInputString)
      Replaces a old value with a new value in the given String
      Parameters:
      aInputString -
      Returns:
      converted String
    • getLabelText

      public static String getLabelText(String aText)
      Value of the label.
      Parameters:
      aText -
      Returns:
      Value of the label
    • getLabelText

      public static String getLabelText(String aText, boolean aAlwaysHTML)
      Returning a formated value for a label or tooltiptext, replacing all linebreaks and special chars.
      Parameters:
      aText -
      aAlwaysHTML -
      Returns:
      a formated value for a label or tooltiptext
    • getLabelText

      public static String getLabelText(String aText, Font aFont, String aAdditionalStyle, boolean aAlwaysHTML)
      Returning a formated value for a label or tooltiptext, replacing all linebreaks and special chars.
      Parameters:
      aText -
      aFont -
      aAdditionalStyle -
      aAlwaysHTML -
      Returns:
      a formated value for a label or tooltiptext
    • getListFromString

      public static LinkedList<String> getListFromString(String aString, String aDivider)
      Parameters:
      aString -
      aDivider -
      Returns:
      List formed from String
    • getListFromString

      public static LinkedList<String> getListFromString(String aString, String aDivider, boolean doLeaveEmptyStringsOut, boolean doTrim)
      Parameters:
      aString -
      aDivider -
      doLeaveEmptyStringsOut -
      doTrim -
      Returns:
      List formed from String
    • getMapFromString

      public static Map<String,String> getMapFromString(String aString, String aMapDivider, String aValueDevider)
      Parameters:
      aString -
      aMapDivider -
      aValueDevider -
      Returns:
      Map formed from String
    • getLong

      public static Long getLong(String aString)
      Returns the part of aString that is made of numbers.
      Parameters:
      aString -
      Returns:
      the part of aString that is made of numbers
    • getMatchesFromString

      public static ArrayList<String> getMatchesFromString(String aString, String aPattern)
      Parameters:
      aString -
      aPattern -
      aTargetDir -
      Returns:
      List of matches from String
    • getNumberFormat

      public static final DecimalFormat getNumberFormat(String aNumberString, int aLenthOfStirng)
      getting number format from a given String. returning null if value is no number. pls make sure that . is used for separator of values. length is used for setting the right number of ### Strings
      Parameters:
      aNumberString -
      aLenthOfStirng -
      Returns:
      number format from a given String
    • getTail

      public static final String getTail(String aString, int aCount)
      Returns a string containing the first aCharCount characters of aString. if the string is smaller the whole string is returned.
      Parameters:
      aString -
      aCount -
      Returns:
      the tail of the string
    • getTimeString

      public static String getTimeString(Long aTime)
      Returns the time in string format.
      Parameters:
      aTime -
      Returns:
      a string containing the first aCharCount characters of aString
    • getTimeText

      public static String getTimeText(long aTime)
      Returns a text for the given time. (08:25:14)
      Parameters:
      aTime -
      Returns:
      a text for the given time
    • insertLineBreaks

      public static String insertLineBreaks(String aString, String aLineBreak, int aMaxLength, boolean aCountSpaces)
      Parameters:
      aString - - the String in which the line breaks should be inserted
      aLineBreak - - a String that contains the LineBreak-characters like "
      " or "\n"
      aMaxLength - - the count of characters of each line
      aCountSpaces - - false = reset the character count on each empty space
      Returns:
      String with inserted line breaks
    • isEmpty

      public static boolean isEmpty(Object aValue)
      Parameters:
      aValue -
      aIconID -
      Returns:
      true, if String is null or ""
    • isNumber

      public static boolean isNumber(String aString)
      Returns the part of aString that is made of numbers.
      Parameters:
      aString -
      Returns:
      the part of aString that is made of numbers
    • outputToString

      public static String outputToString(Map<String,?> aMap)
      Returns a formatted String form the given Map.
      Parameters:
      aMap -
      Returns:
      a formatted String form the given Map
    • pad

      public static String pad(int aStringLength, char aFiller, String aHead, String aTail)
      This method fills a given string with a specified char until the specified length is achieved. Example: pad(6, '0', null, "14") will result in the result string: "000014"
      Parameters:
      aStringLength - The length of the result string that has to be padded.
      aFiller - The character with which the string should be filled.
      aHead - A string representing the head of the result string. The filling character is filled after the head. If null, the head is ignored.
      aTail - A string representing the tail of the result string. The filling character is filled after the tail. If null, the tail is ignored.
      Returns:
      converted String
      Throws:
      IllegalArgumentException - if the sum of lengths of the given strings is longer than the requested result string.
    • parseBoolean

      public static boolean parseBoolean(Object aString)
      Tries to figure out the boolean value of the given String or returns false if it can't.
      Parameters:
      aString -
      Returns:
      success
    • parseDate

      public static LocalDateTime parseDate(Object aParameterFromMap, LocalDateTime aDefaultValue)
      Tries to figure out the date value of the given String or returns a default value if it can't.
      Parameters:
      aParameterFromMap -
      aDefaultValue -
      Returns:
      the date value of the given String or a default value
    • parseBoolean

      public static Boolean parseBoolean(Object aObject, boolean aDefaultValue)
      Tries to figure out the boolean value of the given String or returns a default value if it can't.
      Parameters:
      aObject -
      aDefaultValue -
      Returns:
      the boolean value of the given String or returns a default value
    • parseParameters

      public static List<String> parseParameters(String aInterceptorString, String aParameterDivider, String aBeginListDivider, String aEndListDivider)
      Parses the parameter given in a string an returns a list of them.
      Parameters:
      aInterceptorString -
      aParameterDivider -
      aBeginListDivider -
      aEndListDivider -
      Returns:
      List of parameters
    • parseSeparatedListDouble

      public static ArrayList<Double> parseSeparatedListDouble(String aString, String aDivider)
      Returns a list with the elements that are divided by divider in a String.
      Parameters:
      aString -
      aDivider -
      Returns:
      a list with the elements that are divided by divider in a String
    • removeCharacter

      public static String removeCharacter(String aString, char aChar)
      Replaces line feed characters with whitespaces.
      Parameters:
      aString -
      aChar -
      Returns:
      converted String
    • containsSpecialCharacters

      public static boolean containsSpecialCharacters(String aStringToCheck)
      Searches the given String for special characters. Returns true, if other characters than 0-9 a-z A-Z - _ are found in the string.
      Parameters:
      aStringToCheck - - String to be searched for special characters
      Returns:
      true, if the string contains special characters
    • containsProblematicCharacters

      public static boolean containsProblematicCharacters(String aStringToCheck)
      Parameters:
      aStringToCheck -
      Returns:
      true if a given String contains problematic characters
    • containsProblematicCharacters

      public static boolean containsProblematicCharacters(String aStringToCheck, boolean aAlsoCheckForHTMLEntity)
      Searches the given String for any of the special characters < > $ " ' \ # % Returns true, if one of these is found.
      Parameters:
      aStringToCheck - - String to be searched for special characters
      aAlsoCheckForHTMLEntity - - If true, HTML-Entities are checked for also, e. g. < for <
      Returns:
      true, if the string contains special characters
    • containsWebEuroSign

      public static boolean containsWebEuroSign(String aStringToCheck)
      Searches the given String for the EURO sign as it is transmitted via the browser. Returns true, if it is found.
      Parameters:
      aStringToCheck - - String to be searched for special characters
      Returns:
      true, if the string contains the euro sign
    • containsWebEuroSign

      public static boolean containsWebEuroSign(String aStringToCheck, boolean aAlsoCheckForHTMLEntity)
      Searches the given String for the EURO sign as it is transmitted via the browser. Returns true, if it is found.
      Parameters:
      aStringToCheck - - String to be searched for special characters
      aAlsoCheckForHTMLEntity -
      Returns:
      true, if the string contains the euro sign
    • cutString

      public static String cutString(String aString, int aMaxLength)
      Cuts the tail of the given string if it exceeds a given length (minimum 3).
      Parameters:
      aString -
      aMaxLength -
      Returns:
      converted String
    • findMatches

      public static Iterable<MatchResult> findMatches(String pattern, CharSequence s)
      Parameters:
      pattern -
      s -
      Returns:
      Iterable
    • replaceNullWithEmptyString

      public static String replaceNullWithEmptyString(String aString)
      replaces Null with empty String.
      Parameters:
      aString -
      Returns:
      empty String
    • parseSeparatedListString

      public static List<String> parseSeparatedListString(String aString, String aDivider)
      Returns a list with the elements that are divided by divider in a String.
      Parameters:
      aString -
      aDivider -
      Returns:
      a List of Strings
    • parseSeparatedListInteger

      public static ArrayList<Integer> parseSeparatedListInteger(String aString, String aDivider)
      Returns a list with the elements that are divided by divider in a String.
      Parameters:
      aString -
      aDivider -
      Returns:
      a list with the elements that are divided by divider in a String
    • unParseParameters

      public static String unParseParameters(Collection<?> aElementCollection, String aParameterDivider)
      Parses the parameter given in a string an returns a list of them.
      Parameters:
      aElementCollection -
      aParameterDivider -
      Returns:
      list of parameters
    • replaceHTMLEntities

      public static String replaceHTMLEntities(String aHTML)
      Changes the given code to html.
      Parameters:
      aHTML -
      Returns:
      converted String
    • replaceHTMLEntities

      public static String replaceHTMLEntities(String aHTML, boolean aReplaceHTMLChars)
      Changes the given code to html.
      Parameters:
      aHTML -
      aReplaceHTMLChars -
      Returns:
      converted String
    • replaceAll

      public static String replaceAll(String aString, Map aSubstitutionMap)
      Replaces all entries from the map.
      Parameters:
      aString -
      aSubstitutionMap -
      Returns:
      resulting String
    • transformDataType

      public static Object transformDataType(String aString, FWSimVariable<?> aVariable)
      Parameters:
      aString -
      aVariable -
      Returns:
      Object
    • toIntArray

      public static Integer[] toIntArray(String aString)
      Parameters:
      aString -
      Returns:
      Array of Integers
    • toIntArray

      public static Integer[] toIntArray(String[] aArray)
      Parameters:
      aArray -
      Returns:
      Array of Integers
    • toIntArray

      public static Integer[] toIntArray(int[] aArray)
      Parameters:
      aArray -
      Returns:
      Array of Integers
    • toDoubleArray

      public static Double[] toDoubleArray(String aString)
      Parameters:
      aString -
      Returns:
      Array of Doubles
    • toDateArray

      public static LocalDateTime[] toDateArray(String aValueText)
      Parameters:
      aValueText -
      Returns:
    • toDateArray

      public static LocalDateTime[] toDateArray(String[] aValueText)
      Parameters:
      aValueText -
      Returns:
    • toDoubleMatrix

      public static Double[][] toDoubleMatrix(String aValueText)
      Parameters:
      aValueText -
      Returns:
    • toDoubleArray

      public static Double[] toDoubleArray(String[] aArray)
      Parameters:
      aArray -
      Returns:
      Array of Doubles
    • toDoubleArray

      public static Double[] toDoubleArray(int[] aArray)
      Parameters:
      aArray -
      Returns:
      Array of Doubles
    • toDoubleArray

      public static Double[] toDoubleArray(double[] aArray)
      Parameters:
      aArray -
      Returns:
      Array of Doubles
    • toDoubleMatrix

      public static Double[][] toDoubleMatrix(String[][] aObject)
      Parameters:
      aObject -
      Returns:
    • toStringArray

      public static String[] toStringArray(String aString)
      Parameters:
      aString -
      Returns:
      Array of Strings
    • returnValidString

      public static final String returnValidString(String aUncheckedString)
      Replaces all letters that are maybe not supported by system for using in filename. You should only give the filename without path!!! If add/remove characters also change isValidFilename/getInvalidFilenameCharacters
      Parameters:
      aUncheckedString -
      Returns:
      valid file name
    • toStringForm

      public static String toStringForm(Double[] value)
      Parameters:
      value -
      Returns:
      String
    • toStringForm

      public static String toStringForm(Double[][] matrix)
      Parameters:
      matrix -
      Returns:
      String
    • toStringForm

      public static String toStringForm(Integer[] value)
      Parameters:
      value -
      Returns:
      String
    • toStringForm

      public static String toStringForm(String[] value)
      Parameters:
      value -
      Returns:
      String
    • fullTrim

      public static String fullTrim(String aBeforePart)
      Parameters:
      aBeforePart -
      Returns:
      the full trimmed String
    • splitBySize

      public static String[] splitBySize(String aStringToSplit, int i)
      Parameters:
      aStringToSplit -
      i -
      Returns:
      String, split by size
    • parseIntegerPart

      public static Integer parseIntegerPart(String aLineString)
      Parameters:
      aLineString -
      Returns:
      Integer part of a given String
    • parseFloatPart

      public static Float parseFloatPart(String aLineString)
      Parameters:
      aLineString -
      Returns:
      Float part of a given String
    • parseIntegerToArray

      public static Integer[] parseIntegerToArray(String aIndexString, boolean aConvertIndizes0To1)
      Parameters:
      aIndexString -
      aConvertIndizes0To1 -
      Returns:
      Array of Integers
    • fitString

      public static String fitString(String aUserName, int aLength)
      Fits the length of a String with spaces to the given length
      Parameters:
      aUserName -
      aLength -
      Returns:
      the fitted String
    • round

      public static double round(double aValue, int aPlaces)
      round the double to a "halfUp" value
      Parameters:
      aValue -
      aPlaces -
      Returns:
      the rounded double
    • arrayToString

      public static <T> String arrayToString(T[][] aSumOfCutValues, String aSeperator) throws IOException
      Type Parameters:
      T -
      Parameters:
      aSumOfCutValues -
      aFile -
      aSeperator -
      Throws:
      IOException
    • arrayToString

      public static String arrayToString(String[] aSplit, String aSeparator)
      Parameters:
      aSplit -
      aSeparator -
      Returns:
    • convertStringToLines

      public static Vector<String> convertStringToLines(String aString, Integer[] aLinesToRead)
    • convertLinesToStringarray

      public static String[][] convertLinesToStringarray(Vector<String> aLinesVector, String aDivider)
    • logFormat

      public static String logFormat(String aContent, int aStringMaxLength)