public class StringUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.ToCSV<O>
Used to build csv file using
join(Iterable, ToString, String, boolean)
method. |
static interface |
StringUtil.ToString<O>
Contract to use in
join(Iterable, ToString, String, boolean)
method. |
Modifier and Type | Field and Description |
---|---|
static String[] |
EMPTY_STRING_ARRAY |
protected static double[] |
memoryFactors |
protected static String[] |
memoryUnites |
protected static double[] |
timeFactors |
protected static String[] |
timeUnites |
Modifier | Constructor and Description |
---|---|
protected |
StringUtil()
Constructor for the StringUtil object
|
Modifier and Type | Method and Description |
---|---|
static String |
asHex(byte[] hash)
Turns array of bytes into string representing each byte as
unsigned hex number.
|
static boolean |
checkEnclosure(String txt,
char opener,
char closer)
Vérifie q'une chaine de caractère est valid pour les bloc openner closer, ie.
|
static String |
convert(long value,
double[] factors,
String[] unites)
Note: this method use the current locale
(the
Locale.getDefault() ) in the method
MessageFormat.MessageFormat(String) . |
static String |
convertMemory(long value)
Converts an memory measure into a human readable format.
|
static String |
convertTime(long value)
Converts an time delay into a human readable format.
|
static String |
convertTime(long value,
long value2)
Converts an time period into a human readable format.
|
static String |
convertToConstantName(String name)
Convertir un nom en une constante Java
Les seuls caractères autorisés sont les alpha numériques, ains
que l'underscore. tous les autres caractères seront ignorés.
|
static String |
encodeMD5(String toEncode)
Convert a String to MD5.
|
static String |
encodeSHA1(String toEncode)
Convert a String to SHA1.
|
static String |
escapeCsvValue(String value,
String csvSeparator)
Add quotes if needed to escape special csv chars (',', '\n', '\t', ',', ';', '"')
|
static String |
getFileSeparatorRegex() |
static boolean |
isEmail(String str)
Know if a string is a valid e-mail.
|
static String |
join(Iterable<?> iterable,
String separator,
boolean trim)
Used to concat an
iterable of Object separated
by separator using the toString() method of each object. |
static <O> String |
join(Iterable<O> iterable,
StringUtil.ToString<O> ts,
String separator,
boolean trim)
Used to concat an
iterable of object <O> separated by
separator . |
static String[] |
split(Character[] openingChars,
Character[] closingChars,
String args,
String separator)
Split string use 'separator' as separator.
|
static String[] |
split(String stringList)
Use to split string array representation in array according with ',' as
default separator.
|
static String[] |
split(String args,
String separator)
Split string use 'separator' as separator.
|
static String |
substring(String s,
int begin)
substring from begin to end of s
example:
substring("tatetitotu", -4) → totu
|
static String |
substring(String s,
int begin,
int end)
substring from begin to end of s
example:
substring("tatetitotu", -4, -2) → to
|
static boolean[] |
toArrayBoolean(String... s) |
static byte[] |
toArrayByte(String... s) |
static char[] |
toArrayChar(String... s) |
static double[] |
toArrayDouble(String... s) |
static float[] |
toArrayFloat(String... s) |
static int[] |
toArrayInt(String... s) |
static long[] |
toArrayLong(String... s) |
static short[] |
toArrayShort(String... s) |
static boolean |
toBoolean(String s) |
static byte |
toByte(String s) |
static char |
toChar(String s) |
static Color |
toColor(String s)
Essai de convertir une chaine de caractere en une couleur si possible si
ce n'est pas possible retourne null.
|
static Date |
toDate(String s) |
static double |
toDouble(String s) |
static float |
toFloat(String s) |
static int |
toInt(String s) |
static long |
toLong(String s) |
static short |
toShort(String s) |
public static final String[] EMPTY_STRING_ARRAY
protected static final double[] timeFactors
protected static final String[] timeUnites
protected static final double[] memoryFactors
protected static final String[] memoryUnites
public static boolean isEmail(String str)
str
- a stringstr
is syntactically a valid e-mail addresspublic static String escapeCsvValue(String value, String csvSeparator)
value
- to escapecsvSeparator
- separator used for csvpublic static String join(Iterable<?> iterable, String separator, boolean trim)
iterable
of Object separated
by separator
using the toString() method of each object.
You can specify if the string must be trimmed or not.iterable
- Iterable with objects to treateseparator
- to usedtrim
- if each string must be trimpublic static <O> String join(Iterable<O> iterable, StringUtil.ToString<O> ts, String separator, boolean trim) throws NullPointerException
iterable
of object <O>
separated by
separator
. This method need a ts
contract to
call on each object. The ToString can be null to use directly the
toString() method on the object. The trim
boolean is used
to specify if each string object has to be trimmed. The null elements
in the list
will be ignored.O
- type of object in the listiterable
- Iterable with objects to treatets
- used to specify how the object is converted in Stringseparator
- to used between each object stringtrim
- if trim() method need to by apply on each object stringNullPointerException
- if iterable is null
.public static String substring(String s, int begin)
s
- the string to substringbegin
- if begin < 0 then begin start at end of string - beginpublic static String substring(String s, int begin, int end)
s
- the string to substringbegin
- if begin < 0 then begin start at end of string - beginend
- if end < 0 then end start at end of string - endpublic static String[] split(String args, String separator)
args
- string to splitseparator
- separator use to split stringpublic static String[] split(String stringList)
stringList
- string that represent arraypublic static String[] split(Character[] openingChars, Character[] closingChars, String args, String separator)
openingChar
closingChars
this method count the number of open char end close char to split
correctly argument
WARNING: cette method ne fonctionne pas si le contenu contient
des carateres utilisé pour le parsing et présent une seule fois.
Par exemple: "l'idenfiant" contient ' qui empeche totalement le
parsing de fonctionner.openingChars
- list of opening caracteresclosingChars
- list of closing caracteresargs
- string to splitseparator
- separator use to split stringpublic static boolean toBoolean(String s)
public static byte toByte(String s)
public static double toDouble(String s)
public static float toFloat(String s)
public static long toLong(String s)
public static short toShort(String s)
public static int toInt(String s)
public static char toChar(String s)
public static boolean[] toArrayBoolean(String... s)
public static byte[] toArrayByte(String... s)
public static double[] toArrayDouble(String... s)
public static float[] toArrayFloat(String... s)
public static long[] toArrayLong(String... s)
public static short[] toArrayShort(String... s)
public static int[] toArrayInt(String... s)
public static char[] toArrayChar(String... s)
public static String asHex(byte[] hash)
hash
- Array of bytes to convert to hex-stringpublic static Color toColor(String s) throws StringUtilException
s
- la couleur sous la forme de string, par exemple "red",
"yellow" ou bien en RGB "#FFAA99", et avec un canal alpha
"#FFAA3366"IllegalArgumentException
- FIXMEStringUtilException
- if any problem while conversionpublic static Date toDate(String s) throws ParseException
ParseException
public static String convertTime(long value)
value
- the delay to convertconvert(long, double[], String[])
public static String convertTime(long value, long value2)
value
- the begin timevalue2
- the end timeconvert(long, double[], String[])
public static String convertMemory(long value)
value
- the memory measure to convertconvert(long, double[], String[])
public static String convert(long value, double[] factors, String[] unites)
Locale.getDefault()
) in the method
MessageFormat.MessageFormat(String)
.value
- value to convertfactors
- facotrs used form conversionunites
- libelle of unites to usepublic static boolean checkEnclosure(String txt, char opener, char closer)
txt
- txte a verifieropener
- le caractère ouvrantcloser
- le caractère fermanttrue
is la chaine est validepublic static String convertToConstantName(String name)
name
- le nom à convertirpublic static String encodeMD5(String toEncode)
toEncode
- string concernedIllegalStateException
- if could not found algorithm MD5public static String encodeSHA1(String toEncode)
toEncode
- string to encodeIllegalStateException
- if could not found algorithm SHA1public static String getFileSeparatorRegex()
Copyright © 2004–2020 CodeLutin. All rights reserved.