org.nuiton.util
Class StringUtil

java.lang.Object
  extended by org.nuiton.util.StringUtil

public class StringUtil
extends Object

Classe contenant un ensemle de methode static utiles pour la manipulation des chaine de caractere mais qui ne sont pas defini dans la classe String de Java.

Author:
poussin created 21 octobre 2003

Field Summary
protected static double[] memoryFactors
           
protected static String[] memoryUnites
           
protected static double[] timeFactors
           
protected static String[] timeUnites
           
 
Constructor Summary
protected StringUtil()
          Constructor for the StringUtil object
 
Method Summary
static String capitalize(String word)
          Deprecated. you must use org.apache.commons.lang.StringUtils.capitalise(String)
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)
           
static String convertTime(long value)
           
static String convertTime(long value, long value2)
           
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[] 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 swixat seperator list
static String[] split(String args, String separator)
          Split string use 'separator' as separator.
static String substring(String s, int begin)
           
static String substring(String s, int begin, int end)
           
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)
           
static String unaccent(String s)
          Cette methode retire les accents.
static String uncapitalize(String word)
          Deprecated. you must use org.apache.commons.lang.StringUtils.uncapitalise(String)
static String unsplit(String[] s, String sep)
          Deprecated. you must use org.apache.commons.lang.StringUtils.join
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeFactors

protected static final double[] timeFactors

timeUnites

protected static final String[] timeUnites

memoryFactors

protected static final double[] memoryFactors

memoryUnites

protected static final String[] memoryUnites
Constructor Detail

StringUtil

protected StringUtil()
Constructor for the StringUtil object

Method Detail

unaccent

public static String unaccent(String s)
Cette methode retire les accents. Quand le caractere est connu, elle le remplace par une version sans accent sinon, elle le supprime. Les caracteres non-alphanumeriques sont supprimes.

Parameters:
s - la chaine a unaccentuer
Returns:
la chaine sans accent

substring

public static String substring(String s,
                               int begin)

substring

public static String substring(String s,
                               int begin,
                               int end)

capitalize

public static String capitalize(String word)
Deprecated. you must use org.apache.commons.lang.StringUtils.capitalise(String)

Met en majuscule le premier caractere de la chaine passee en parametre

Parameters:
word - La chaine a capitaliser
Returns:
La chaine capitalisee

uncapitalize

public static String uncapitalize(String word)
Deprecated. you must use org.apache.commons.lang.StringUtils.uncapitalise(String)

Met en minuscule le premier caractere de la chaine passe en parametre

Parameters:
word - La chaine a decapitaliser
Returns:
La chaine decapitalisee

unsplit

public static String unsplit(String[] s,
                             String sep)
Deprecated. you must use org.apache.commons.lang.StringUtils.join

Concatène un tableau de chaine de caracteres en une seul chaine.

Parameters:
s - le tableau de chaines
sep - le separateur a utiliser pour separer chaque chaine.
Returns:
la chaine resultante de la concatenation. Si le tableau est null ou vide, la chaine resultante est une chaine vide.

split

public static String[] split(String args,
                             String separator)
Split string use 'separator' as separator. If String contains "'()[]{} this method count the number of open char end close char to split correctly argument

Parameters:
args - string to split
separator - separator use to split string
Returns:
array of string

split

public static String[] split(String stringList)
Use to split string array representation in array according with swixat seperator list

Parameters:
stringList - string that represent array
Returns:
array with length > 0 if listAsString != null or null

split

public static String[] split(Character[] openingChars,
                             Character[] closingChars,
                             String args,
                             String separator)
Split string use 'separator' as separator. If String contains "' and openingChar closingChars

this method count the number of open char end close char to split correctly argument

Parameters:
openingChars - list of opening caracteres
closingChars - list of closing caracteres
args - string to split
separator - separator use to split string
Returns:
array of string

toBoolean

public static boolean toBoolean(String s)

toByte

public static byte toByte(String s)

toDouble

public static double toDouble(String s)

toFloat

public static float toFloat(String s)

toLong

public static long toLong(String s)

toShort

public static short toShort(String s)

toInt

public static int toInt(String s)

toChar

public static char toChar(String s)

toArrayBoolean

public static boolean[] toArrayBoolean(String... s)

toArrayByte

public static byte[] toArrayByte(String... s)

toArrayDouble

public static double[] toArrayDouble(String... s)

toArrayFloat

public static float[] toArrayFloat(String... s)

toArrayLong

public static long[] toArrayLong(String... s)

toArrayShort

public static short[] toArrayShort(String... s)

toArrayInt

public static int[] toArrayInt(String... s)

toArrayChar

public static char[] toArrayChar(String... s)

toColor

public static Color toColor(String s)
                     throws StringUtilException
Essai de convertir une chaine de caractere en une couleur si possible si ce n'est pas possible retourne null.

Parameters:
s - la couleur sous la forme de string, par exemple "red", "yellow" ou bien en RGB "#FFAA99", et avec un canal alpha "#FFAA3366"
Returns:
la couleur demandé si possible sinon null
Throws:
IllegalArgumentException
StringUtilException - if any problem while conversion

toDate

public static Date toDate(String s)
                   throws ParseException
Throws:
ParseException

convertTime

public static String convertTime(long value)
Parameters:
value -
Returns:
the memory representation of the given value
See Also:
convert(long, double[], String[])

convertTime

public static String convertTime(long value,
                                 long value2)
Parameters:
value -
value2 -
Returns:
the time representation of the given value
See Also:
convert(long, double[], String[])

convertMemory

public static String convertMemory(long value)
Parameters:
value -
Returns:
the memory representation of the given value
See Also:
convert(long, double[], String[])

convert

public 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).

Parameters:
value -
factors -
unites -
Returns:
the converted representation of the given value

checkEnclosure

public 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.

que les blocs définit par les deux caractères s'entrechevauchent pas.

Exemple avec '(' ')' :

(a(b)) est valide, par contre ((aaa))) n'est pas valide

Parameters:
txt - txte a verifier
opener - le caractère ouvrant
closer - le caractère fermant
Returns:
true is la chaine est valide

convertToConstantName

public 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.

Parameters:
name - le nom à convertir
Returns:
la constante générée


Copyright © 2004-2010 CodeLutin. All Rights Reserved.