public class Strings
extends java.lang.Object
String
. Constructor and Description |
---|
Strings() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
change(java.lang.String string,
java.util.Map toChange)
In the sent string changes the strings in toChange map
for its values.
|
static java.lang.String |
change(java.lang.String string,
java.lang.String original,
java.lang.String newString)
Change in
string |
static java.lang.String |
changeSeparatorsBySpaces(java.lang.String string)
Changes \n, \r and \t by space.
|
static java.lang.String |
concat(java.lang.String separator,
java.lang.String... strings)
Concatenates the list of strings using the separator.
|
static java.lang.String |
firstLower(java.lang.String s)
Returns a string like the sent one but with the first letter in lowercase.
|
static java.lang.String |
firstToken(java.lang.String string,
java.lang.String delim) |
static java.lang.String |
firstUpper(java.lang.String s)
Returns a string like the sent one but with the first letter in uppercase.
|
static java.lang.String |
fix(java.lang.String string,
int length,
Align align)
Fix the length of the string filling with spaces if needed.
|
static java.lang.String |
fix(java.lang.String string,
int length,
Align align,
char fillCharacter)
Fix the length of the string filling with the specified character if needed.
|
static boolean |
isModelName(java.lang.String string)
Determines if the string is a valid model name.
|
static boolean |
isNumeric(java.lang.CharSequence string)
The space, comma, dot, + and - are considered as numeric.
|
static java.lang.String |
javaIdentifierToNaturalLabel(java.lang.String name)
Convert a string with a Java identifier in label natural for a human.
|
static java.lang.String |
lastToken(java.lang.String string) |
static java.lang.String |
lastToken(java.lang.String string,
java.lang.String delim) |
static java.lang.String |
multiline(java.lang.String... strings)
Returns a String multiline platform independent.
|
static java.lang.String |
naturalLabelToIdentifier(java.lang.String naturalLabel)
Convert a string with a label natural for a human into a identifier valid to use as URL, file name, internal id, etc.
|
static java.lang.String |
noFirstToken(java.lang.String string,
java.lang.String delim)
All string but without first token.
|
static java.lang.String |
noFirstTokenWithoutFirstDelim(java.lang.String string,
java.lang.String delim)
All string but without first token.
|
static java.lang.String |
noLastToken(java.lang.String string)
All string but without last token.
|
static java.lang.String |
noLastToken(java.lang.String string,
java.lang.String delim)
All string but without last token.
|
static java.lang.String |
noLastTokenWithoutLastDelim(java.lang.String string,
java.lang.String delim)
All string but without last token.
|
static java.lang.String |
removeAccents(java.lang.String value)
Change from a vowel with an accent, to vowel with no accent
If you send "Camión" it returns "Camion"
|
static java.lang.String |
removeBlanks(java.lang.String string)
Returns the argument
string without blanks (\n, \r, \t, \f) or
whitespace. |
static java.lang.Object |
removeXSS(java.lang.Object notSafeValue) |
static java.lang.String |
removeXSS(java.lang.String notSafeValue)
A key function of any application filtering process will be
the removal of possible dangerous special characters.
|
static java.lang.String |
repeat(int count,
java.lang.String string)
Creates a string from repeating another string.
|
static java.lang.String |
spaces(int count)
Creates a string with the specified blank spaces.
|
static java.lang.String[] |
toArray(java.lang.String list)
Converts a list of comma separated elements in a string array.
|
static java.lang.String[] |
toArray(java.lang.String list,
java.lang.String separator)
Converts a list of elements separated by a arbitrary character
in a string array.
|
static java.lang.String |
toCharSet(java.lang.String original,
java.lang.String charSet)
Translate to the charset specified.
|
static java.util.Collection<java.lang.String> |
toCollection(java.lang.String list)
Converts a list of comma separated elements in a string collection.
|
static java.util.Collection<java.lang.String> |
toCollection(java.lang.String list,
java.lang.String separator)
Converts a list of elements separated by a arbitrary character
in a string collection.
|
static java.util.List<java.lang.String> |
toList(java.lang.String list)
Converts a list of comma separated elements in a string List.
|
static java.util.List<java.lang.String> |
toList(java.lang.String list,
java.lang.String separator)
Converts a list of elements separated by a arbitrary character
in a string List.
|
static java.lang.Object |
toObject(java.lang.Class type,
java.lang.String string)
Converts a string a object of the specified type.
|
static java.util.Set<java.lang.String> |
toSet(java.lang.String list)
Converts a list of comma separated elements in a string set.
|
static java.util.Set<java.lang.String> |
toSet(java.lang.String list,
java.lang.String separator)
Converts a list of elements separated by a arbitrary character
in a string set.
|
static java.util.Set<java.lang.String> |
toSetNullByPass(java.lang.String list)
Converts a list of comma separated elements in a string set.
|
static java.lang.String |
toString(java.util.Collection collection)
Converts a collection of objects in a string of comma separated elements.
|
static java.lang.String |
toString(java.util.Collection collection,
java.lang.String separator)
Converts a collection of objects in string of elements separated by a
arbitrary character .
|
static java.lang.String |
toString(java.lang.Object object)
Try to do a decent toString from a regular object.
|
static java.lang.String |
toString(java.lang.Object[] array)
Converts an array of objects in a string of comma separated elements.
|
static java.lang.String |
toString(java.lang.Object[] array,
java.lang.String separator)
Converts an array of objects in string of elements separated by a
arbitrary character .
|
static java.lang.String |
unquote(java.lang.String sentence)
Remove the quotes from a sentence between quotes.
|
public static java.lang.String concat(java.lang.String separator, java.lang.String... strings)
For example, concat(" - ", "Juan", "Perico", "Andrés") returns
"Juan - Perico - Andrés".
separator
- The character used as separator.strings
- Strings to be concatenated. Can be null.public static boolean isNumeric(java.lang.CharSequence string)
public static java.lang.String changeSeparatorsBySpaces(java.lang.String string)
string
- Not nullpublic static java.lang.String toCharSet(java.lang.String original, java.lang.String charSet) throws java.io.UnsupportedEncodingException
original
- Original stringcharSet
- Charset to traslate to, for example, UTF-8, or ISO-8859-1java.io.UnsupportedEncodingException
- If charset is not supportedpublic static java.lang.String spaces(int count)
count
- Quantity of spacespublic static java.lang.String fix(java.lang.String string, int length, Align align)
Returns the sent string but with the specified length.
It fills or cuts as it needs.
string
- Can be null, in which case empty string is assumedlength
- Character count of result stringalign
- Not nullpublic static java.lang.String fix(java.lang.String string, int length, Align align, char fillCharacter)
Returns the sent string but with the specified length.
It fills or cuts as it needs.
string
- Can be null, in which case empty string is assumedlength
- Character count of result stringalign
- Not nullfillCharacter
- Character used to fillpublic static java.lang.String repeat(int count, java.lang.String string)
count
- Times to repeatstring
- String to repeatpublic static final java.lang.String[] toArray(java.lang.String list)
For example, the list Angel, Manolo, Antonia is converted to
a array of 3 elements with this 3 names without comman nor spaces.
list
- String with the list. If null return a empty stringpublic static final java.lang.String[] toArray(java.lang.String list, java.lang.String separator)
For example, the list Angel : Manolo : Antonia is converted to
a array of 3 elements with this 3 names without colon (for example) nor spaces.
list
- String with the list. If null return a empty stringseparator
- The character used as separator.public static final java.util.Collection<java.lang.String> toCollection(java.lang.String list)
For example, the list Angel, Manolo, Antonia is converted to
a collection of 3 elements with this 3 names without comman nor spaces.
list
- String with the list. If null return a empty stringpublic static final java.util.Collection<java.lang.String> toCollection(java.lang.String list, java.lang.String separator)
For example, the list Angel : Manolo : Antonia is converted to
a collection of 3 elements with this 3 names without colon (for example) nor spaces.
list
- String with the list. If null return a empty stringseparator
- The character used as separator.public static final java.util.List<java.lang.String> toList(java.lang.String list)
For example, the list Angel, Manolo, Antonia is converted to
a List of 3 elements with this 3 names without comma nor spaces.
list
- String with the list. If null return a empty stringpublic static final java.util.List<java.lang.String> toList(java.lang.String list, java.lang.String separator)
For example, the list Angel : Manolo : Antonia is converted to
a List of 3 elements with this 3 names without colon (for example) nor spaces.
list
- String with the list. If null return a empty stringseparator
- The character used as separator.public static final java.util.Set<java.lang.String> toSet(java.lang.String list)
For example, the list Angel, Manolo, Antonia is converted to
a set of 3 elements with this 3 names without comman nor spaces.
list
- String with the list. If null return a empty stringpublic static final java.util.Set<java.lang.String> toSetNullByPass(java.lang.String list)
For example, the list Angel, Manolo, Antonia is converted to
a set of 3 elements with this 3 names without comman nor spaces.
list
- String with the list. If null return a empty stringpublic static final java.util.Set<java.lang.String> toSet(java.lang.String list, java.lang.String separator)
For example, the list Angel : Manolo : Antonia is converted to
a set of 3 elements with this 3 names without colon (for example) nor spaces.
list
- String with the list. If null return a empty stringseparator
- The character used as separator.public static final java.lang.String toString(java.util.Collection collection)
For example, a collection of 3 elements with 3 names
is converted to the string Angel, Manolo, Antonia
collection
- Collection with the elements. If null return an empty stringpublic static final java.lang.String toString(java.util.Collection collection, java.lang.String separator)
For example, a collection of 3 elements with this 3 names
is converted to a string of 3 elements with this 3 names and colon (for example).
collection
- A collection of objects. If null return an empty stringseparator
- The character used as separator.public static final java.lang.String toString(java.lang.Object[] array)
For example, an array of 3 elements with 3 names
is converted to the string Angel, Manolo, Antonia
array
- Array with the elements. If null return a empty stringpublic static final java.lang.String toString(java.lang.Object[] array, java.lang.String separator)
For example, an array of 3 elements with this 3 names
is converted to a string of 3 elements with this 3 names and colon (for example).
array
- An array of objects. If null return an empty stringseparator
- The character used as separator.public static final java.lang.String toString(java.lang.Object object)
Good format for arrays, dates, numbers, etc. taking in account the current locales (from Locales.getCurrent())
public static final java.lang.Object toObject(java.lang.Class type, java.lang.String string)
Supports all primitive type plus its wrappers except char and void.
Support String
and BigDecimal
too.
If there is conversion error or is a type not supporte return null or the default value for the type (zero for numeric).
type
- The type of returned object (can be a primitive type
in this case return its wrapper). Not nullstring
- String with data to convert. Can be null, in this case
return a default value.public static java.lang.String firstUpper(java.lang.String s)
If null is sent null is returned.
public static java.lang.String firstLower(java.lang.String s)
If null is sent null is returned.
public static java.lang.String change(java.lang.String string, java.util.Map toChange)
string
- Not nulltoChagne
- Not nullpublic static java.lang.String change(java.lang.String string, java.lang.String original, java.lang.String newString)
string original
by newString
.
string
- String in which we make the changes. Can be nulloriginal
- String to search. Not nullnewString
- New value to put in place of original. Not nullpublic static java.lang.String lastToken(java.lang.String string)
public static java.lang.String lastToken(java.lang.String string, java.lang.String delim)
public static java.lang.String noLastToken(java.lang.String string)
A trim is applied to the result.
public static java.lang.String noLastToken(java.lang.String string, java.lang.String delim)
Includes the last delim.
public static java.lang.String noFirstToken(java.lang.String string, java.lang.String delim)
Includes the delim.
public static java.lang.String noFirstTokenWithoutFirstDelim(java.lang.String string, java.lang.String delim)
Does not include the delim.
public static java.lang.String noLastTokenWithoutLastDelim(java.lang.String string, java.lang.String delim)
It does not include the last delim.
public static java.lang.String firstToken(java.lang.String string, java.lang.String delim)
public static java.lang.String removeXSS(java.lang.String notSafeValue)
public static java.lang.Object removeXSS(java.lang.Object notSafeValue)
notSafeValue
- public static java.lang.String javaIdentifierToNaturalLabel(java.lang.String name)
If you send "firstName" it returns "First name".
If you send "CustomerOrder" it returns "Customer order".
public static java.lang.String naturalLabelToIdentifier(java.lang.String naturalLabel)
If you send "León, España" it returns "LeonEspana".
The % is changed by the "percent" string.
public static java.lang.String removeAccents(java.lang.String value)
public static boolean isModelName(java.lang.String string)
public static java.lang.String removeBlanks(java.lang.String string)
string
without blanks (\n, \r, \t, \f) or
whitespace.
If you send "my group" it returns "myGroup".
If you send "My Section" it returns "MySection".
string
- String not nullpublic static java.lang.String multiline(java.lang.String... strings)
For example,
Strings.multiline("OpenXava", "AJAX Java Framework Web", "You only have to write the domain classes") ->
"OpenXava
AJAX Java Framework Web
You only have to write the domain classes"
strings
- The array of String objects, entries not may be nullpublic static java.lang.String unquote(java.lang.String sentence)
That is:
"Hi, I'm Peter" --> Hi, I'm Peter
sentence
- The original sentence, with or without surrounding quotes.