LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.misc
Class LyTools

java.lang.Object
  extended by leon.misc.LyTools

public class LyTools
extends java.lang.Object

This class implements some basic conversion and utilities methods. Part of them are toString methods that convert objects to their string representation and fromString methods that build objects from a given string.


Field Summary
static java.lang.String __VERSION
           
static char ARRAY_SEP
          Separator used for Arrays.
static char BITSET_SEP
          Separator used for BitSets.
static char CLASS_SEP
          Separator used between class name and id.
static char OBJECT_SEP
          Separator used for applicative objects.
static char PIPE_SEP
          Separator used for strings in web.
static char VALUE_SEP
          Separator used between values of applicative objects.
static char VECTOR_SEP
          Separator used for Vectors.
 
Constructor Summary
LyTools()
           
 
Method Summary
static java.lang.Object[] ArrayFromString(java.lang.String value, java.lang.Class<?> classRef)
          Converts a string to an Array of objects.
static java.util.BitSet BitSetFromString(java.lang.String value)
          Converts a string to a BitSet.
static boolean booleanFromString(java.lang.String value)
          Converts a string to a boolean.
static java.lang.Boolean BooleanFromString(java.lang.String value)
          Converts a string to a Boolean.
static java.lang.String breakString(java.lang.String label, int maxChars)
          Break the line in label that exceed maxChars number.
static byte byteFromString(java.lang.String value)
          Converts a string to a byte.
static java.lang.Byte ByteFromString(java.lang.String value)
          Converts a string to a Byte.
static java.lang.Character CharacterFromString(java.lang.String value)
          Converts a string to a Character.
static char charFromString(java.lang.String value)
          Converts a string to a char.
static double checkDecimals(double value, int decimals)
          Checks the number of decimals of the given double.
static java.lang.String checkDecimals(java.lang.String value, int decimals)
          Checks the number of decimals of the given string representation of a number.
static java.util.Date DateFromString(java.lang.String value)
          Converts a string to a Date.
static double doubleFromString(java.lang.String value)
          Converts a string to a double.
static java.lang.Double DoubleFromString(java.lang.String value)
          Converts a string to a Double.
static double doubleFromString(java.lang.String value, double defaultValue)
          Converts a string to a double.
static java.lang.String encodeXmlTags(java.lang.String value)
          Encode Xml tags from a string to display it as Html.
static float floatFromString(java.lang.String value)
          Converts a string to a float.
static java.lang.Float FloatFromString(java.lang.String value)
          Converts a string to a Float.
static java.lang.String formatToHTML(java.lang.String tip, int maxCharPerLine)
          Used in swing component to replace multilined String by its equivalent in HTML.
static java.lang.String getIndentString()
           
static int getNextIdentifier()
          Gets next identifier and increments internal counter.
static double getPitch(double pitch, int decimals)
          Calculate a pitch according to a given number of decimals.
static char getSeparator(java.lang.Object object)
          Gets a separator depending on object type.
static java.lang.Integer IntegerFromString(java.lang.String value)
          Converts a string to an Integer.
static int intFromString(java.lang.String value)
          Converts a string to an int.
static boolean isDouble(java.lang.String str)
          Check if the given string can be parse as float or double
static long longFromString(java.lang.String value)
          Converts a string to a long.
static java.lang.Long LongFromString(java.lang.String value)
          Converts a string to a Long.
static double nextDouble()
          Gets the next random value as a double.
static float nextFloat()
          Gets the next random value as a float.
static int nextInt()
          Gets the next random value as an int.
static long nextLong()
          Gets next counter value and increments internal counter.
static short nextShort()
          Gets the next random value as a short.
static java.lang.String removeAccents(java.lang.String s)
          Removes accents from given string.
static java.lang.String removeChar(java.lang.String str, char character)
          Remove all occurrence of a specific character in a string
static java.lang.String removeExponent(java.lang.String value)
          Removes exponent from the given string representation of a double.
static java.lang.String removeHtmlTags(java.lang.String value)
          Remove tags from a string.
