Package net.sf.gridarta.utils
Class StringUtils
- java.lang.Object
-
- net.sf.gridarta.utils.StringUtils
-
public class StringUtils extends java.lang.ObjectUtility class for string manipulation.
-
-
Field Summary
Fields Modifier and Type Field Description static @NotNull java.util.regex.PatternPATTERN_BACKSLASHThe pattern that matches a single backslash ("\").static @NotNull java.util.regex.PatternPATTERN_COLONThe pattern that matches a single colon (":").static @NotNull java.util.regex.PatternPATTERN_COMMAThe pattern that matches a single comma (",").static @NotNull java.util.regex.PatternPATTERN_END_OF_LINEThe pattern to match end of line characters separating lines.static @NotNull java.util.regex.PatternPATTERN_EQUALThe pattern that matches a single equal sign ("=").static @NotNull java.util.regex.PatternPATTERN_NEWLINEThe pattern that matches a single newline ("\n").static @NotNull java.util.regex.PatternPATTERN_SLASHThe pattern that matches a single slash ("/").static @NotNull java.util.regex.PatternPATTERN_SPACEThe pattern that matches a single space.static @NotNull java.util.regex.PatternPATTERN_SPACESThe pattern that matches a non-empty sequence of spaces.static @NotNull java.util.regex.PatternPATTERN_WHITESPACEPattern to match whitespace excluding NL and CR.static @NotNull java.util.regex.PatternPATTERN_WHITESPACE_NEWLINEPattern to match whitespace including NL and CR.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable java.lang.CharSequencediffTextString(@NotNull java.lang.CharSequence base, @NotNull java.lang.String str, boolean ignoreValues)Helper function for 'diffArchText()': Looks for occurrence of the attribute 'str' in 'base' and if found, returns the full line where 'str' occurs in base.static @NotNull java.lang.CharSequenceensureTrailingNewline(@NotNull java.lang.String str)Returns a given string which ends with a trailing newline character; empty strings remain empty.static @Nullable java.lang.StringgetAttribute(@NotNull java.lang.CharSequence attributes, @NotNull java.lang.String attributeName)Returns an attribute line from a set of attribute definitions.static @NotNull java.lang.StringremoveTrailingWhitespace(@NotNull java.lang.CharSequence str)Removes trailing whitespace from a string.static @NotNull java.lang.StringremoveTrailingWhitespaceFromLines(@NotNull java.lang.CharSequence str)Removes trailing whitespace from all lines of a string.static @NotNull java.lang.StringsortLines(@NotNull java.lang.CharSequence string)Sorts newline separated lines in a string.
-
-
-
Field Detail
-
PATTERN_WHITESPACE
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
-
PATTERN_WHITESPACE_NEWLINE
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_WHITESPACE_NEWLINE
Pattern to match whitespace including NL and CR.
-
PATTERN_END_OF_LINE
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_END_OF_LINE
The pattern to match end of line characters separating lines.
-
PATTERN_SPACE
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_SPACE
The pattern that matches a single space.
-
PATTERN_SPACES
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_SPACES
The pattern that matches a non-empty sequence of spaces.
-
PATTERN_SLASH
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_SLASH
The pattern that matches a single slash ("/").
-
PATTERN_BACKSLASH
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_BACKSLASH
The pattern that matches a single backslash ("\").
-
PATTERN_COLON
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_COLON
The pattern that matches a single colon (":").
-
PATTERN_COMMA
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_COMMA
The pattern that matches a single comma (",").
-
PATTERN_EQUAL
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_EQUAL
The pattern that matches a single equal sign ("=").
-
PATTERN_NEWLINE
@NotNull public static final @NotNull java.util.regex.Pattern PATTERN_NEWLINE
The pattern that matches a single newline ("\n").
-
-
Method Detail
-
removeTrailingWhitespace
@NotNull public static @NotNull java.lang.String removeTrailingWhitespace(@NotNull @NotNull java.lang.CharSequence str)Removes trailing whitespace from a string.- Parameters:
str- the string- Returns:
- the trimmed string
-
removeTrailingWhitespaceFromLines
@NotNull public static @NotNull java.lang.String removeTrailingWhitespaceFromLines(@NotNull @NotNull java.lang.CharSequence str)Removes trailing whitespace from all lines of a string.- Parameters:
str- the string- Returns:
- the trimmed string
-
ensureTrailingNewline
@NotNull public static @NotNull java.lang.CharSequence ensureTrailingNewline(@NotNull @NotNull java.lang.String str)Returns a given string which ends with a trailing newline character; empty strings remain empty. If the input strings ends in a newline character or if it is empty, it is returned; else a newline character is appended first.- Parameters:
str- the input string- Returns:
- the string with a trailing newline character
-
diffTextString
@Nullable public static @Nullable java.lang.CharSequence diffTextString(@NotNull @NotNull java.lang.CharSequence base, @NotNull @NotNull java.lang.String str, boolean ignoreValues)Helper function for 'diffArchText()': Looks for occurrence of the attribute 'str' in 'base' and if found, returns the full line where 'str' occurs in base. Only occurrences of 'str' at the beginning of a new line are counted as valid. If not found, null is returned.- Parameters:
base- full text to searchstr- string (attribute) to look forignoreValues- if true, lines are matched against 'str' only till the first space (" ")- Returns:
- the text that differs
-
getAttribute
@Nullable public static @Nullable java.lang.String getAttribute(@NotNull @NotNull java.lang.CharSequence attributes, @NotNull @NotNull java.lang.String attributeName)Returns an attribute line from a set of attribute definitions. If the set contains more than one instance ofattributeName, only the first instance is returned.- Parameters:
attributes- the attribute set to searchattributeName- the attribute name to search for- Returns:
- the set of attribute value or
nullif the attribute was not found
-
sortLines
@NotNull public static @NotNull java.lang.String sortLines(@NotNull @NotNull java.lang.CharSequence string)Sorts newline separated lines in a string.- Parameters:
string- the string to sort- Returns:
- the sorted string
-
-