Package net.simplace.core.service
Class StringHelper
java.lang.Object
net.simplace.core.service.StringHelper
- Author:
- Andreas Enders
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarrayToList(Object[] aArray) Turns an array into a (Array-)list.static StringarrayToString(String[] aSplit, String aSeparator) static <T> StringarrayToString(T[][] aSumOfCutValues, String aSeperator) static booleancontainsAnyCharacter(String aStringToCheck, String aCharactersToLookFor) Checks, whether any of the characters in aCharactersContained occurs in aStringToCheck.static booleancontainsProblematicCharacters(String aStringToCheck) static booleancontainsProblematicCharacters(String aStringToCheck, boolean aAlsoCheckForHTMLEntity) Searches the given String for any of the special characters < > $ " ' \ # % Returns true, if one of these is found.static booleancontainsSpecialCharacters(String aStringToCheck) Searches the given String for special characters.static booleancontainsWebEuroSign(String aStringToCheck) Searches the given String for the EURO sign as it is transmitted via the browser.static booleancontainsWebEuroSign(String aStringToCheck, boolean aAlsoCheckForHTMLEntity) Searches the given String for the EURO sign as it is transmitted via the browser.static StringconvertEncoding(String aContent, String aInputEncoding, String aOutputEncoding) Gets String with one encoding and returns one with another encoding.static StringconvertLineBreak(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 StringCuts the tail of the given string if it exceeds a given length (minimum 3).static StringextractDigitsFromString(String aString) discards every non digit from the passed stringstatic StringfilterLineFeed(String aString) Replaces line feed characters with whitespaces.static StringfilterWhiteSpacesAndTabs(String aString) Replaces several white spaces characters with one.static Iterable<MatchResult>findMatches(String pattern, CharSequence s) static StringFits the length of a String with spaces to the given lengthstatic Stringstatic StringgetAfterDivider(String aString, String aDivider) Returns the part of aString after aDivider.static StringgetAfterFirstDivider(String aString, String aDivider) Returns the part of aString after aDivider.static StringgetBeforeDivider(String aString, String aDivider) Returns the part of aString before aDivider.static StringgetBeforeLastDivider(String aString, String aDivider) Returns the part of aString before the last Divider.static final StringReturns a string containing the first aCharCount characters of aString.static final StringgetInternationalisedString(String aInputString) Replaces a old value with a new value in the given Stringstatic StringgetLabelText(String aText) Value of the label.static StringgetLabelText(String aText, boolean aAlwaysHTML) Returning a formated value for a label or tooltiptext, replacing all linebreaks and special chars.static StringgetLabelText(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 LongReturns the part of aString that is made of numbers.getMapFromString(String aString, String aMapDivider, String aValueDevider) getMatchesFromString(String aString, String aPattern) static final DecimalFormatgetNumberFormat(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 StringReturns a string containing the first aCharCount characters of aString.static StringgetTimeString(Long aTime) Returns the time in string format.static StringgetTimeText(long aTime) Returns a text for the given time. (08:25:14)static StringinsertLineBreaks(String aString, String aLineBreak, int aMaxLength, boolean aCountSpaces) static booleanstatic booleanReturns the part of aString that is made of numbers.static Stringstatic StringoutputToString(Map<String, ?> aMap) Returns a formatted String form the given Map.static StringThis method fills a given string with a specified char until the specified length is achieved.static booleanparseBoolean(Object aString) Tries to figure out the boolean value of the given String or returns false if it can't.static BooleanparseBoolean(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 LocalDateTimeparseDate(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 FloatparseFloatPart(String aLineString) static IntegerparseIntegerPart(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 StringremoveCharacter(String aString, char aChar) Replaces line feed characters with whitespaces.static StringreplaceAll(String aString, Map aSubstitutionMap) Replaces all entries from the map.static StringreplaceHTMLEntities(String aHTML) Changes the given code to html.static StringreplaceHTMLEntities(String aHTML, boolean aReplaceHTMLChars) Changes the given code to html.static StringreplaceNullWithEmptyString(String aString) replaces Null with empty String.static final StringreplacePlaceholder(String aDocument, String aPlaceholder, String aValue) Replaces a String ($Example$) in a document by taking the Value.static final StringBufferreplacePlaceholderAsBuffer(String aDocument, String aPlaceholder, String aValue) Replaces a StringBuffer ($Example$) in a document by taking the Value.static final StringreturnValidString(String aUncheckedString) Replaces all letters that are maybe not supported by system for using in filename.static doubleround(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 StringtoStringForm(Double[] value) static StringtoStringForm(Double[][] matrix) static StringtoStringForm(Integer[] value) static StringtoStringForm(String[] value) static ObjecttransformDataType(String aString, FWSimVariable<?> aVariable) static StringunParseParameters(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
-