static short shortFromString(java.lang.String value)
          Converts a string to a short.
static java.lang.Short ShortFromString(java.lang.String value)
          Converts a string to a Short.
static java.lang.String toString(java.util.BitSet bs)
          Converts a BitSet to a string.
static java.lang.String toString(char c)
          Converts a character to a string.
static java.lang.String toString(java.util.Date date)
          Convert a date to a string.
static java.lang.String toString(java.lang.Object[] a)
          Returns a string representation of the contents of the specified array.
static java.util.Vector<java.lang.Object> VectorFromString(java.lang.String value, java.lang.Class<?> classRef)
          Converts a string to a vector.
static java.util.Vector<java.lang.Object> VectorFromString(java.lang.String value, java.lang.Class<?> classRef, char SEP)
          Converts a string to a vector.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
See Also:
Constant Field Values

OBJECT_SEP

public static final char OBJECT_SEP
Separator used for applicative objects.

See Also:
Constant Field Values

VALUE_SEP

public static final char VALUE_SEP
Separator used between values of applicative objects.

See Also:
Constant Field Values

VECTOR_SEP

public static final char VECTOR_SEP
Separator used for Vectors.

See Also:
Constant Field Values

ARRAY_SEP

public static final char ARRAY_SEP
Separator used for Arrays.

See Also:
Constant Field Values

BITSET_SEP

public static final char BITSET_SEP
Separator used for BitSets.

See Also:
Constant Field Values

CLASS_SEP

public static final char CLASS_SEP
Separator used between class name and id.

See Also:
Constant Field Values

PIPE_SEP

public static final char PIPE_SEP
Separator used for strings in web.

See Also:
Constant Field Values
Constructor Detail

LyTools

public LyTools()
Method Detail

toString

public static java.lang.String toString(char c)
Converts a character to a string.

Parameters:
c - the character to convert
Returns:
the string that represents this character.
See Also:
Character.toString(char)

toString

public static java.lang.String toString(java.util.Date date)
Convert a date to a string. Calls the method LyDateFormatter.format(date, "dd/MM/yyyy HH:mm:ss")

Parameters:
date - The date that must be converted.
Returns:
The string that represents the date.

toString

public static java.lang.String toString(java.util.BitSet bs)
Converts a BitSet to a string.

Parameters:
bs - The BitSet that must be converted.
Returns:
The string that represents the BitSet.

intFromString

public static int intFromString(java.lang.String value)
Converts a string to an int.

Parameters:
value - The string that must be parsed.
Returns:
The integer that represents the parsed string or 0 if not an int representation.

IntegerFromString

public static java.lang.Integer IntegerFromString(java.lang.String value)
Converts a string to an Integer.

Parameters:
value - The string that must be parsed.
Returns:
The Integer that represents the parsed string or null if not an Integer representation.

floatFromString

public static float floatFromString(java.lang.String value)
Converts a string to a float.

Parameters:
value - The string that must be parsed.
Returns:
The float that represents the parsed string or 0F if not a float representation.

FloatFromString

public static java.lang.Float FloatFromString(java.lang.String value)
Converts a string to a Float.

Parameters:
value - The string that must be parsed.
Returns:
The Float that represents the parsed string or null if not a Float representation.

doubleFromString

public static double doubleFromString(java.lang.String value)
Converts a string to a double. Calls doubleFromString(value, 0.0)

Parameters:
value - The string that must be parsed.
Returns:
The double that represents the parsed string or 0.0 if not a double representation.
See Also:
doubleFromString(String, double)

doubleFromString

public static double doubleFromString(java.lang.String value,
                                      double defaultValue)
Converts a string to a double.

Parameters:
value - The string that must be parsed.
defaultValue - The default value if it is not a double value.
Returns:
The double that represents the parsed string or the default value if not a double representation.
See Also:
DoubleFromString(String)

DoubleFromString

public static java.lang.Double DoubleFromString(java.lang.String value)
Converts a string to a Double.

Parameters:
value - The string that must be parsed.
Returns:
The Double that represents the parsed string or null if not a Double representation.

