Package net.simplace.core.service
Class StringHelper
java.lang.Object
net.simplace.core.service.StringHelper
- Author:
- Andreas Enders
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionarrayToList
(Object[] aArray) Turns an array into a (Array-)list.static String
arrayToString
(String[] aSplit, String aSeparator) static <T> String
arrayToString
(T[][] aSumOfCutValues, String aSeperator) static boolean
containsAnyCharacter
(String aStringToCheck, String aCharactersToLookFor) Checks, whether any of the characters in aCharactersContained occurs in aStringToCheck.static boolean
containsProblematicCharacters
(String aStringToCheck) 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.static boolean
containsSpecialCharacters
(String aStringToCheck) Searches the given String for special characters.static boolean
containsWebEuroSign
(String aStringToCheck) Searches the given String for the EURO sign as it is transmitted via the browser.static boolean
containsWebEuroSign
(String aStringToCheck, boolean aAlsoCheckForHTMLEntity) Searches the given String for the EURO sign as it is transmitted via the browser.static String
convertEncoding
(String aContent, String aInputEncoding, String aOutputEncoding) Gets String with one encoding and returns one with another encoding.static String
convertLineBreak
(String aValue) Replaces the extensive line break with the simple one.static String[][]
convertLinesToStringarray
(Vector<String> aLinesVector, String aDivider) convertStringToLines
(String aString, Integer[] aLinesToRead) static String
Cuts the tail of the given string if it exceeds a given length (minimum 3).static String
extractDigitsFromString
(String aString) discards every non digit from the passed stringstatic String
filterLineFeed
(String aString) Replaces line feed characters with whitespaces.static String
filterWhiteSpacesAndTabs
(String aString) Replaces several white spaces characters with one.static Iterable<MatchResult>
findMatches
(String pattern, CharSequence s) static String
Fits the length of a String with spaces to the given lengthstatic String
static String
getAfterDivider
(String aString, String aDivider) Returns the part of aString after aDivider.static String
getAfterFirstDivider
(String aString, String aDivider) Returns the part of aString after aDivider.static String
getBeforeDivider
(String aString, String aDivider) Returns the part of aString before aDivider.static String
getBeforeLastDivider
(String aString, String aDivider) Returns the part of aString before the last Divider.static final String
Returns a string containing the first aCharCount characters of aString.static final String
getInternationalisedString
(String aInputString) Replaces a old value with a new value in the given Stringstatic String
getLabelText
(String aText) Value of the label.static String
getLabelText
(String aText, boolean aAlwaysHTML) Returning a formated value for a label or tooltiptext, replacing all linebreaks and special chars.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.static LinkedList<String>
getListFromString
(String aString, String aDivider) static LinkedList<String>
getListFromString
(String aString, String aDivider, boolean doLeaveEmptyStringsOut, boolean doTrim) static Long
Returns the part of aString that is made of numbers.getMapFromString
(String aString, String aMapDivider, String aValueDevider) getMatchesFromString
(String aString, String aPattern) 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.static final String
Returns a string containing the first aCharCount characters of aString.static String
getTimeString
(Long aTime) Returns the time in string format.static String
getTimeText
(long aTime) Returns a text for the given time. (08:25:14)static String
insertLineBreaks
(String aString, String aLineBreak, int aMaxLength, boolean aCountSpaces) static boolean
static boolean
Returns the part of aString that is made of numbers.static String
static String
outputToString
(Map<String, ?> aMap) Returns a formatted String form the given Map.static String
This method fills a given string with a specified char until the specified length is achieved.static boolean
parseBoolean
(Object aString) Tries to figure out the boolean value of the given String or returns false if it can't.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.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.static Float
parseFloatPart
(String aLineString) static Integer
parseIntegerPart
(String aLineString) static Integer[]
parseIntegerToArray
(String aIndexString, boolean aConvertIndizes0To1) parseParameters
(String aInterceptorString, String aParameterDivider, String aBeginListDivider, String aEndListDivider) Parses the parameter given in a string an returns a list of them.parseSeparatedListDouble
(String aString, String aDivider) Returns a list with the elements that are divided by divider in a String.parseSeparatedListInteger
(String aString, String aDivider) Returns a list with the elements that are divided by divider in a String.parseSeparatedListString
(String aString, String aDivider) Returns a list with the elements that are divided by divider in a String.static String
removeCharacter
(String aString, char aChar) Replaces line feed characters with whitespaces.static String
replaceAll
(String aString, Map aSubstitutionMap) Replaces all entries from the map.static String
replaceHTMLEntities
(String aHTML) Changes the given code to html.static String
replaceHTMLEntities
(String aHTML, boolean aReplaceHTMLChars) Changes the given code to html.static String
replaceNullWithEmptyString
(String aString) replaces Null with empty String.static final String
replacePlaceholder
(String aDocument, String aPlaceholder, String aValue) Replaces a String ($Example$) in a document by taking the Value.static final StringBuffer
replacePlaceholderAsBuffer
(String aDocument, String aPlaceholder, String aValue) Replaces a StringBuffer ($Example$) in a document by taking the Value.static final String
returnValidString
(String aUncheckedString) Replaces all letters that are maybe not supported by system for using in filename.static double
round
(double aValue, int aPlaces) round the double to a "halfUp" valuestatic String[]
splitBySize
(String aStringToSplit, int i) static LocalDateTime[]
toDateArray
(String aValueText) static LocalDateTime[]
toDateArray
(String[] aValueText) static Double[]
toDoubleArray
(double[] aArray) static Double[]
toDoubleArray
(int[] aArray) static Double[]
toDoubleArray
(String aString) static Double[]
toDoubleArray
(String[] aArray) static Double[][]
toDoubleMatrix
(String aValueText) static Double[][]
toDoubleMatrix
(String[][] aObject) static Integer[]
toIntArray
(int[] aArray) static Integer[]
toIntArray
(String aString) static Integer[]
toIntArray
(String[] aArray) static String[]
toStringArray
(String aString) static String
toStringForm
(Double[] value) static String
toStringForm
(Double[][] matrix) static String
toStringForm
(Integer[] value) static String
toStringForm
(String[] value) static Object
transformDataType
(String aString, FWSimVariable<?> aVariable) static String
unParseParameters
(Collection<?> aElementCollection, String aParameterDivider) Parses the parameter given in a string an returns a list of them.
-
Constructor Details
-
StringHelper
public StringHelper()
-
-
Method Details
-
arrayToList
Turns an array into a (Array-)list.- Parameters:
aArray
-- Returns:
- a (Array-)list
-
convertLineBreak
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
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 searchedaCharactersToLookFor
- - String containing the characters to look for in aStringToCheck- Returns:
- true, if any of the characters in aCharactersContained is contained in aStringToCheck
-
extractDigitsFromString
discards every non digit from the passed string- Parameters:
aString
-- Returns:
- NULL on error
-
filterLineFeed
Replaces line feed characters with whitespaces.- Parameters:
aString
-- Returns:
- converted String
-
filterWhiteSpacesAndTabs
Replaces several white spaces characters with one.- Parameters:
aString
-- Returns:
- converted String
-
getAfterDivider
Returns the part of aString after aDivider.- Parameters:
aString
-aDivider
-- Returns:
- the part of aString after aDivider
-
getAfterFirstDivider
Returns the part of aString after aDivider.- Parameters:
aString
-aDivider
-- Returns:
- the part of aString after aDivider
-
getBeforeDivider
Returns the part of aString before aDivider.- Parameters:
aString
-aDivider
-- Returns:
- value before divider
-
getBeforeLastDivider
Returns the part of aString before the last Divider.- Parameters:
aString
-aDivider
-- Returns:
- the part of aString before the last Divider
-
getHead
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
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
Replaces a old value with a new value in the given String- Parameters:
aInputString
-- Returns:
- converted String
-
getLabelText
Value of the label.- Parameters:
aText
-- Returns:
- Value of the label
-
getLabelText
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
- 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
Returns the part of aString that is made of numbers.- Parameters:
aString
-- Returns:
- the part of aString that is made of numbers
-
getMatchesFromString
- Parameters:
aString
-aPattern
-aTargetDir
-- Returns:
- List of matches from String
-
getNumberFormat
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
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
Returns the time in string format.- Parameters:
aTime
-- Returns:
- a string containing the first aCharCount characters of aString
-
getTimeText
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 insertedaLineBreak
- - a String that contains the LineBreak-characters like "
" or "\n"aMaxLength
- - the count of characters of each lineaCountSpaces
- - false = reset the character count on each empty space- Returns:
- String with inserted line breaks
-
isEmpty
- Parameters:
aValue
-aIconID
-- Returns:
- true, if String is null or ""
-
isNumber
Returns the part of aString that is made of numbers.- Parameters:
aString
-- Returns:
- the part of aString that is made of numbers
-
outputToString
Returns a formatted String form the given Map.- Parameters:
aMap
-- Returns:
- a formatted String form the given Map
-
pad
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
Tries to figure out the boolean value of the given String or returns false if it can't.- Parameters:
aString
-- Returns:
- success
-
parseDate
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
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
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
Replaces line feed characters with whitespaces.- Parameters:
aString
-aChar
-- Returns:
- converted String
-
containsSpecialCharacters
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
- 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 charactersaAlsoCheckForHTMLEntity
- - If true, HTML-Entities are checked for also, e. g. < for <- Returns:
- true, if the string contains special characters
-
containsWebEuroSign
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
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 charactersaAlsoCheckForHTMLEntity
-- Returns:
- true, if the string contains the euro sign
-
cutString
Cuts the tail of the given string if it exceeds a given length (minimum 3).- Parameters:
aString
-aMaxLength
-- Returns:
- converted String
-
findMatches
- Parameters:
pattern
-s
-- Returns:
- Iterable
-
replaceNullWithEmptyString
replaces Null with empty String.- Parameters:
aString
-- Returns:
- empty String
-
parseSeparatedListString
Returns a list with the elements that are divided by divider in a String.- Parameters:
aString
-aDivider
-- Returns:
- a List of Strings
-
parseSeparatedListInteger
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
Parses the parameter given in a string an returns a list of them.- Parameters:
aElementCollection
-aParameterDivider
-- Returns:
- list of parameters
-
replaceHTMLEntities
Changes the given code to html.- Parameters:
aHTML
-- Returns:
- converted String
-
replaceHTMLEntities
Changes the given code to html.- Parameters:
aHTML
-aReplaceHTMLChars
-- Returns:
- converted String
-
replaceAll
Replaces all entries from the map.- Parameters:
aString
-aSubstitutionMap
-- Returns:
- resulting String
-
transformDataType
- Parameters:
aString
-aVariable
-- Returns:
- Object
-
toIntArray
- Parameters:
aString
-- Returns:
- Array of Integers
-
toIntArray
- Parameters:
aArray
-- Returns:
- Array of Integers
-
toIntArray
- Parameters:
aArray
-- Returns:
- Array of Integers
-
toDoubleArray
- Parameters:
aString
-- Returns:
- Array of Doubles
-
toDateArray
- Parameters:
aValueText
-- Returns:
-
toDateArray
- Parameters:
aValueText
-- Returns:
-
toDoubleMatrix
- Parameters:
aValueText
-- Returns:
-
toDoubleArray
- Parameters:
aArray
-- Returns:
- Array of Doubles
-
toDoubleArray
- Parameters:
aArray
-- Returns:
- Array of Doubles
-
toDoubleArray
- Parameters:
aArray
-- Returns:
- Array of Doubles
-
toDoubleMatrix
- Parameters:
aObject
-- Returns:
-
toStringArray
- Parameters:
aString
-- Returns:
- Array of Strings
-
returnValidString
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
- Parameters:
value
-- Returns:
- String
-
toStringForm
- Parameters:
matrix
-- Returns:
- String
-
toStringForm
- Parameters:
value
-- Returns:
- String
-
toStringForm
- Parameters:
value
-- Returns:
- String
-
fullTrim
- Parameters:
aBeforePart
-- Returns:
- the full trimmed String
-
splitBySize
- Parameters:
aStringToSplit
-i
-- Returns:
- String, split by size
-
parseIntegerPart
- Parameters:
aLineString
-- Returns:
- Integer part of a given String
-
parseFloatPart
- Parameters:
aLineString
-- Returns:
- Float part of a given String
-
parseIntegerToArray
- Parameters:
aIndexString
-aConvertIndizes0To1
-- Returns:
- Array of Integers
-
fitString
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
- Type Parameters:
T
-- Parameters:
aSumOfCutValues
-aFile
-aSeperator
-- Throws:
IOException
-
arrayToString
- Parameters:
aSplit
-aSeparator
-- Returns:
-
convertStringToLines
-
convertLinesToStringarray
-
logFormat
-