Class StringUtil
java.lang.Object
net.okapia.osid.torrefacto.util.StringUtil
Some string utilities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringabbreviate(String str, int maxWidth) Abbreviates a string using ellipses.static Stringabbreviate(String str, int offset, int maxWidth) Abbreviates a string using ellipses, working from the given left edge offset so that a window further into the string can be shown.static Stringabbreviate(String str, String abbrevMarker, int maxWidth) Abbreviates a string using the given replacement marker.static Stringabbreviate(String str, String abbrevMarker, int offset, int maxWidth) Abbreviates a string using the given replacement marker, working from the given left edge offset.static Stringabbreviate(DisplayText text, int maxWidth) Abbreviates the text of a display text using ellipses.static Stringabbreviate(DisplayText text, int offset, int maxWidth) Abbreviates the text of a display text using ellipses, working from the given left edge offset.static Stringabbreviate(DisplayText text, String abbrevMarker, int maxWidth) Abbreviates the text of a display text using the given replacement marker.static Stringabbreviate(DisplayText text, String abbrevMarker, int offset, int maxWidth) Abbreviates the text of a display text using the given replacement marker, working from the given left edge offset.static StringabbreviateMiddle(String str, String middle, int length) Abbreviates a string to the given length using a replacement marker in the middle, keeping the first and last characters.static StringabbreviateMiddle(DisplayText text, String middle, int length) Abbreviates the text of a display text to the given length using a replacement marker in the middle.static Stringcapitalize(String str) Capitalizes a string.static Stringcapitalize(DisplayText text) Capitalizes the text of a display text.static StringCenters a string in a larger string of the given size, padding with spaces.static StringCenters a string in a larger string of the given size, padding with the given character.static StringCenters a string in a larger string of the given size, padding with the given string.static Stringcenter(DisplayText text, int size) Centers the text of a display text in a larger string of the given size, padding with spaces.static Stringcenter(DisplayText text, int size, char padChar) Centers the text of a display text in a larger string of the given size, padding with the given character.static Stringcenter(DisplayText text, int size, String padStr) Centers the text of a display text in a larger string of the given size, padding with the given string.static StringGets a lower case article for the given word.static StringgetLowerArticle(DisplayText text) Gets a lower case article for the text of a display text.static StringGets an upper case article for the given word.static StringgetUpperArticle(DisplayText text) Gets an upper case article for the text of a display text.static booleanTests if a string isnullor empty ("").static booleanisEmpty(DisplayText text) Tests if the text of a display text isnullor empty ("").static booleanTests if a string contains only Unicode digits.static booleanisNumeric(DisplayText text) Tests if the text of a display text contains only Unicode digits.static booleanisVowel(char c) Tests if a letter is a vowel.static Stringordinalize(long number) Turns a non-negative number into an ordinal string used to denote the position in an ordered sequence, such as 1st, 2nd, 3rd, 4th.static Stringuncapitalize(String str) UnCapitalizes a String.static Stringuncapitalize(DisplayText text) Uncapitalizes the text of a display text.
-
Constructor Details
-
StringUtil
public StringUtil()Constructs a newStringUtil.
-
-
Method Details
-
getUpperArticle
Gets an upper case article for the text of a display text.- Parameters:
text- a display text- Returns:
- the article
- Throws:
NullArgumentException-textisnull
-
getUpperArticle
Gets an upper case article for the given word.- Parameters:
s- a work or phrase- Returns:
- the article
- Throws:
NullArgumentException-sisnull
-
getLowerArticle
Gets a lower case article for the text of a display text.- Parameters:
text- a display text- Returns:
- the article
- Throws:
NullArgumentException-textisnull
-
getLowerArticle
Gets a lower case article for the given word.- Parameters:
s- a work or phrase- Returns:
- the article
- Throws:
NullArgumentException-sisnull
-
capitalize
Capitalizes the text of a display text.- Parameters:
text- a display text- Returns:
- the capitalized string
- Throws:
NullArgumentException-textisnull
-
capitalize
Capitalizes a string.- Parameters:
str- a string- Returns:
- the capitalized string
- Throws:
NullArgumentException-strisnull
-
uncapitalize
Uncapitalizes the text of a display text.- Parameters:
text- a display text- Returns:
- the uncapitalized string
- Throws:
NullArgumentException-textisnull
-
uncapitalize
UnCapitalizes a String.- Parameters:
str- a string- Returns:
- the uncapitalized string
- Throws:
NullArgumentException-strisnull
-
ordinalize
Turns a non-negative number into an ordinal string used to denote the position in an ordered sequence, such as 1st, 2nd, 3rd, 4th.- Parameters:
number- the non-negative number- Returns:
- the string with the number and ordinal suffix
- Throws:
InvalidArgumentException-numberis negative
-
isVowel
public static boolean isVowel(char c) Tests if a letter is a vowel.- Parameters:
c- a character- Returns:
trueifcis a vowelmfalseotherwise
-
abbreviate
Abbreviates the text of a display text using ellipses.- Parameters:
text- a display textmaxWidth- the maximum length of the result, at least 4- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-textisnull
-
abbreviate
Abbreviates a string using ellipses. The result is no longer thanmaxWidth. For example:abbreviate("abcdefg", 6) = "abc..." abbreviate("abcdefg", 7) = "abcdefg" abbreviate("abcdefg", 4) = "a..."- Parameters:
str- the string to abbreviatemaxWidth- the maximum length of the result, at least 4- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-strisnull
-
abbreviate
Abbreviates the text of a display text using ellipses, working from the given left edge offset.- Parameters:
text- a display textoffset- the left edge of the source stringmaxWidth- the maximum length of the result, at least 4- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-textisnull
-
abbreviate
Abbreviates a string using ellipses, working from the given left edge offset so that a window further into the string can be shown. For example:abbreviate("abcdefghijklmno", 5, 10) = "...fghi..."- Parameters:
str- the string to abbreviateoffset- the left edge of the source stringmaxWidth- the maximum length of the result, at least 4- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-strisnull
-
abbreviate
Abbreviates the text of a display text using the given replacement marker.- Parameters:
text- a display textabbrevMarker- the replacement marker, may benullmaxWidth- the maximum length of the result- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-textisnull
-
abbreviate
Abbreviates a string using the given replacement marker. The result is no longer thanmaxWidth. For example:abbreviate("abcdefg", ".", 5) = "abcd."- Parameters:
str- the string to abbreviateabbrevMarker- the replacement marker, may benullmaxWidth- the maximum length of the result- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-strisnull
-
abbreviate
Abbreviates the text of a display text using the given replacement marker, working from the given left edge offset.- Parameters:
text- a display textabbrevMarker- the replacement marker, may benulloffset- the left edge of the source stringmaxWidth- the maximum length of the result- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-textisnull
-
abbreviate
Abbreviates a string using the given replacement marker, working from the given left edge offset. Anullstring returnsnulland an empty marker with a positive width simply truncates. For example:abbreviate("abcdefghijklmno", "...", 5, 10) = "...fghi..." abbreviate("abcdefghijklmno", "...", 8, 10) = "...ijklmno"- Parameters:
str- the string to abbreviateabbrevMarker- the replacement marker, may benulloffset- the left edge of the source stringmaxWidth- the maximum length of the result- Returns:
- the abbreviated string
- Throws:
InvalidArgumentException-maxWidthis too smallNullArgumentException-strisnull
-
abbreviateMiddle
Abbreviates the text of a display text to the given length using a replacement marker in the middle.- Parameters:
text- a display textmiddle- the replacement marker, may benulllength- the target length- Returns:
- the abbreviated string, or the original if it does not fit
- Throws:
NullArgumentException-textisnull
-
abbreviateMiddle
Abbreviates a string to the given length using a replacement marker in the middle, keeping the first and last characters. The string is returned unchanged if it is shorter than the length or the length cannot accommodate the marker. For example:abbreviateMiddle("abcdef", ".", 4) = "ab.f"- Parameters:
str- the string to abbreviatemiddle- the replacement marker, may benulllength- the target length- Returns:
- the abbreviated string, or the original if it does not fit
- Throws:
NullArgumentException-strisnull
-
center
Centers the text of a display text in a larger string of the given size, padding with spaces.- Parameters:
text- a display textsize- the size of the result- Returns:
- the centered string
- Throws:
NullArgumentException-textisnull
-
center
Centers a string in a larger string of the given size, padding with spaces. The original string is returned when the size is smaller. For example:center("abc", 7) = " abc " center("ab", 4) = " ab "- Parameters:
str- the string to centersize- the size of the result- Returns:
- the centered string
- Throws:
NullArgumentException-strisnull
-
center
Centers the text of a display text in a larger string of the given size, padding with the given character.- Parameters:
text- a display textsize- the size of the resultpadChar- the padding character- Returns:
- the centered string
- Throws:
NullArgumentException-textisnull
-
center
Centers a string in a larger string of the given size, padding with the given character.- Parameters:
str- the string to centersize- the size of the resultpadChar- the padding character- Returns:
- the centered string
- Throws:
NullArgumentException-strisnull
-
center
Centers the text of a display text in a larger string of the given size, padding with the given string.- Parameters:
text- a display textsize- the size of the resultpadStr- the padding string, a space if empty- Returns:
- the centered string
- Throws:
NullArgumentException-textisnull
-
center
Centers a string in a larger string of the given size, padding with the given string. An empty pad string defaults to a space. For example:center("abc", 7, "*") = "**abc**"- Parameters:
str- the string to centersize- the size of the resultpadStr- the padding string, a space if empty- Returns:
- the centered string
- Throws:
NullArgumentException-strisnull
-
isNumeric
Tests if the text of a display text contains only Unicode digits.- Parameters:
text- a display text- Returns:
trueif the text is non-empty and contains only digits,falseotherwise- Throws:
NullArgumentException-textisnull
-
isNumeric
Tests if a string contains only Unicode digits. Anullor empty string returnsfalse; a sign or decimal point is not a digit. For example:isNumeric("123") = true isNumeric("12.3") = false isNumeric("-123") = false- Parameters:
s- a string- Returns:
trueifsis non-empty and contains only digits,falseotherwise
-
isEmpty
Tests if the text of a display text isnullor empty ("").- Parameters:
text- a display text- Returns:
trueif the text isnullor empty,falseotherwise- Throws:
NullArgumentException-textisnull
-
isEmpty
Tests if a string isnullor empty ("").- Parameters:
s- a string- Returns:
trueifsisnullor empty,falseotherwise
-