shortFromString

public static short shortFromString(java.lang.String value)
Converts a string to a short.

Parameters:
value - The string that must be parsed.
Returns:
The short that represents the parsed string or 0 if not a short representation.

ShortFromString

public static java.lang.Short ShortFromString(java.lang.String value)
Converts a string to a Short.

Parameters:
value - The string that must be parsed.
Returns:
The Short that represents the parsed string or null if not a Short representation.

longFromString

public static long longFromString(java.lang.String value)
Converts a string to a long.

Parameters:
value - The string that must be parsed.
Returns:
The long that represents the parsed string or 0L if not a long representation.

LongFromString

public static java.lang.Long LongFromString(java.lang.String value)
Converts a string to a Long.

Parameters:
value - The string that must be parsed.
Returns:
The Long that represents the parsed string or null if not a Long representation.

byteFromString

public static byte byteFromString(java.lang.String value)
Converts a string to a byte.

Parameters:
value - The string that must be parsed.
Returns:
The byte that represents the parsed string or 0 if not a byte representation.

ByteFromString

public static java.lang.Byte ByteFromString(java.lang.String value)
Converts a string to a Byte.

Parameters:
value - The string that must be parsed.
Returns:
The Byte that represents the parsed string or null if not a Byte representation.

booleanFromString

public static boolean booleanFromString(java.lang.String value)
Converts a string to a boolean.

Parameters:
value - The string that must be parsed.
Returns:
true if the string value equals "true",
See Also:
BooleanFromString(String)

BooleanFromString

public static java.lang.Boolean BooleanFromString(java.lang.String value)
Converts a string to a Boolean.

Parameters:
value - The string that must be parsed.
Returns:
The true Boolean object if the string value equals "true",

charFromString

public static char charFromString(java.lang.String value)
Converts a string to a char.

Parameters:
value - The string that must be parsed.
Returns:
The char that represents the parsed string or OBJECT_SEP if not a char representation.

CharacterFromString

public static java.lang.Character CharacterFromString(java.lang.String value)
Converts a string to a Character.

Parameters:
value - The string that must be parsed.
Returns:
The Character that represents the parsed string or null if not a Character representation.

DateFromString

public static java.util.Date DateFromString(java.lang.String value)
Converts a string to a Date.

Parameters:
value - The string that must be parsed. It must respect the date format 'dd/MM/yyyy HH:mm:ss'.
Returns:
The Date that represents the parsed string or null if not a Date representation.
See Also:
LyDateFormatter.parse(String, String)

ArrayFromString

public static java.lang.Object[] ArrayFromString(java.lang.String value,
                                                 java.lang.Class<?> classRef)
Converts a string to an Array of objects. The string must contain the objects representation separated by ARRAY_SEP.

Parameters:
value - The string that must be converted.
classRef - The class of the objects to create.
Returns:
The array of objects.
See Also:
VectorFromString(String, Class, char)

VectorFromString

public static java.util.Vector<java.lang.Object> VectorFromString(java.lang.String value,
                                                                  java.lang.Class<?> classRef)
Converts a string to a vector. The string must contain the objects representation separated by VECTOR_SEP. Only calls #VectorFromString(value, classRef, VECTOR_SEP)

Parameters:
value - The string that must be converted.
classRef - The class of the objects to create.
Returns:
The vector of objects.

VectorFromString

public static java.util.Vector<java.lang.Object> VectorFromString(java.lang.String value,
                                                                  java.lang.Class<?> classRef,
                                                                  char SEP)
Converts a string to a vector. The string must contain the objects representation separated by SEP parameter.

Parameters:
value - The string that must be converted.
classRef - The class of the objects to create.
SEP - the separator between values.
Returns:
The vector of objects.

BitSetFromString

public static java.util.BitSet BitSetFromString(java.lang.String value)
Converts a string to a BitSet. The string must contain the bits separated by BITSET_SEP.

Parameters:
value - The string that must be parsed.
Returns:
The BitSet that represents the parsed string or null if not a BitSet representation.

