Package org.hcjf.utils
Class Strings
- java.lang.Object
-
- org.hcjf.utils.Strings
-
public final class Strings extends java.lang.ObjectThis class contains utils methods to work with strings.- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStrings.BuilderThis class is a StringBuilder wrapper that add a way to append objects with a buffer to be used in the next append or discard the buffer is there are not a other append operationstatic classStrings.StandardOutputstatic classStrings.TaggedMessages
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALLstatic java.lang.StringARGUMENT_SEPARATORstatic java.lang.StringARGUMENT_SEPARATOR_2static java.lang.StringASSIGNATIONstatic java.lang.StringATstatic java.lang.StringCARRIAGE_RETURNstatic java.lang.StringCARRIAGE_RETURN_AND_LINE_SEPARATORstatic java.lang.StringCASE_INSENSITIVE_REGEX_FLAGstatic java.lang.StringCLASS_SEPARATORstatic java.lang.StringDEFAULT_PADDING_VALUEstatic java.lang.StringEMPTY_STRINGstatic java.lang.StringEND_GROUPstatic java.lang.StringEND_OBJECTstatic java.lang.StringEND_SUB_GROUPstatic java.lang.StringLINE_SEPARATORstatic java.lang.StringOBJETC_FIELD_SEPARATORstatic java.lang.StringREPLACEABLE_GROUPstatic java.lang.StringREPLACEABLE_RICH_TEXTstatic java.lang.StringRICH_TEXT_SEPARATORstatic java.lang.StringRICH_TEXT_SKIP_CHARACTERstatic java.lang.StringSLASHstatic java.lang.StringSPLIT_BY_LENGTH_REGEXstatic java.lang.StringSTART_GROUPstatic java.lang.StringSTART_OBJECTstatic java.lang.StringSTART_SUB_GROUPstatic java.lang.StringTABstatic java.lang.StringWHITE_SPACE
-
Constructor Summary
Constructors Constructor Description Strings()
-
Method Summary
Modifier and Type Method Description static java.util.Set<java.lang.Integer>allIndexOf(java.lang.String value, java.lang.String foundedValue)Return all the index into the string value where found the specific founded value.static java.util.Set<java.lang.Integer>allIndexOf(java.lang.String value, java.lang.String foundedValue, boolean desc)Return all the index into the string value where found the specific founded value.static java.lang.StringbytesToHex(byte[] bytes)Returns a hexadecimal representation of the byte array.static java.lang.Stringcapitalize(java.lang.String value)Replace the first character for his upper case representation.static java.lang.StringcreateTaggedMessage(java.lang.String message, java.lang.String... tags)This method create a tagged message with the format $@{tag,tag,tag...}messagestatic java.util.UUIDcreateUUIDFromStringHash(java.lang.String value)This method creates a uuid from a hash code of the string object.static java.util.UUIDcreateUUIDFromStringHash(java.lang.String value1, java.lang.String value2)This method creates a uuid from a hash code of the string object.static java.lang.ObjectdeductInstance(java.lang.String value)Returns the instance of the class that is deducted from the string value.static java.lang.StringgetGroupIndex(java.lang.String value, java.lang.String groupIndicator)Return the first replaceable index founded.static java.lang.StringgetNearFrom(java.lang.String value, int position, int length)Returns a shorted string that the original centered into the position parameter and withstatic intgetNoMatchPlace(java.util.regex.Matcher matcher, java.lang.String value)Returns the place where the regex is no matching with the value.static java.util.Map<java.lang.String,java.lang.String>getTagsFromMessage(java.lang.String taggedMessage)This method create a hash map indexing the same message with the different tags.static java.util.List<java.lang.String>group(java.lang.String value)Return the list with all the groups and sub groups of the value.static java.util.List<java.lang.String>groupRichText(java.lang.String value)Returns all the rich texts contained into the value and the value (in the last place) with all the replaceable places for each rich text.static byte[]hexToBytes(java.lang.String hex)Returns a byte array based on the hexadecimal representation.static java.lang.Stringjoin(java.util.Collection<java.lang.String> values, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified.static java.lang.Stringjoin(java.util.Collection<java.lang.String> values, java.lang.String startValue, java.lang.String endValue, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified and wrapped by the start and and value.static java.lang.Stringjoin(java.util.stream.Stream<java.lang.String> values, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified.static java.lang.Stringjoin(java.util.stream.Stream<java.lang.String> values, java.lang.String startValue, java.lang.String endValue, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified and wrapped by the start and and value.static java.lang.StringjoinWords(java.lang.String value, java.lang.String separator)This method join the words into the value identifying each of word for the uppercase character.static java.lang.StringleftPad(java.lang.String value, int paddingSize)Complete the left side of the value with n instance of the default padding value (' ').static java.lang.StringleftPad(java.lang.String value, java.lang.String paddingValue, int paddingSize)Complete the left side of the value with n instance of the padding value.static java.lang.StringremoveLines(java.lang.String value)This method replace the combination of character \r\n and the character \n for white space character.static java.util.List<java.lang.String>replaceableGroup(java.lang.String value)Return a list with all groups and sub groups in ascendant order with replacement places that refer some index into the same list.static java.lang.StringreverseGrouping(java.lang.String value, java.util.List<java.lang.String> groups)Reverts the grouping action over the specific value.static java.lang.StringreverseRichTextGrouping(java.lang.String value, java.util.List<java.lang.String> richTextGroups)Reverts the grouping action over the specific value.static java.lang.StringrightPad(java.lang.String value, int paddingSize)Complete the right side of the value with n instance of the default padding value (' ').static java.lang.StringrightPad(java.lang.String value, java.lang.String paddingValue, int paddingSize)Complete the right side of the value with n instance of the padding value.static java.lang.String[]splitByLength(java.lang.String value, int length)This method splits the string value in n substring with the same length except for the last substring that could be smaller than the rest of the substrings.static java.lang.StringsplitInWord(java.lang.String value, java.lang.String separator)This method search all the upper case characters into the value parameter and separates the value using this upper case characters like limit adding between words the separator value.static java.lang.Stringtrim(java.lang.String value, java.lang.String limitStrings)This method trim the first and the last value if this values are equals that the parameter.static java.lang.Stringtrim(java.lang.String value, java.lang.String startingString, java.lang.String endingString)This method trim the first and the last value if this values are equals that the parameters.static java.lang.Stringuncapitalize(java.lang.String value)Replace the first character for his lower case representation.
-
-
-
Field Detail
-
DEFAULT_PADDING_VALUE
public static final java.lang.String DEFAULT_PADDING_VALUE
- See Also:
- Constant Field Values
-
START_GROUP
public static final java.lang.String START_GROUP
- See Also:
- Constant Field Values
-
END_GROUP
public static final java.lang.String END_GROUP
- See Also:
- Constant Field Values
-
START_SUB_GROUP
public static final java.lang.String START_SUB_GROUP
- See Also:
- Constant Field Values
-
END_SUB_GROUP
public static final java.lang.String END_SUB_GROUP
- See Also:
- Constant Field Values
-
START_OBJECT
public static final java.lang.String START_OBJECT
- See Also:
- Constant Field Values
-
END_OBJECT
public static final java.lang.String END_OBJECT
- See Also:
- Constant Field Values
-
OBJETC_FIELD_SEPARATOR
public static final java.lang.String OBJETC_FIELD_SEPARATOR
- See Also:
- Constant Field Values
-
REPLACEABLE_GROUP
public static final java.lang.String REPLACEABLE_GROUP
- See Also:
- Constant Field Values
-
EMPTY_STRING
public static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
WHITE_SPACE
public static final java.lang.String WHITE_SPACE
- See Also:
- Constant Field Values
-
CLASS_SEPARATOR
public static final java.lang.String CLASS_SEPARATOR
- See Also:
- Constant Field Values
-
CASE_INSENSITIVE_REGEX_FLAG
public static final java.lang.String CASE_INSENSITIVE_REGEX_FLAG
- See Also:
- Constant Field Values
-
ARGUMENT_SEPARATOR
public static final java.lang.String ARGUMENT_SEPARATOR
- See Also:
- Constant Field Values
-
ARGUMENT_SEPARATOR_2
public static final java.lang.String ARGUMENT_SEPARATOR_2
- See Also:
- Constant Field Values
-
ASSIGNATION
public static final java.lang.String ASSIGNATION
- See Also:
- Constant Field Values
-
REPLACEABLE_RICH_TEXT
public static final java.lang.String REPLACEABLE_RICH_TEXT
- See Also:
- Constant Field Values
-
RICH_TEXT_SEPARATOR
public static final java.lang.String RICH_TEXT_SEPARATOR
- See Also:
- Constant Field Values
-
RICH_TEXT_SKIP_CHARACTER
public static final java.lang.String RICH_TEXT_SKIP_CHARACTER
- See Also:
- Constant Field Values
-
CARRIAGE_RETURN_AND_LINE_SEPARATOR
public static final java.lang.String CARRIAGE_RETURN_AND_LINE_SEPARATOR
- See Also:
- Constant Field Values
-
CARRIAGE_RETURN
public static final java.lang.String CARRIAGE_RETURN
- See Also:
- Constant Field Values
-
LINE_SEPARATOR
public static final java.lang.String LINE_SEPARATOR
- See Also:
- Constant Field Values
-
TAB
public static final java.lang.String TAB
- See Also:
- Constant Field Values
-
SLASH
public static final java.lang.String SLASH
- See Also:
- Constant Field Values
-
AT
public static final java.lang.String AT
- See Also:
- Constant Field Values
-
ALL
public static final java.lang.String ALL
- See Also:
- Constant Field Values
-
SPLIT_BY_LENGTH_REGEX
public static final java.lang.String SPLIT_BY_LENGTH_REGEX
- See Also:
- Constant Field Values
-
-
Method Detail
-
trim
public static java.lang.String trim(java.lang.String value, java.lang.String limitStrings)This method trim the first and the last value if this values are equals that the parameter.- Parameters:
value- Value to trim.limitStrings- Value to compare with the start and end of the value.- Returns:
- Returns the value trimmed
-
trim
public static java.lang.String trim(java.lang.String value, java.lang.String startingString, java.lang.String endingString)This method trim the first and the last value if this values are equals that the parameters.- Parameters:
value- Value to trim.startingString- Value to compare with the start of the value.endingString- Value to compare with the end of the value.- Returns:
- Returns the value trimmed.
-
removeLines
public static java.lang.String removeLines(java.lang.String value)
This method replace the combination of character \r\n and the character \n for white space character.- Parameters:
value- String to remove the lines.- Returns:
- String value without lines.
-
join
public static java.lang.String join(java.util.Collection<java.lang.String> values, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified.- Parameters:
values- Values to join.separator- Separator value.- Returns:
- Result of the join operation.
-
join
public static java.lang.String join(java.util.stream.Stream<java.lang.String> values, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified.- Parameters:
values- Values to join.separator- Separator value.- Returns:
- Result of the join operation.
-
join
public static java.lang.String join(java.util.Collection<java.lang.String> values, java.lang.String startValue, java.lang.String endValue, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified and wrapped by the start and and value.- Parameters:
values- Values to join.startValue- Wrapped start value.endValue- Wrapped end value.separator- Separator value.- Returns:
- Result of the join operation.
-
join
public static java.lang.String join(java.util.stream.Stream<java.lang.String> values, java.lang.String startValue, java.lang.String endValue, java.lang.String separator)Return the string that result of join all the values separated by the separated value specified and wrapped by the start and and value.- Parameters:
values- Values to join.startValue- Wrapped start value.endValue- Wrapped end value.separator- Separator value.- Returns:
- Result of the join operation.
-
capitalize
public static java.lang.String capitalize(java.lang.String value)
Replace the first character for his upper case representation.- Parameters:
value- Value to replace.- Returns:
- Replaced value.
-
uncapitalize
public static java.lang.String uncapitalize(java.lang.String value)
Replace the first character for his lower case representation.- Parameters:
value- Value to replace.- Returns:
- Replaced value.
-
splitInWord
public static java.lang.String splitInWord(java.lang.String value, java.lang.String separator)This method search all the upper case characters into the value parameter and separates the value using this upper case characters like limit adding between words the separator value.- Parameters:
value- Value to split.separator- Separator value.- Returns:
- String with separated words.
-
joinWords
public static java.lang.String joinWords(java.lang.String value, java.lang.String separator)This method join the words into the value identifying each of word for the uppercase character.- Parameters:
value- Value to join.separator- String to delimits the words.- Returns:
- Joined value.
-
leftPad
public static java.lang.String leftPad(java.lang.String value, int paddingSize)Complete the left side of the value with n instance of the default padding value (' ').- Parameters:
value- Value to be completed.paddingSize- Number of instance to pad the value.- Returns:
- New string with the left side padding.
-
leftPad
public static java.lang.String leftPad(java.lang.String value, java.lang.String paddingValue, int paddingSize)Complete the left side of the value with n instance of the padding value.- Parameters:
value- Value to be completed.paddingValue- Padding value.paddingSize- Number of instance to pad the value.- Returns:
- New string with the left side padding.
-
rightPad
public static java.lang.String rightPad(java.lang.String value, int paddingSize)Complete the right side of the value with n instance of the default padding value (' ').- Parameters:
value- Value to be completed.paddingSize- Number of instance to pad the value.- Returns:
- New string with the right side padding.
-
rightPad
public static java.lang.String rightPad(java.lang.String value, java.lang.String paddingValue, int paddingSize)Complete the right side of the value with n instance of the padding value.- Parameters:
value- Value to be completed.paddingValue- Padding value.paddingSize- Number of instance to pad the value.- Returns:
- New string with the right side padding.
-
allIndexOf
public static java.util.Set<java.lang.Integer> allIndexOf(java.lang.String value, java.lang.String foundedValue)Return all the index into the string value where found the specific founded value.- Parameters:
value- Value to found the index.foundedValue- Founded value into the string.- Returns:
- Return a list with the indexes of the places where found value.
-
allIndexOf
public static java.util.Set<java.lang.Integer> allIndexOf(java.lang.String value, java.lang.String foundedValue, boolean desc)Return all the index into the string value where found the specific founded value.- Parameters:
value- Value to found the index.foundedValue- Founded value into the string.desc- If this parameter is true then the first index is the smaller else if the parameter s false then the first index is bigger.- Returns:
- Return a list with the indexes of the places where found value.
-
groupRichText
public static java.util.List<java.lang.String> groupRichText(java.lang.String value)
Returns all the rich texts contained into the value and the value (in the last place) with all the replaceable places for each rich text.- Parameters:
value- Value to get the rich texts.- Returns:
- List with the rich text and the original value.
-
group
public static java.util.List<java.lang.String> group(java.lang.String value)
Return the list with all the groups and sub groups of the value. A group is the char sequence between the start group character '(' and the end group character ')'- Parameters:
value- Groupable value.- Returns:
- List with all the groups.
-
replaceableGroup
public static final java.util.List<java.lang.String> replaceableGroup(java.lang.String value)
Return a list with all groups and sub groups in ascendant order with replacement places that refer some index into the same list. e.g. "Hello (world)" - ["world", "Hello $0"]- Parameters:
value- String to group.- Returns:
- List with groups.
-
getGroupIndex
public static java.lang.String getGroupIndex(java.lang.String value, java.lang.String groupIndicator)Return the first replaceable index founded.- Parameters:
value- Value to analyse- Returns:
- Replaceable index.
-
reverseRichTextGrouping
public static java.lang.String reverseRichTextGrouping(java.lang.String value, java.util.List<java.lang.String> richTextGroups)Reverts the grouping action over the specific value.- Parameters:
value- Value to revert.richTextGroups- Group lists.- Returns:
- Reverted value.
-
reverseGrouping
public static java.lang.String reverseGrouping(java.lang.String value, java.util.List<java.lang.String> groups)Reverts the grouping action over the specific value.- Parameters:
value- Value to revert.groups- Group lists.- Returns:
- Reverted value.
-
bytesToHex
public static java.lang.String bytesToHex(byte[] bytes)
Returns a hexadecimal representation of the byte array.- Parameters:
bytes- Byte array to represents.- Returns:
- Hexadecimal representation.
-
hexToBytes
public static byte[] hexToBytes(java.lang.String hex)
Returns a byte array based on the hexadecimal representation.- Parameters:
hex- Hexadecimal representation.- Returns:
- Byte array.
-
splitByLength
public static java.lang.String[] splitByLength(java.lang.String value, int length)This method splits the string value in n substring with the same length except for the last substring that could be smaller than the rest of the substrings.- Parameters:
value- String value to split.length- Length of the substrings.- Returns:
- Substrings array.
-
createUUIDFromStringHash
public static java.util.UUID createUUIDFromStringHash(java.lang.String value)
This method creates a uuid from a hash code of the string object.- Parameters:
value- String to create a uuid. The hash code of this value is used to create the least significant bits of the uuid and the most significant bits are 0.- Returns:
- UUID instance generated using the nex constructor new UUID(0, value.hashCode());
-
createUUIDFromStringHash
public static java.util.UUID createUUIDFromStringHash(java.lang.String value1, java.lang.String value2)This method creates a uuid from a hash code of the string object.- Parameters:
value1- First string to create a uuid. The hash code of this value is used to create the most significant bits of the uuid. This value con be null.value2- Second string to create a uuid. The hash code of this value is used to create the least significant bits of the uuid- Returns:
- UUID instance generated using the nex constructor new UUID(0, value.hashCode());
-
deductInstance
public static java.lang.Object deductInstance(java.lang.String value)
Returns the instance of the class that is deducted from the string value.- Parameters:
value- String value.- Returns:
- Instance deducted.
-
createTaggedMessage
public static final java.lang.String createTaggedMessage(java.lang.String message, java.lang.String... tags)This method create a tagged message with the format $@{tag,tag,tag...}message- Parameters:
message- Message to tag.tags- Array of tags.- Returns:
- Returns the tagged message.
-
getTagsFromMessage
public static final java.util.Map<java.lang.String,java.lang.String> getTagsFromMessage(java.lang.String taggedMessage)
This method create a hash map indexing the same message with the different tags.- Parameters:
taggedMessage- Tagged message.- Returns:
- Hash map with the tags.
-
getNoMatchPlace
public static final int getNoMatchPlace(java.util.regex.Matcher matcher, java.lang.String value)Returns the place where the regex is no matching with the value.- Parameters:
matcher- Matcher instance.value- Value to found.- Returns:
- Returns the index into the value where the regex is not matching.
-
getNearFrom
public static final java.lang.String getNearFrom(java.lang.String value, int position, int length)Returns a shorted string that the original centered into the position parameter and with- Parameters:
value-position-length-- Returns:
-
-