getNextIdentifier

public static int getNextIdentifier()
Gets next identifier and increments internal counter.

Returns:
The next identifier.

nextLong

public static long nextLong()
Gets next counter value and increments internal counter.

Returns:
The next counter value.

nextInt

public static int nextInt()
Gets the next random value as an int.

Returns:
the next random value
See Also:
Random.nextInt()

nextShort

public static short nextShort()
Gets the next random value as a short. Calls _random.nextInt(Short.MAX_VALUE)

Returns:
the next random value
See Also:
Random.nextInt(int)

nextFloat

public static float nextFloat()
Gets the next random value as a float.

Returns:
the next random value
See Also:
Random.nextFloat()

nextDouble

public static double nextDouble()
Gets the next random value as a double.

Returns:
the next random value
See Also:
Random.nextDouble()

checkDecimals

public static double checkDecimals(double value,
                                   int decimals)
Checks the number of decimals of the given double.

Parameters:
value - the double value to check
decimals - The number of decimals allowed. A negative value means no limit on number of decimals.
Returns:
A double value corresponding to the given value with the right number of decimals. For example the result of checkDecimals (3.454, 1) will be 3.4.

checkDecimals

public static java.lang.String checkDecimals(java.lang.String value,
                                             int decimals)
Checks the number of decimals of the given string representation of a number.

Parameters:
value - the string representation of the number to check
decimals - The number of decimals. A negative value means no limit on number of decimals.
Returns:
A substring of the given string with the right number of decimals. For example the result of checkDecimals (3.454, 1) will be 3.4.

removeChar

public static java.lang.String removeChar(java.lang.String str,
                                          char character)
Remove all occurrence of a specific character in a string

Parameters:
str - the source string
character - the character to remove
Returns:
a string without the given character

removeExponent

public static java.lang.String removeExponent(java.lang.String value)
Removes exponent from the given string representation of a double.

Parameters:
value - Initial value result of Double.toString
Returns:
Result without exponent.

getPitch

public static double getPitch(double pitch,
                              int decimals)
Calculate a pitch according to a given number of decimals.

Parameters:
pitch - The desired pitch.
decimals - The maximum number of decimals. For example the result of getPitch(0.04, 1) will be 0.1.
Returns:
the computed pitch

getSeparator

public static char getSeparator(java.lang.Object object)
Gets a separator depending on object type. Here are the correspondencies:

Parameters:
object - The object whose type we want to retrieve separator.
Returns:
The character that is used as separator for the given object type.

formatToHTML

public static java.lang.String formatToHTML(java.lang.String tip,
                                            int maxCharPerLine)
Used in swing component to replace multilined String by its equivalent in HTML.

Parameters:
tip - the original String to replace.
maxCharPerLine - maximum number of character in a line
Returns:
the equivalent String in HTML with "<p>" instead of "\n".

breakString

public static java.lang.String breakString(java.lang.String label,
                                           int maxChars)
Break the line in label that exceed maxChars number.

Parameters:
label - the label that must not exceed maxChar length
maxChars - the maximum number of characters of the label
Returns:
a breaked version of the label

toString

public static java.lang.String toString(java.lang.Object[] a)
Returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a

removeAccents

public static java.lang.String removeAccents(java.lang.String s)
Removes accents from given string.

Parameters:
str - Initial string.
Returns:
String without accents.

getIndentString

public static java.lang.String getIndentString()

encodeXmlTags

public static java.lang.String encodeXmlTags(java.lang.String value)
Encode Xml tags from a string to display it as Html.

Parameters:
value - the string that must be parsed
Returns:
the encoded string

removeHtmlTags

public static java.lang.String removeHtmlTags(java.lang.String value)
Remove tags from a string.

Parameters:
value - the string that must be parsed
Returns:
the string without tags parts

isDouble

public static boolean isDouble(java.lang.String str)
Check if the given string can be parse as float or double

Parameters:
str - the string to check
Returns:
true if the given string is a float or double, false otherwise

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com