public class Util
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.HashMap |
basicEntitiesDecodingMap |
static java.util.HashMap |
basicEntitiesEncodingMap |
static java.util.HashMap<java.lang.String,java.lang.String> |
cookieTransTable |
static java.util.TreeSet |
EMPTY_TREESET
The empty TreeSet (immutable).
|
static char |
ESCAPE_CHAR |
static int |
FILE_SIZE_UNIT_DIV |
protected static org.apache.oro.text.regex.Perl5Compiler |
hexaPercentCompiler |
protected static org.apache.oro.text.regex.Pattern |
hexaPercentPattern |
protected static org.apache.oro.text.regex.Perl5Substitution |
hexaPercentSubst |
static java.util.HashMap<java.lang.String,java.lang.String> |
isoLatin1_xml |
static java.util.HashMap<java.lang.String,java.lang.String> |
regexpEscaped1 |
static java.util.HashMap<java.lang.String,java.lang.String> |
regexpEscaped2 |
static java.util.HashMap<java.lang.String,java.lang.String> |
regexpEscaped3 |
static java.lang.String |
REVISION |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.Collection<T> |
addAll(java.util.Collection<T> collection,
java.util.Enumeration<T> enu)
Add all element of the enumerate to the collection
return the collection modified.
|
static <T> java.util.Collection<T> |
addAll(java.util.Collection<T> collection,
java.util.Iterator<T> it)
Add all element of the iterator to the collection
return the collection modified.
|
static <T> java.util.Collection<T> |
addAll(T[] array,
java.util.Collection<T> coll)
Copy all non-null objects from the given array to given
collection.
|
static <T> T[] |
addAll(T[] array1,
T... otherArrays)
Adds all the elements of the given arrays into a new array.
|
static <K,V> void |
addInMapHashSet(java.util.Map<K,java.util.Set<V>> map,
K key,
V value)
A convenient method that add the given value to a set bound to the given key in the given map.
|
static <K,V> void |
addInMapLinkedHashSet(java.util.Map<K,java.util.LinkedHashSet<V>> map,
K key,
V value)
A convenient method that add the given value to a set bound to the given key in the given map.
|
static boolean |
arrayContains(java.lang.Object[] array,
java.lang.Object key)
Test if an array contains a given object.
|
static java.lang.String |
asciiIndent(java.lang.String text,
int cols,
int rows,
java.lang.String tailString)
Indent a given text according a number of column and row.
|
static java.lang.String |
buildCamelID(java.lang.String str)
Build a Camel Case ID from the given String: remove the blanks,
unaccentuates, removes non-alphanum chars.
|
static java.lang.String |
buildID(java.lang.String str)
Build an ID from the given String: replaces the blanks with '_',
unaccentuates, removes non-alphanum chars and lowercases.
|
static java.lang.String |
buildID(java.lang.String str,
java.lang.String charRange)
Build an ID from the given String: replaces the blanks with '_',
unaccentuates, removes chars out of the given range and
lowercases.
|
static java.lang.String |
buildUID(java.lang.String str,
java.util.Set<java.lang.String> strSet)
Build an ID from the given String: replaces the blanks with '_',
unaccentuates, removes non-alphanum chars and lowercases.
|
static <T> java.util.Collection<T> |
cleanCollection(java.util.Collection<T> coll)
Remove the null entries of the given collection.
|
static java.lang.Object[] |
cleanObjectArray(java.lang.Object[] array)
Creates a new array that contains all elements of the given array without null.
|
static java.lang.String[] |
cleanStringArray(java.lang.String[] array)
Creates a new array that contains all elements of the given array except
empty Strings (ie null or empty).
|
static <T> java.util.Set<T> |
collectionToCleanSet(java.util.Collection<T> coll)
Returns a set which contains all the non empty element of the given collection.
|
static <K,V> java.util.Map.Entry<K,V> |
compareMap(java.util.Map<K,V> map1,
java.util.Map<K,V> map2)
Returns the first common Map.Entry of the given maps.
|
static java.lang.String |
conceal(java.lang.String clearStr)
Conceal the given string with an internally choosen encryption algorithm.
|
static long |
convertFileSizeWidgetElt(java.lang.String value,
java.lang.String unit)
Convert a size value and the unit in which it is expressed into a file size expressed in bytes.
|
static java.lang.String |
cryptMD5(java.lang.String str)
Encrypt the given string with the MD5 algorithm and BASE64
|
static java.lang.String |
cryptUnix(java.lang.String str)
Encrypt the given string with the Unix crypt algorithm
|
static java.lang.String |
decodeBASE64(java.lang.String str)
Decode the given string using BASE64 algorithm
|
static java.lang.String |
decodeCookie(java.lang.String src) |
static java.lang.String |
decodeHtmlBasicEntities(java.lang.String src)
Does the opposite job of encodeHtmlBasicEntities.
|
static int[] |
decodeIntArray(java.lang.String param) |
static int[] |
decodeIntArray(java.lang.String param,
char separator) |
static java.lang.Object |
decodeObject(java.lang.String encoded)
Returns the object decoded from the given String.
|
static java.lang.String[] |
decodeStringArray(java.lang.String param) |
static java.lang.String[] |
decodeStringArray(java.lang.String param,
char separator) |
static java.lang.String |
decodeUrl(java.lang.String str) |
static java.lang.String |
decryptDES3(java.lang.String encryptedStr)
Decrypt the specified string using DESede
StringEncrypter using same internal key
used by encryptDES3(String) . |
static <T> java.util.TreeSet<T> |
emptyTreeSet()
Returns the empty TreeSet (immutable).
|
static java.lang.String |
encodeBASE64(java.lang.String str)
Encode the given string using BASE64 algorithm.
|
static java.lang.String |
encodeBASE64(java.lang.String str,
boolean isChunck)
Encode the given string using BASE64 algorithm.
|
static java.lang.String |
encodeCookie(java.lang.String src) |
static java.lang.String |
encodeHtmlBasicEntities(java.lang.String src)
Encode given string according to the following table.
|
static java.lang.String |
encodeIntArray(int[] array) |
static java.lang.String |
encodeIntArray(int[] array,
char separator) |
static java.lang.String |
encodeJavaScriptQuote(java.lang.String str)
Deprecated.
use com.jalios.jcms.HttpUtil.encodeForJavaScript
|
static java.lang.String |
encodeObject(java.lang.Object obj)
Returns the encoded objected as a String.
|
static java.lang.String |
encodeStringArray(java.lang.String[] array) |
static java.lang.String |
encodeStringArray(java.lang.String[] array,
char separator) |
static java.lang.String |
encodeUrl(java.lang.String s)
Same implementation as
URLEncoder.encode(String, String) ,
but space is encoded with %20 and '/' is not encoded. |
static java.lang.String |
encodeUrl(java.lang.String s,
java.lang.String enc)
Same implementation as
URLEncoder.encode(String, String) ,
but space is encoded with %20 and '/' is not encoded. |
static java.lang.String |
encryptDES3(java.lang.String clearStr)
Encrypt the specified string using DESede
StringEncrypter with an internal key. |
static java.lang.String |
entitiesToIsoLatin1(java.lang.String src)
Does the opposite of isoLatin1ToEntities.
|
static java.lang.String |
escapeBackslash(java.lang.String str)
Escape all the '\' in the given String ('\\')
|
static java.lang.String |
escapeChars(java.lang.String str,
java.lang.String charsToEscape)
Escape specified characters in a String.
|
static java.lang.String |
escapeHtml(java.lang.String str)
Escapes some special HTML characters such as <, >, &
and ".
|
static java.lang.String |
escapeHtmlQuote(java.lang.String str)
Deprecated.
use com.jalios.jcms.HttpUtil.encodeFor[HTML|HTMLAttribute|Javascript] depending on the context
|
static java.lang.String |
escapeInputQuote(java.lang.String str)
Deprecated.
use com.jalios.jcms.HttpUtil.encodeFor[HTML|HTMLAttribute|Javascript] depending on the context
|
static java.lang.String |
escapeJavaScriptQuote(java.lang.String str)
Deprecated.
use com.jalios.jcms.HttpUtil.encodeForJavaScript
|
static java.lang.String |
escapeJavaStringChar(java.lang.String str)
Escape all the invalide char in Java String:
'\' -> "\\"
CR -> "\n"
'"' -> \"
|
static java.lang.String |
escapeLuceneQuery(java.lang.String str)
Escape Lucene special chars.
|
static java.lang.String |
escapePercent(java.lang.String url)
This method replace % in wrong hexa character
by '_' character
|
static java.lang.String |
escapeRegexp(java.lang.String string)
Escape a (OROMatcher) regular expression with support of basic
regexp (* and ?).
|
static java.lang.String |
escapeRegexp(java.lang.String string,
boolean basicRegexp)
Escape a (OROMatcher) regular expression with support of basic
regexp (* and ?).
|
static int |
exec(java.util.List<java.lang.String> cmdList)
Executes the specified command and arguments in a separate process.
|
static int |
exec(java.lang.String... cmdarray)
Executes the specified command and arguments in a separate process.
|
static int |
exec(java.lang.String[] cmdarray,
java.io.OutputStream stdout,
java.io.OutputStream stderr)
Executes the specified command and arguments in a separate process.
|
static int |
exec(java.lang.String[] cmdarray,
java.lang.StringBuilder stdout,
java.lang.StringBuilder stderr)
Executes the specified command and arguments in a separate process.
|
static boolean |
forceFullGarbageCollection(long timeout)
Force the garbage collection
|
static java.lang.String |
formatDuration(java.util.Date begin,
java.util.Date end)
Deprecated.
Use
DateUtil.formatDuration(Date,Date) instead |
static java.lang.String |
formatDuration(java.util.Date begin,
java.util.Date end,
java.util.Locale locale)
Deprecated.
Use
DateUtil.formatDuration(Date,Date,Locale) instead |
static java.lang.String |
formatDuration(long time)
Deprecated.
Use
DateUtil.formatDuration(long) instead |
static java.lang.String |
formatDuration(long time,
java.util.Locale locale)
Deprecated.
Use
DateUtil.formatDuration(long,Locale) instead |
static java.lang.String |
formatFileSize(long size)
This method format the given size on the greatest unit.
|
static java.lang.String |
formatFileSize(long size,
java.util.Locale locale)
This method format the given size on the greatest unit.
|
static java.lang.String |
formatFileSize(long size,
java.util.Locale locale,
boolean htmlDisplay)
This method format the given size on the greatest unit.
|
static java.lang.String |
formatIso8601Date(java.util.Date date)
Deprecated.
Use
DateUtil.formatIso8601Date(Date) instead |
static java.lang.String |
formatNoSpaceDate(java.util.Date date)
Deprecated.
Use
DateUtil.formatNoSpaceDate(Date) instead |
static java.lang.String |
formatRfc822Date(java.util.Date date)
Deprecated.
Use
DateUtil.formatRfc822Date(Date) instead |
static java.lang.String |
formatSize(long size,
java.util.Locale locale)
This method format the given size on the greatest unit.
|
static java.lang.String |
formatW3cDate(java.util.Date date)
Deprecated.
Use
DateUtil.formatW3cDate(Date) instead |
static java.lang.String |
generatePassword()
Generates a basic password (consonnants / voyels) of 8 characters.
|
static java.lang.String |
generatePassword(int length)
Generates a basic password (consonnants / voyels) of the specified length.
|
static java.lang.String |
generatePronounceablePassword(int pwdLength)
Generates pronounceable passwords of specified length.
|
static java.util.Set |
getAllChildren(TreeNode node,
java.util.Set nodeSet)
Fill the given set with every children of the given treenode, including the node itself,
returns the filled set.
|
static java.util.TreeSet |
getAllChildrenSet(TreeNode node)
Returns a TreeSet with all children of the given treenode, (including the node itself)
|
static <T> java.util.ArrayList<T> |
getArrayList(boolean skipNull,
boolean trim,
T... array) |
static <T> java.util.ArrayList<T> |
getArrayList(T... array)
Returns a new ArrayList filled with the given objects (skip null object).
|
static <T> java.util.Set<java.util.Set<T>> |
getBatchSet(java.util.Collection<T> coll,
int batchSize)
Convenient method to convert a Collection of object into many smaller
collections allowing batch processing.
|
static boolean |
getBoolean(boolean[] array,
int index,
boolean defaultValue) |
static byte[] |
getBytesUtf8(java.lang.String string)
Encodes the specified
String into a sequence of bytes using the given
UTF-8 charset, storing the result into a
new byte array. |
static java.lang.Object |
getChildListMap(java.util.Map map,
java.lang.String key)
Returns the first Value matching the given key
|
static java.util.List |
getChildrenListMap(java.util.Map map,
java.lang.String key)
Returns values matching the given key.
|
static java.util.List |
getChildrenListMap(java.util.Map map,
java.lang.String[] keys)
Returns a new List of values matching the ordered given keys.
|
static java.util.Set<java.lang.String> |
getClassFiles(java.lang.String realPath,
java.lang.String fullname,
boolean java)
Returns a Set of relative path to all class files including inner class and java.
|
static java.lang.String |
getClassNameFromFilename(java.lang.String filename)
Returns the class name from the filename of a class (e.g. it returns "com.jalios.util.Util" for "com/jalios/util/Util.class")
|
static java.lang.String |
getClassShortName(java.lang.Class clazz)
Returns the short name of the given class (e.g.
|
static java.lang.String |
getClassShortName(java.lang.Object object)
Returns the short name of the given object's class (e.g.
|
static java.lang.String |
getClassShortName(java.lang.String fullname)
Returns the short name of the given class name (e.g.
|
static java.lang.Class<?> |
getCommonSuperClass(java.lang.Class<?>... classes)
Retrieve the common super class of the specified classes.
|
static java.lang.String |
getCurrentStackTrace()
Returns the current StackTrace in a String.
|
static java.lang.String[] |
getFileSizeUnitLabels(java.util.Locale locale)
Retrieve an array containing I18Ned labels to express file size, from bytes to terabytes.
|
static java.lang.String[] |
getFileSizeWidgetElt(long size)
Convert a file size to a rounded value with a size as a string
and the unit in which it is expressed (units are in english).
|
static <T> T |
getFirst(java.util.Collection<T> coll)
Returns the first item of the given collection (or null if the collection is empty).
|
static <T> T |
getFirst(T[] array)
Returns the first item of the given array (or null if the array is empty).
|
static java.lang.Class |
getFirstCommonClass(java.lang.Class parent,
java.lang.Class child)
Follow class tree of parent to find a class or an interface that is also
parent of the child.
|
static java.lang.String |
getFirstSentences(java.lang.String text,
int limit)
Get the first sentences in a given string.
|
static <K,V> java.util.HashMap<K,V> |
getHashMap(K key,
V value)
Returns a new HashMap filled with the given key/value pair (if the key is not null).
|
static <K,V> java.util.HashMap<K,V> |
getHashMap(java.util.Map<K,V> map)
Returns a new HashMap filled with the given map (if it is not null)
|
static <T> java.util.HashSet<T> |
getHashSet(T... array)
Returns a new HashSet filled with the given objects (skip null object).
|
static java.lang.String |
getHtmlIcon(java.lang.String src,
java.lang.String alt)
Deprecated.
use com.jalios.util.HtmlUtil.getHtmlIcon
|
static int |
getInt(int[] array,
int index,
int defaultValue) |
static <K,V> java.lang.Object |
getKey(java.util.Map<K,V> map,
V value)
Iterate over a Map, looking for a Key associated to a given value.
|
static <K,V> java.util.Set<K> |
getKeys(java.util.Map<K,V> map,
V value)
Iterate over a Map, looking for a Keys associated to a given value.
|
static <T> T |
getLast(java.util.List<T> list)
Returns the last item of the given List (or null if the List is empty).
|
static <T> T |
getLast(java.util.SortedSet<T> set)
Returns the last item of the given SortedSet (or null if the SortedSet is empty).
|
static <T> T |
getLast(T[] array)
Returns the last item of the given array (or null if the array is empty).
|
static <K,V> java.util.LinkedHashMap<K,V> |
getLinkedHashMap(K key,
V value)
Returns a new LinkedHashMap filled with the given key/value pair (if the key is not null).
|
static <K,V> java.util.LinkedHashMap<K,V> |
getLinkedHashMap(java.util.Map<K,V> map)
Returns a new LinkedHashMap filled with the given map (if it is not null)
|
static java.lang.String |
getMatch(java.util.regex.Pattern pattern,
java.lang.String str,
int group)
Return the group matching the given regexp for the given String or null if
do not match or exception happens
|
static java.lang.String |
getMatch(java.lang.String regexp,
java.lang.String str,
int group)
Return the group matching the given regexp for the given String or null if
do not match or exception happens
|
static java.util.Date |
getNewDateWithoutMillis()
Deprecated.
Use
DateUtil.getNewDateWithoutMillis() instead |
static java.lang.Object |
getObject(java.lang.Object[] array,
int index,
java.lang.Object defaultValue) |
static java.util.Set<java.lang.String> |
getPackageClassFiles(java.lang.String realPath,
java.lang.String fullPackage,
boolean sources,
java.lang.String excludesPattern)
Returns a Set of relative path to all class files including inner class and java.
|
static int |
getSize(boolean[] array)
Returns the size of the given array.
|
static int |
getSize(byte[] array)
Returns the size of the given array.
|
static int |
getSize(char[] array)
Returns the size of the given array.
|
static int |
getSize(java.util.Collection coll)
Returns the size of the given collection.
|
static int |
getSize(double[] array)
Returns the size of the given array.
|
static int |
getSize(float[] array)
Returns the size of the given array.
|
static int |
getSize(int[] array)
Returns the size of the given array.
|
static int |
getSize(long[] array)
Returns the size of the given array.
|
static int |
getSize(java.util.Map map)
Returns the size of the given map.
|
static int |
getSize(java.lang.Object[] array)
Returns the size of the given array.
|
static int |
getSize(short[] array)
Returns the size of the given array.
|
static int |
getSize(java.lang.String str)
Returns the size of the given String.
|
static java.lang.String |
getStackTrace(java.lang.Throwable throwable)
This method print the stack trace into a String and return it.
|
static java.lang.String |
getString(java.lang.Object[] array,
int index,
java.lang.String defaultValue)
Call the method getString() with the Object in the array specified at the given index.
|
static java.lang.String |
getString(java.lang.Object obj,
java.lang.String defaultValue)
Return the String representation of the given object if it is not
null nor empty, otherwise it returns the default value.
|
static java.lang.String |
getStringUtf8(byte[] bytes)
Decode the specified array of bytes into a new
String using the UTF-8 charset. |
static java.util.List |
getSuperclassList(java.lang.Class clazz,
java.lang.Class ancestor,
boolean addClass,
boolean addAncestor)
Returns a list of classes the given class is an ancestor of.
|
static java.util.TreeSet |
getTreeDescendantSet(TreeNode node)
Returns a TreeSet with all descendant of the given treenode, (excluding the node itself)
|
static java.util.Set |
getTreeDescendantSet(TreeNode node,
java.util.Set nodeSet) |
static <K,V> java.util.TreeMap<K,V> |
getTreeMap(K key,
V value)
Returns a new TreeMap filled with the given key/value pair (if the key is not null).
|
static <K,V> java.util.TreeMap<K,V> |
getTreeMap(java.util.Map<K,V> map)
Returns a new TreeMap filled with the given map (if it is not null)
|
static <T> java.util.TreeSet<T> |
getTreeSet(T... array)
Returns a new TreeSet filled with the given objects (skip null object).
|
static boolean |
hasAppenderDefined(org.apache.log4j.Logger logger)
Checks if the given
Logger has any appender defined. |
static java.lang.String |
html2Ascii(java.lang.String str)
Convert the specified string from HTML to raw text, preserving and converting as much
spaces as possibles (space, <br>, carriage return, line feeds, ...).
|
static java.lang.String |
html2text(java.lang.String html)
Deprecated.
|
static int |
indexOf(java.lang.Object elem,
java.lang.Object[] array)
Searches for the first occurence of the given argument in a given array, testing
for equality using the equals method.
|
static boolean[] |
insertArray(boolean[] array,
int index,
boolean elt)
Insert an element into a boolean array and return a duplicate copy of it.
|
static int[] |
insertArray(int[] array,
int index,
int elt)
Insert an element into an int array and return a duplicate copy of it.
|
static java.lang.Object[] |
insertArray(java.lang.Object[] array,
int index,
java.lang.Object elt)
Insert an element into an Object array and return a duplicate copy of it.
|
static <K,V> java.util.Map<? extends K,? extends V> |
interMap(java.util.Map<? extends K,? extends V> map,
java.util.Set<? extends K> keys)
This method will return a new Map containing only values of specified
map with given keys.
|
static java.util.Set |
interSet(java.util.Set... sets)
Returns the intersection of an array of
Set . |
static java.util.Set |
interSet(java.util.Set set1,
java.util.Set set2)
Returns the intersection of two
Set . |
static java.util.Set |
interSet(java.util.Set set1,
java.util.Set set2,
java.util.Set set3)
Returns the intersection of three
Set . |
static boolean |
isChildNode(TreeNode node,
TreeNode child)
Test if a node is a child of an other node
Return false if child == node |
static boolean |
isEmpty(boolean[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(byte[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(char[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(java.util.Collection<?> c)
Returns
true if this collection is
null or empty. |
static boolean |
isEmpty(java.util.Collection<?> c,
boolean deep)
Returns
true if this collection is
null or empty. |
static boolean |
isEmpty(double[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(java.io.File file)
Returns
true if this file is
null or empty. |
static boolean |
isEmpty(java.io.File file,
java.io.FileFilter fileFilter)
Returns
true if this file is
null or empty. |
static boolean |
isEmpty(float[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(int[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(long[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(java.util.Map<?,?> map)
Returns
true if this map is
null or empty. |
static boolean |
isEmpty(java.lang.Object object)
Returns
true if this object is
null or empty. |
static boolean |
isEmpty(java.lang.Object[] array)
Returns
true if this array is
null or empty. |
static boolean |
isEmpty(java.lang.Object[] array,
boolean recursive)
Returns
true if this array is
null or empty. |
static boolean |
isEmpty(short[] array)
Returns
true if this array is null or empty. |
static boolean |
isEmpty(SQLQueryResult sqr)
Returns
true if this SQLQueryResult is
null or empty. |
static boolean |
isEmpty(java.lang.String s)
Returns
true if this string is null or
empty (once trimmed). |
static <K,V> boolean |
isMapFilled(java.util.Map<K,V> map)
Returns true if the given map contains at least one value not empty.
|
static boolean |
isNumber(java.lang.String str)
Returns true if the given string only contains 0-9 characters
|
static java.lang.String |
isoLatin1ToEntities(java.lang.String src)
Convert all the isoLatin1 accent into XML entities (e.g.
|
static boolean |
isSameContent(boolean[] array1,
boolean[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(byte[] array1,
byte[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(char[] array1,
char[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(java.util.Date date1,
java.util.Date date2)
Returns true if date1 has same content than date2.
|
static boolean |
isSameContent(double[] array1,
double[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(org.jdom.Element elt1,
org.jdom.Element elt2)
Returns true if elt1 has same content than elt2.
|
static boolean |
isSameContent(float[] array1,
float[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(int[] array1,
int[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(java.util.List list1,
java.util.List list2)
Returns true if list1 has same content than list2.
|
static boolean |
isSameContent(long[] array1,
long[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(java.util.Map map1,
java.util.Map map2)
Returns true if map1 has same content than map2.
|
static boolean |
isSameContent(java.lang.Object[] array1,
java.lang.Object[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(java.util.Set set1,
java.util.Set set2)
Returns true if set1 has same content than set2.
|
static boolean |
isSameContent(short[] array1,
short[] array2)
Returns true if array1 has same content than array2.
|
static boolean |
isSameContent(java.lang.String str1,
java.lang.String str2)
Returns true if str1 has same content than str2.
|
static boolean |
isSameDay(java.util.Date date1,
java.util.Date date2)
Deprecated.
Use
DateUtil.isSameDay(Date,Date) instead |
static boolean |
isToday(java.util.Date date)
Deprecated.
Use
DateUtil.isToday(Date) instead |
static boolean |
isTomorrow(java.util.Date date)
Deprecated.
Use
DateUtil.isTomorrow(Date) instead |
static boolean |
isYesterday(java.util.Date date)
Deprecated.
Use
DateUtil.isYesterday(Date) instead |
static java.lang.String |
join(boolean[] array,
java.lang.String sep)
Joins an array of boolean with the given separator.
|
static java.lang.String |
join(boolean[] array,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins an array of boolean with the given separator.
|
static java.lang.String |
join(java.util.Collection<?> col,
java.lang.String sep)
Joins a collection of Object with the given separator into a
String.
|
static java.lang.String |
join(java.util.Collection<?> col,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins a collection of Object with the given separator into a
String.
|
static java.lang.String |
join(double[] array,
java.lang.String sep)
Joins an array of double with the given separator.
|
static java.lang.String |
join(double[] array,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins an array of double with the given separator.
|
static java.lang.String |
join(int[] array,
java.lang.String sep)
Joins an array of int with the given separator.
|
static java.lang.String |
join(int[] array,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins an array of int with the given separator.
|
static java.lang.String |
join(java.util.Iterator<?> it,
java.lang.String sep)
Joins a collection of Object with the given separator into a
String.
|
static java.lang.String |
join(java.util.Iterator<?> it,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins a collection of Object with the given separator into a
String.
|
static java.lang.String |
join(long[] array,
java.lang.String sep)
Joins an array of long with the given separator.
|
static java.lang.String |
join(long[] array,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins an array of long with the given separator.
|
static java.lang.String |
join(java.lang.Object[] array,
java.lang.String sep)
Joins an array of String with the given separator.
|
static java.lang.String |
join(java.lang.Object[] array,
java.lang.String sep,
int max,
java.lang.String suffix)
Joins an array of String with the given separator.
|
static java.lang.String |
join(java.lang.String... str)
Join String with a given separator
First String is the separator
Always return a String
If Str1 or Str2 is null then return the other value without separator
|
static java.lang.String |
joinMap(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map,
java.lang.String keyValueSep,
java.lang.String entrySep)
Joins the entries of a map into a String.
|
static void |
listDictionary(java.util.Dictionary<?,?> dict)
Lists a Dictionnary on
System.out . |
static void |
listDictionary(java.util.Dictionary<?,?> dict,
java.io.PrintStream out)
Lists a Dictionnary on the given
PrintStream . |
static void |
listDictionary(java.util.Dictionary<?,?> dict,
java.io.PrintStream out,
java.lang.String sep)
Lists a dictionnary on the given
PrintStream with
the given separator. |
static void |
listMap(java.util.Map<?,?> map)
Lists a map on
System.out . |
static void |
listMap(java.util.Map<?,?> map,
java.io.PrintStream out)
Lists a map on the given
PrintStream . |
static void |
listMap(java.util.Map<?,?> map,
java.io.PrintStream out,
java.lang.String sep)
Lists a map on the given
PrintStream with the given
separator. |
static void |
mainRemoveArray(java.lang.String[] args) |
static void |
mainSwapArray(java.lang.String[] args) |
static void |
mainTestBuildID(java.lang.String[] args) |
static void |
mainTestEmpty(java.lang.String[] args) |
static void |
mainTestEscapeLuceneQuery(java.lang.String[] args) |
static void |
mainTestFormatDuration(java.lang.String[] args)
Deprecated.
Use
DateUtil.mainTestFormatDuration(String[]) instead |
static void |
mainTestGeneratePassword(java.lang.String[] args) |
static void |
mainTestJoin(java.lang.String[] args) |
static boolean |
notEmpty(java.util.Collection<?> c)
Returns
true if this collection is not
null nor empty. |
static boolean |
notEmpty(java.io.File file)
Returns
true if this File is not
null nor empty. |
static boolean |
notEmpty(java.io.File file,
java.io.FileFilter fileFilter)
Returns
true if this File is not
null nor empty. |
static boolean |
notEmpty(int[] array)
Returns
true if this array is not null nor empty. |
static boolean |
notEmpty(java.util.Map<?,?> map)
Returns
true if this map is not
null nor empty. |
static boolean |
notEmpty(java.lang.Object object)
Returns
true if this object is not
null nor empty. |
static boolean |
notEmpty(java.lang.Object[] array)
Returns
true if this array is not
null nor empty. |
static boolean |
notEmpty(java.lang.Object[] array,
boolean recursive)
Returns
true if this array is not
null nor empty. |
static boolean |
notEmpty(SQLQueryResult map)
Returns
true if this SQLQueryResult is not
null nor empty. |
static boolean |
notEmpty(java.lang.String s)
Returns
true if this string is not null
nor empty (once trimmed). |
static java.util.Date |
parseIso8601Date(java.lang.String source)
Deprecated.
Use
DateUtil.parseIso8601Date(String) instead |
static java.util.Date |
parseNoSpaceDate(java.lang.String source)
Deprecated.
Use
DateUtil.parseNoSpaceDate(String) instead |
static java.util.Date |
parseRfc822Date(java.lang.String source)
Deprecated.
Use
DateUtil.parseRfc822Date(String) instead |
static java.util.Date |
parseW3cDate(java.lang.String source)
Deprecated.
Use
DateUtil.parseW3cDate(String) instead |
static java.lang.String |
performDecoding(java.lang.String src,
java.util.HashMap transMap)
Replace all occurences of values found in transMap with their assiocated keys.
|
static java.lang.String |
performEncodeDecode(java.lang.String src,
java.util.HashMap transMap,
boolean decode)
Encode or decode the given String using the given translation Map.
|
static java.lang.String |
performEncoding(java.lang.String src,
java.util.HashMap transMap)
Replace all occurences of keys found in transMap with their assiocated values.
|
static java.util.Set<java.lang.String> |
prefixSet(java.util.Set<java.lang.String> set,
java.lang.String prefix)
Prefix all elements of a Set of String
with a given prefix
|
static <K,V> java.util.Map<K,V> |
putAll(K[] array,
java.util.Map<K,V> map,
V value)
Copy all non-null objects from the given array to given
map with a given value.
|
static java.lang.String |
randomString(int length) |
static java.lang.String |
recapitalize(java.lang.String str)
Force the first char of a String to be a uppercase char.
|
static java.lang.String |
reduceBlankLines(java.lang.String text)
Right trim all the lines in the message and reduced many CRLF to only one line.
|
static boolean[] |
removeArray(boolean[] array,
int index)
Remove an element of an Array of boolean
|
static boolean[] |
removeArray(boolean[] array,
int from,
int to)
Remove n elements of an Array of boolean
|
static int[] |
removeArray(int[] array,
int index)
Remove an element of an Array of int
|
static int[] |
removeArray(int[] array,
int from,
int to)
Remove n elements of an Array of int
|
static java.lang.Object[] |
removeArray(java.lang.Object[] array,
int index)
Remove an element of an Array of object
|
static java.lang.Object[] |
removeArray(java.lang.Object[] array,
int from,
int to)
Remove n elements of an Array of object
|
static java.lang.Object[] |
removeArray(java.lang.Object[] array,
java.lang.Object obj)
Remove an element of an Array of object
|
static java.lang.String |
removeBlankLines(java.lang.String str)
Cleans the given string : remove pure blank lines and remove leadings white spaces.
|
static <K,V> void |
removeFromMapHashSet(java.util.Map<K,java.util.Set<V>> map,
K key,
V value)
A convenient method that remove the given value to a set bound to the given key in the given map.
|
static <K,V> void |
removeFromMapLinkedHashSet(java.util.Map<K,java.util.LinkedHashSet<V>> map,
K key,
V value)
A convenient method that remove the given value to a set bound to the given key in the given map.
|
static java.lang.String |
removeJavaScriptQuote(java.lang.String str)
Deprecated.
use com.jalios.jcms.HttpUtil.encodeForJavaScript
|
static java.lang.String |
repeat(java.lang.String pattern,
int count)
Repeat a String pattern
count times |
static java.lang.String |
replace(java.lang.String text,
org.apache.oro.text.regex.Pattern pattern,
RegexpSubstitution substitution)
Replaces the given pattern in the given text with the given substitution function.
|
static java.lang.String |
replace(java.lang.String str,
java.lang.String pattern)
Search and replace a string by another one
|
static java.lang.String |
replace(java.lang.String text,
java.lang.String regexp,
RegexpSubstitution substitution)
Replaces the given regexp in the given text with the given substitution function.
|
static java.lang.String |
replace(java.lang.String str,
java.lang.String match,
java.lang.String rep)
Search and replace a string by another one (Note the input string
must not contains '#' char)
|
static java.lang.String |
replaceAll(java.lang.String input,
java.lang.String searchString,
java.lang.String replaceString)
Replace all occurence of searchString with replaceString in input string.
|
static java.lang.String |
reveal(java.lang.String concealedStr)
Reveal the specified hidden string with an internally choosen encryption algorithm.
|
static <K,V> java.util.Map<V,K> |
reverseMap(java.util.Map<K,V> originalMap,
java.util.Map<V,K> reverseMap)
Fill the reverse map with the original map replacing keys by values and values by keys.
|
static long |
roundDuration(long duration)
Deprecated.
Use
DateUtil.roundDuration(long) instead |
static java.lang.String[] |
split(java.lang.String str,
char delim,
java.lang.String emptyToken)
Splits a String into an array of String.
|
static java.lang.String[] |
split(java.lang.String str,
java.lang.String delim)
Splits a String into an array of String.
|
static int[] |
splitToIntArray(java.lang.String str,
java.lang.String delim)
Splits a String into an array of int.
|
static java.util.ArrayList<java.lang.String> |
splitToList(java.lang.String str,
java.lang.String delim)
Splits a String into a list of String.
|
static java.lang.String[] |
splitWithPattern(java.lang.String text,
java.lang.String pattern)
Splits a String according a given pattern and returns an array of String.
|
static java.lang.String |
startsWith(java.lang.String str,
java.util.Collection<java.lang.String> coll)
Returns the String in the given collection that
is a starting string og given str
|
static java.util.Set<java.lang.String> |
stringArrayToCleanSet(java.lang.String[] array)
Returns a set which contains all the non empty cells of the given array.
|
static <K,V> java.util.Map<K,V> |
subMap(java.util.Map<K,V> map,
java.util.Set<K> keys)
This method will return a new Map containing all values of specified
map without given keys.
|
static java.util.Set |
subSet(java.util.Set... sets)
Returns the subset of an array of
Set . |
static java.util.Set |
subSet(java.util.Set set1,
java.util.Set set2)
Returns the subset of an array of
Set . |
static java.util.Set |
subSet(java.util.Set set1,
java.util.Set set2,
java.util.Set set3)
Returns the subset of an array of
Set . |
static java.lang.String |
surround(java.lang.String inside,
java.lang.String begin,
java.lang.String end)
Surround a given text (the first argument) with the two other arguments, only if the given text is not empty.
|
static java.lang.String |
surroundWithTag(java.lang.String inside,
java.lang.String tag)
Surround a given text (the first argument) with a html tag.
|
static boolean[] |
swapArray(boolean[] array,
int from,
int to,
boolean roll,
boolean copy)
Swap two cells of a boolean array.
|
static int[] |
swapArray(int[] array,
int from,
int to,
boolean roll,
boolean copy)
Swap two cells of an int array.
|
static java.lang.Object[] |
swapArray(java.lang.Object[] array,
int from,
int to,
boolean roll,
boolean copy)
Swap two cells of an Object array.
|
static boolean |
toBoolean(java.lang.Object obj,
boolean def)
Convert an Object (assert to be either a String or a Boolean) to a boolean
|
static byte |
toByte(java.lang.Object obj,
byte def)
Convert an Object (assert to be either a
String or a Byte ) to a byte |
static char |
toChar(java.lang.Object obj,
char def)
Convert an Object (assert to be either a
String or a Character ) to a char |
static java.util.Date |
toDate(java.lang.String str,
java.lang.String format,
java.util.Locale loc,
java.util.Date def)
Parse a String and Convert it into a Date
|
static double |
toDouble(java.lang.Object obj,
double def)
Convert an Object (assert to be either a
String or a Double ) to a double |
static float |
toFloat(java.lang.Object obj,
float def)
Convert an Object (assert to be either a
String or a Float ) to a float |
static int |
toInt(java.lang.Object obj,
int def)
Convert an Object (assert to be either a
String or a Integer ) to a int |
static int[] |
toIntArray(java.lang.Object[] objs,
int def)
Convert an Object[] (assert to be either a
String or a Integer ) to a int |
static java.util.Locale |
toLocale(java.lang.String str,
java.util.Locale def)
Deprecated.
|
static long |
toLong(java.lang.Object obj,
long def)
Convert an Object (assert to be either a
String or a Long ) to a long |
static short |
toShort(java.lang.Object obj,
short def)
Convert an Object (assert to be either a
String or a Short ) to a short |
static java.lang.String |
toWordLine(java.lang.String str)
Split a text in a String with one word by line (used for diffing 2 strings at word level).
|
static java.lang.String[] |
trim(java.lang.String[] array)
Remove the trailing empty cells of the given String
array.
|
static java.lang.String |
trimEnd(java.lang.String str)
Trim the end of a String
|
static <T> java.util.List<T> |
trimList(java.util.List<T> list)
Returns a copy of the given list without any null values at the end.
|
static java.lang.String[] |
trimStringArray(java.lang.String[] array)
Remove the trailing empty cells of the given String
array.
|
static java.lang.String |
truncate(java.lang.String str,
int length)
Truncates the given String.
|
static java.lang.String |
truncate(java.lang.String str,
int length,
java.lang.String suffix)
Truncates the given String
|
static java.lang.String |
truncateHtml(java.lang.String text,
int length,
boolean trim)
Truncate an HTML string.
|
static java.lang.String |
unaccentuate(java.lang.String str)
Removes all the accentuate chars of the given string.
|
static java.lang.String |
unaccentuateRegexp(java.lang.String str)
Build an unaccentuated version of the given regexp.
|
static java.lang.String |
uncapitalize(java.lang.String str)
Force the first char of a String to be a lowercase char.
|
static java.lang.String |
unescapeChar(java.lang.String str)
Unescape escaped character in a String.
|
static java.util.Set<?> |
unionSet(java.util.Set<?>... sets)
Returns the union of an array of
Set . |
static java.util.Set |
unionSet(java.util.Set set1,
java.util.Set set2)
Returns the union of two
Set . |
static java.util.Set |
unionSet(java.util.Set set1,
java.util.Set set2,
java.util.Set set3)
Returns the union of three
Set . |
static void |
updateListMap(java.util.Map map,
java.lang.Object key,
java.lang.Object value,
boolean lazy)
Updated Map with the given key/value pair.
|
static boolean |
validateRegexp(java.lang.String regexp)
Tell if a String is a valid Perl 5 regexp.
|
static java.lang.String |
wordWrap(java.lang.String str,
int width)
Wraps a single line of text, identifying words by
' ' . |
static java.lang.String |
wordWrap(java.lang.String str,
int wrapLength,
java.lang.String newLineStr,
boolean wrapLongWords)
Wraps a single line of text, identifying words by
' ' . |
public static final java.lang.String REVISION
public static final java.util.TreeSet EMPTY_TREESET
emptyTreeSet()
for generics compliance.public static final java.util.HashMap<java.lang.String,java.lang.String> regexpEscaped1
public static final java.util.HashMap<java.lang.String,java.lang.String> regexpEscaped2
public static final java.util.HashMap<java.lang.String,java.lang.String> regexpEscaped3
protected static org.apache.oro.text.regex.Pattern hexaPercentPattern
protected static org.apache.oro.text.regex.Perl5Substitution hexaPercentSubst
protected static org.apache.oro.text.regex.Perl5Compiler hexaPercentCompiler
public static final char ESCAPE_CHAR
public static final java.util.HashMap<java.lang.String,java.lang.String> cookieTransTable
public static final java.util.HashMap<java.lang.String,java.lang.String> isoLatin1_xml
public static final java.util.HashMap basicEntitiesEncodingMap
public static final java.util.HashMap basicEntitiesDecodingMap
public static int FILE_SIZE_UNIT_DIV
public static final <T> java.util.TreeSet<T> emptyTreeSet()
This example illustrates the type-safe way to obtain an empty set:
TreeSet<String> s = Util.emptyTreeSet();
EMPTY_TREESET
public static <K,V> java.lang.Object getKey(java.util.Map<K,V> map, V value)
map
- the Map to searhc onvalue
- the value to searchpublic static <K,V> java.util.Set<K> getKeys(java.util.Map<K,V> map, V value)
map
- the Map to searhc onvalue
- the value to searchpublic static void updateListMap(java.util.Map map, java.lang.Object key, java.lang.Object value, boolean lazy)
map
- Map to work withkey
- Object key of the Mapvalue
- Object value of the maplazy
- boolean true to create List only after 2 elementspublic static java.lang.Object getChildListMap(java.util.Map map, java.lang.String key)
map
- the Mapkey
- Object key of the Mappublic static java.util.List getChildrenListMap(java.util.Map map, java.lang.String key)
map
- the Mapkey
- Object key of the Mappublic static java.util.List getChildrenListMap(java.util.Map map, java.lang.String[] keys)
map
- the Mapkeys
- Object key of the Mappublic static <K,V> java.util.Map<V,K> reverseMap(java.util.Map<K,V> originalMap, java.util.Map<V,K> reverseMap)
K
- keyV
- valueoriginalMap
- original mapreverseMap
- reverse mappublic static <K,V> java.util.Map.Entry<K,V> compareMap(java.util.Map<K,V> map1, java.util.Map<K,V> map2)
map1
- the first mapmap2
- the second map.public static <K,V> boolean isMapFilled(java.util.Map<K,V> map)
map
- the map.public static <T> java.util.Collection<T> addAll(java.util.Collection<T> collection, java.util.Enumeration<T> enu)
collection
- Collection
enu
- Enumeration
public static <T> java.util.Collection<T> addAll(java.util.Collection<T> collection, java.util.Iterator<T> it)
collection
- the collectionit
- the iteratorpublic static java.lang.String startsWith(java.lang.String str, java.util.Collection<java.lang.String> coll)
str
- the String to matchcoll
- a Collection of String that may be start of strpublic static java.lang.String getString(java.lang.Object obj, java.lang.String defaultValue)
obj
- the objectdefaultValue
- the default valuepublic static java.lang.String getString(java.lang.Object[] array, int index, java.lang.String defaultValue)
array
- the object arrayindex
- the indexdefaultValue
- the default valuepublic static java.lang.Object getObject(java.lang.Object[] array, int index, java.lang.Object defaultValue)
public static int getInt(int[] array, int index, int defaultValue)
public static boolean getBoolean(boolean[] array, int index, boolean defaultValue)
public static int getSize(java.lang.String str)
str
- the String.public static int getSize(java.lang.Object[] array)
array
- the array.public static int getSize(byte[] array)
array
- an array of byte.public static int getSize(short[] array)
array
- an array of short.public static int getSize(int[] array)
array
- an array of int.public static int getSize(long[] array)
array
- an array of long.public static int getSize(float[] array)
array
- an array of float.public static int getSize(double[] array)
array
- an array of double.public static int getSize(boolean[] array)
array
- an array of boolean.public static int getSize(char[] array)
array
- an array of char.public static int getSize(java.util.Collection coll)
coll
- the collection.public static int getSize(java.util.Map map)
map
- the map.public static boolean notEmpty(java.io.File file)
true
if this File is not
null
nor empty.file
- the file to testpublic static boolean isEmpty(java.io.File file)
true
if this file is
null
or empty.file
- the file to testpublic static boolean notEmpty(java.io.File file, java.io.FileFilter fileFilter)
true
if this File is not
null
nor empty.file
- the file to testfileFilter
- the filterpublic static boolean isEmpty(java.io.File file, java.io.FileFilter fileFilter)
true
if this file is
null
or empty.file
- the file to testfileFilter
- the filterpublic static boolean notEmpty(java.lang.Object object)
true
if this object is not
null
nor empty.object
- the object to testpublic static boolean isEmpty(java.lang.Object object)
true
if this object is
null
or empty.object
- the object to testpublic static boolean notEmpty(int[] array)
true
if this array is not null
nor empty.array
- the array to testpublic static boolean isEmpty(int[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(long[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(byte[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(short[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(float[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(double[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(boolean[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean isEmpty(char[] array)
true
if this array is null
or empty.array
- the array to testpublic static boolean notEmpty(java.lang.Object[] array)
true
if this array is not
null
nor empty.array
- the array to testpublic static boolean isEmpty(java.lang.Object[] array)
true
if this array is
null
or empty.array
- the array to testpublic static boolean notEmpty(java.lang.Object[] array, boolean recursive)
true
if this array is not
null
nor empty.array
- the array to testrecursive
- check if arrays elements are emptypublic static boolean isEmpty(java.lang.Object[] array, boolean recursive)
true
if this array is
null
or empty.array
- the array to testrecursive
- check if arrays elements are emptypublic static boolean notEmpty(java.util.Collection<?> c)
true
if this collection is not
null
nor empty.c
- the collection to testpublic static boolean isEmpty(java.util.Collection<?> c)
true
if this collection is
null
or empty.c
- the collection to testpublic static boolean isEmpty(java.util.Collection<?> c, boolean deep)
true
if this collection is
null
or empty.c
- the collection to testdeep
- to call Util.isEmpty on content otherwise check only == nullpublic static boolean notEmpty(java.util.Map<?,?> map)
true
if this map is not
null
nor empty.map
- the map to testpublic static boolean isEmpty(SQLQueryResult sqr)
true
if this SQLQueryResult is
null
or empty.sqr
- the SQLQueryResult to testpublic static boolean notEmpty(SQLQueryResult map)
true
if this SQLQueryResult is not
null
nor empty.map
- the SQLQueryResult to testpublic static boolean isEmpty(java.util.Map<?,?> map)
true
if this map is
null
or empty.map
- the map to testpublic static void mainTestEmpty(java.lang.String[] args)
public static java.lang.String join(java.util.Collection<?> col, java.lang.String sep)
toString()
method for each iterated
Object.col
- the collectionsep
- the separatorpublic static java.lang.String join(java.util.Collection<?> col, java.lang.String sep, int max, java.lang.String suffix)
toString()
method for each iterated
Object.col
- the collectionsep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String join(java.util.Iterator<?> it, java.lang.String sep)
toString()
method for each iterated
Object.it
- the iterator of the collectionsep
- the separatorpublic static java.lang.String join(java.util.Iterator<?> it, java.lang.String sep, int max, java.lang.String suffix)
toString()
method for each iterated
Object.it
- the iterator of the collectionsep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String joinMap(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map, java.lang.String keyValueSep, java.lang.String entrySep)
Mapmap = new LinkedHashMap (); map.put("simpleobject", "bar"); map.put("stringarray", new String[] { "hi", "hello" } ); List<Object> list = new ArrayList<Object>(); list.add("John"); list.add("Doe"); map.put("collection", list ); String output = "{" + Util.joinMap(map, "=>", ", ") + "}"; output == "{ simpleobject=>bar, stringarray=>[hi, hello], collection=>[John, Doe] }"
map
- the map to join akeyValueSep
- the separator to use between key and the valueentrySep
- the separator to use between each entrypublic static void listMap(java.util.Map<?,?> map)
System.out
.map
- the map to listpublic static void listMap(java.util.Map<?,?> map, java.io.PrintStream out)
PrintStream
.map
- the map to listout
- the PrintStream to use to list the mappublic static void listMap(java.util.Map<?,?> map, java.io.PrintStream out, java.lang.String sep)
PrintStream
with the given
separator.map
- the map to listout
- the PrintStream to use to list the mapsep
- the separatorpublic static void listDictionary(java.util.Dictionary<?,?> dict)
System.out
.dict
- the Dictionnary to listpublic static void listDictionary(java.util.Dictionary<?,?> dict, java.io.PrintStream out)
PrintStream
.dict
- the Dictionnary to listout
- the PrintStream to use to list the dictionnarypublic static void listDictionary(java.util.Dictionary<?,?> dict, java.io.PrintStream out, java.lang.String sep)
PrintStream
with
the given separator.dict
- the dictionnary to listout
- the PrintStream to use to list the dictionnarsep
- the separatorpublic static <K,V> java.util.Map<K,V> subMap(java.util.Map<K,V> map, java.util.Set<K> keys)
map
- Map to work onkeys
- Set of key to removepublic static <K,V> java.util.Map<? extends K,? extends V> interMap(java.util.Map<? extends K,? extends V> map, java.util.Set<? extends K> keys)
map
- Map to work onkeys
- Set of keypublic static java.util.Set<java.lang.String> prefixSet(java.util.Set<java.lang.String> set, java.lang.String prefix)
set
- Set of Stringprefix
- a String to prefixpublic static java.util.Set<?> unionSet(java.util.Set<?>... sets)
Set
. The result set does not contains null item.sets
- an array of Set
Set
(same class as the first set)public static java.util.Set unionSet(java.util.Set set1, java.util.Set set2)
Set
.set1
- the first Set
set2
- the second Set
Set
public static java.util.Set unionSet(java.util.Set set1, java.util.Set set2, java.util.Set set3)
Set
.set1
- the first Set
set2
- the second Set
set3
- the thrid Set
Set
public static java.util.Set interSet(java.util.Set... sets)
Set
.sets
- an array of Set
Set
(same class as the first set, with same comparator for TreeSet)
containing only element presents in all the given set.
does not return a new set if only one set was given, instead return the given set.public static java.util.Set interSet(java.util.Set set1, java.util.Set set2)
Set
.set1
- the first Set
set2
- the second Set
Set
public static java.util.Set interSet(java.util.Set set1, java.util.Set set2, java.util.Set set3)
Set
.set1
- the first Set
set2
- the second Set
set3
- the thrid Set
Set
public static java.util.Set subSet(java.util.Set... sets)
Set
. The subset
contains all the elements of the first Set
without
those of the other Set
.sets
- an array of Set
Set
(same class as the first set)public static java.util.Set subSet(java.util.Set set1, java.util.Set set2)
Set
. The subset
contains all the elements of the first Set
without
those of the second Set
.set1
- the first Set
set2
- the second Set
Set
public static java.util.Set subSet(java.util.Set set1, java.util.Set set2, java.util.Set set3)
Set
. The subset
contains all the elements of the first Set
without
those of the second and third Set
.set1
- the first Set
set2
- the second Set
set3
- the third Set
Set
public static <T> java.util.ArrayList<T> getArrayList(T... array)
T
- any typearray
- a varargs of objectspublic static <T> java.util.ArrayList<T> getArrayList(boolean skipNull, boolean trim, T... array)
T
- any typeskipNull
- remove null objecttrim
- if true remove the null at the end of the arrayarray
- a varargs of objectspublic static <T> java.util.HashSet<T> getHashSet(T... array)
T
- any typearray
- a varargs of objectspublic static <T> java.util.TreeSet<T> getTreeSet(T... array)
T
- any typearray
- a varargs of objectspublic static <K,V> java.util.HashMap<K,V> getHashMap(K key, V value)
K
- any typeV
- any typekey
- the first key to be addedvalue
- the first value to be addedpublic static <K,V> java.util.HashMap<K,V> getHashMap(java.util.Map<K,V> map)
K
- any typeV
- any typemap
- the map to be addedpublic static <K,V> java.util.TreeMap<K,V> getTreeMap(K key, V value)
K
- any typeV
- any typekey
- the first key to be addedvalue
- the first value to be addedpublic static <K,V> java.util.TreeMap<K,V> getTreeMap(java.util.Map<K,V> map)
K
- any typeV
- any typemap
- the map to be addedpublic static <K,V> java.util.LinkedHashMap<K,V> getLinkedHashMap(K key, V value)
K
- any typeV
- any typekey
- the first key to be addedvalue
- the first value to be addedpublic static <K,V> java.util.LinkedHashMap<K,V> getLinkedHashMap(java.util.Map<K,V> map)
K
- any typeV
- any typemap
- the map to be addedpublic static <T> T getFirst(java.util.Collection<T> coll)
coll
- the collectionpublic static <T> T getFirst(T[] array)
array
- the arraypublic static <T> T getLast(java.util.SortedSet<T> set)
set
- the SortedSetpublic static <T> T getLast(java.util.List<T> list)
list
- the Listpublic static <T> T getLast(T[] array)
array
- the arraypublic static <K,V> void addInMapHashSet(java.util.Map<K,java.util.Set<V>> map, K key, V value)
map
- the mapkey
- the keyvalue
- the valuepublic static <K,V> void removeFromMapHashSet(java.util.Map<K,java.util.Set<V>> map, K key, V value)
map
- the mapkey
- the keyvalue
- the valuepublic static <K,V> void addInMapLinkedHashSet(java.util.Map<K,java.util.LinkedHashSet<V>> map, K key, V value)
map
- the mapkey
- the keyvalue
- the valuepublic static <K,V> void removeFromMapLinkedHashSet(java.util.Map<K,java.util.LinkedHashSet<V>> map, K key, V value)
map
- the mapkey
- the keyvalue
- the valuepublic static <T> java.util.Collection<T> cleanCollection(java.util.Collection<T> coll)
coll
- the collection to be cleanedpublic static <T> java.util.Set<T> collectionToCleanSet(java.util.Collection<T> coll)
coll
- the collectionpublic static java.util.Set<java.lang.String> stringArrayToCleanSet(java.lang.String[] array)
array
- the arraypublic static <T> java.util.Collection<T> addAll(T[] array, java.util.Collection<T> coll)
array
- the array to copy fromcoll
- the collection to copy topublic static <T> T[] addAll(T[] array1, T... otherArrays)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed by all of the elements array2
. When an array is returned, it is
always a new array.
Util.addAll(null, null) = null Util.addAll(array1, null) = cloned copy of array1 Util.addAll(null, array2) = cloned copy of array2 Util.addAll([], []) = [] Util.addAll([null], [null]) = [null, null] Util.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
T
- the component type of the arrayarray1
- the first array whose elements are added to the new array, may be null
otherArrays
- the other arrays whose elements are added to the new array, may be null
null
if both arrays are null
.
The type of the new array is the type of the first array,
unless the first array is null, in which case the type is the same as the second array.java.lang.IllegalArgumentException
- if the array types are incompatiblepublic static <K,V> java.util.Map<K,V> putAll(K[] array, java.util.Map<K,V> map, V value)
array
- the array to copy frommap
- the collection to copy tovalue
- the value to setpublic static int[] swapArray(int[] array, int from, int to, boolean roll, boolean copy)
array
- the arrayfrom
- the location of the first element (< 0 not to swap)to
- the location of the element to swap with (-2 to roll back, -1 to roll forward)roll
- if should roll from end to startcopy
- return a copy of of the arraypublic static boolean[] swapArray(boolean[] array, int from, int to, boolean roll, boolean copy)
array
- the array of arrayfrom
- the location of the first element (< 0 not to swap)to
- the location of the element to swap with (-2 to roll back, -1 to roll forward)roll
- if should roll from end to startcopy
- return a copy of of the arraypublic static java.lang.Object[] swapArray(java.lang.Object[] array, int from, int to, boolean roll, boolean copy)
array
- the array of arrayfrom
- the location of the first element (< 0 not to swap)to
- the location of the element to swap with (-2 to roll back, -1 to roll forward)roll
- if should roll from end to startcopy
- return a copy of of the arraypublic static int[] insertArray(int[] array, int index, int elt)
array
- the arrayindex
- the location where the element must be inserted (use -1 to insert ahead and array.length (or greater) to insert at the end)elt
- the element to be insertedpublic static boolean[] insertArray(boolean[] array, int index, boolean elt)
array
- the arrayindex
- the location where the element must be inserted (use -1 to insert ahead, array.length (or greater) to insert at the end)elt
- the element to be insertedpublic static java.lang.Object[] insertArray(java.lang.Object[] array, int index, java.lang.Object elt)
array
- the arrayindex
- the location where the element must be inserted (use -1 to insert ahead, array.length (or greater) to insert at the end)elt
- the element to be insertedpublic static java.lang.Object[] removeArray(java.lang.Object[] array, int index)
array
- the array of objectindex
- the location of the element to be removed frompublic static java.lang.Object[] removeArray(java.lang.Object[] array, java.lang.Object obj)
array
- the array of objectobj
- the object to be removedpublic static int[] removeArray(int[] array, int index)
array
- the array of intindex
- the location of the element to be removed frompublic static boolean[] removeArray(boolean[] array, int index)
array
- the array of booleanindex
- the location of the element to be removed frompublic static java.lang.Object[] removeArray(java.lang.Object[] array, int from, int to)
array
- the array of intfrom
- the location of the first element to be removed fromto
- the location of the last element to be removed frompublic static int[] removeArray(int[] array, int from, int to)
array
- the array of intfrom
- the location of the first element to be removed fromto
- the location of the last element to be removed frompublic static boolean[] removeArray(boolean[] array, int from, int to)
array
- the array of booleanfrom
- the location of the first element to be removed fromto
- the location of the last element to be removed frompublic static boolean isSameContent(boolean[] array1, boolean[] array2)
array1
- a boolean arrayarray2
- a boolean arraypublic static boolean isSameContent(byte[] array1, byte[] array2)
array1
- a byte arrayarray2
- a byte arraypublic static boolean isSameContent(char[] array1, char[] array2)
array1
- a char arrayarray2
- a char arraypublic static boolean isSameContent(double[] array1, double[] array2)
array1
- a double arrayarray2
- a double arraypublic static boolean isSameContent(float[] array1, float[] array2)
array1
- a float arrayarray2
- a float arraypublic static boolean isSameContent(int[] array1, int[] array2)
array1
- an int arrayarray2
- an int arraypublic static boolean isSameContent(long[] array1, long[] array2)
array1
- a long arrayarray2
- a long arraypublic static boolean isSameContent(short[] array1, short[] array2)
array1
- a short arrayarray2
- a short arraypublic static boolean isSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
array1
- an object arrayarray2
- an object arraypublic static boolean isSameContent(java.util.Set set1, java.util.Set set2)
set1
- a Setset2
- a Setpublic static boolean isSameContent(java.util.List list1, java.util.List list2)
list1
- a Listlist2
- a Listpublic static boolean isSameContent(java.util.Map map1, java.util.Map map2)
map1
- a Mapmap2
- a Mappublic static boolean isSameContent(java.lang.String str1, java.lang.String str2)
str1
- a Stringstr2
- a Stringpublic static boolean isSameContent(java.util.Date date1, java.util.Date date2)
date1
- a Datedate2
- a Datepublic static boolean isSameContent(org.jdom.Element elt1, org.jdom.Element elt2)
elt1
- a JDom Elementelt2
- a JDom Elementpublic static java.util.TreeSet getTreeDescendantSet(TreeNode node)
node
- the nodepublic static java.util.Set getTreeDescendantSet(TreeNode node, java.util.Set nodeSet)
public static java.util.TreeSet getAllChildrenSet(TreeNode node)
node
- the nodepublic static java.util.Set getAllChildren(TreeNode node, java.util.Set nodeSet)
node
- the parent nodenodeSet
- the set to fill, if null, returns nullpublic static boolean isChildNode(TreeNode node, TreeNode child)
node
- the parent nodechild
- the node to seek@Deprecated public static java.lang.String getHtmlIcon(java.lang.String src, java.lang.String alt)
src
- the image sourcealt
- the iamge titlepublic static boolean notEmpty(java.lang.String s)
true
if this string is not null
nor empty (once trimmed).s
- the string to testpublic static boolean isEmpty(java.lang.String s)
true
if this string is null
or
empty (once trimmed).s
- the string to testpublic static int[] splitToIntArray(java.lang.String str, java.lang.String delim)
str
- the String to splitdelim
- the delimiter (same as StringTokenizer)splitToList(String, String)
,
StringTokenizer
public static java.lang.String[] split(java.lang.String str, java.lang.String delim)
str
- the String to splitdelim
- the delimiter (same as StringTokenizer)splitToList(String, String)
,
StringTokenizer
public static java.util.ArrayList<java.lang.String> splitToList(java.lang.String str, java.lang.String delim)
str
- the String to splitdelim
- the delimiter (same as StringTokenizer)StringTokenizer
public static java.lang.String[] split(java.lang.String str, char delim, java.lang.String emptyToken)
str
- the String to splitdelim
- the delimiteremptyToken
- the value to used when encounter an empty tokenpublic static java.lang.String[] splitWithPattern(java.lang.String text, java.lang.String pattern)
text: foo [one: 1] [two: 2] bar [three: 3] bar
pattern: "\\[([^\\]]+)\\]"
String[] {"one: 1", "two: 2", "three: 3" }
text: foo [one: 1] [two: 2] bar [three: 3] bar
pattern: "\\[[^\\]]+\\]"
String[] {"[one: 1]", "[two: 2]", "[three: 3]" }
text
- the text to split.pattern
- the pattern to split with.public static java.lang.String trimEnd(java.lang.String str)
str
- the String to trimpublic static java.lang.String getMatch(java.lang.String regexp, java.lang.String str, int group)
regexp
- the regular expressionstr
- the String to matchgroup
- the group to matchpublic static java.lang.String getMatch(java.util.regex.Pattern pattern, java.lang.String str, int group)
pattern
- java.util.regex.Patternstr
- the String to matchgroup
- the group to matchpublic static java.lang.String wordWrap(java.lang.String str, int width)
Wraps a single line of text, identifying words by ' '
.
New lines will be separated by the system property line separator. Very long words, such as URLs will not be wrapped.
Leading spaces on a new line are stripped. Trailing spaces are not stripped.
Util.wordWrap(null, *) = null Util.wordWrap("", *) = ""
str
- the String to be word wrapped, may be nullwidth
- the column to wrap the words at, less than 1 is treated as 1null
if null input
TODO: replace with jakarta WordUtils.wrap()public static java.lang.String wordWrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords)
Wraps a single line of text, identifying words by ' '
.
Leading spaces on a new line are stripped. Trailing spaces are not stripped.
Util.wordWrap(null, *, *, *) = null Util.wordWrap("", *, *, *) = ""
str
- the String to be word wrapped, may be nullwrapLength
- the column to wrap the words at, less than 1 is treated as 1newLineStr
- the string to insert for a new line,
null
uses the system property line separatorwrapLongWords
- true if long words (such as URLs) should be wrappednull
if null input
TODO: replace with jakarta WordUtils.wrap()public static void mainTestGeneratePassword(java.lang.String[] args)
public static void mainTestJoin(java.lang.String[] args)
public static java.lang.String join(java.lang.Object[] array, java.lang.String sep)
array
- the array of String to join.sep
- the separatorpublic static java.lang.String join(java.lang.Object[] array, java.lang.String sep, int max, java.lang.String suffix)
array
- the array of String to join.sep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String join(int[] array, java.lang.String sep)
array
- the array of int to join.sep
- the separatorpublic static java.lang.String join(int[] array, java.lang.String sep, int max, java.lang.String suffix)
array
- the array of int to join.sep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String join(java.lang.String... str)
str
- the strings to be joined.public static java.lang.String join(long[] array, java.lang.String sep)
array
- the array of long to join.sep
- the separatorpublic static java.lang.String join(long[] array, java.lang.String sep, int max, java.lang.String suffix)
array
- the array of long to join.sep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String join(double[] array, java.lang.String sep)
array
- the array of long to join.sep
- the separatorpublic static java.lang.String join(double[] array, java.lang.String sep, int max, java.lang.String suffix)
array
- the array of double to join.sep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String join(boolean[] array, java.lang.String sep)
array
- the array of boolean to join.sep
- the separatorpublic static java.lang.String join(boolean[] array, java.lang.String sep, int max, java.lang.String suffix)
array
- the array of boolean to join.sep
- the separatormax
- the maximum of item to joinsuffix
- the suffix to add if the maximum has been reachedpublic static java.lang.String toWordLine(java.lang.String str)
str
- the string to splitpublic static java.lang.String repeat(java.lang.String pattern, int count)
count
timespattern
- the patterncount
- the number of times the pattern must be repeatedpublic static boolean arrayContains(java.lang.Object[] array, java.lang.Object key)
array
- the array to be searched.key
- the value to be searched for.public static java.lang.String[] trim(java.lang.String[] array)
array
- the array to be trimmedpublic static java.lang.String[] trimStringArray(java.lang.String[] array)
array
- the array to be trimmedpublic static <T> java.util.List<T> trimList(java.util.List<T> list)
T
- any typelist
- the list to be trimmedpublic static java.lang.String[] cleanStringArray(java.lang.String[] array)
array
- the array to be cleanedpublic static java.lang.Object[] cleanObjectArray(java.lang.Object[] array)
array
- the array to be cleanedpublic static java.lang.String unaccentuate(java.lang.String str)
str
- the String to unaccentuate.public static java.lang.String unaccentuateRegexp(java.lang.String str)
str
- the String of the regexp to unaccentuate.public static java.lang.String recapitalize(java.lang.String str)
str
- the String to proceedpublic static java.lang.String uncapitalize(java.lang.String str)
str
- the String to proceedpublic static java.lang.String asciiIndent(java.lang.String text, int cols, int rows, java.lang.String tailString)
text
- the text to indentcols
- Number of columnrows
- Number of rowstailString
- the string to append if the text has been truncatedpublic static java.lang.String cryptUnix(java.lang.String str)
str
- the String to encryptpublic static java.lang.String cryptMD5(java.lang.String str)
str
- the String to encryptpublic static java.lang.String encodeBASE64(java.lang.String str)
str
- the String to encodepublic static java.lang.String encodeBASE64(java.lang.String str, boolean isChunck)
str
- the string to encodeisChunck
- - if true this encoder will chunk the base64 output into 76 character blockspublic static java.lang.String decodeBASE64(java.lang.String str)
str
- the String to decodepublic static java.lang.String encryptDES3(java.lang.String clearStr) throws StringEncrypter.EncryptionException
StringEncrypter
with an internal key.clearStr
- the string to encrypt.StringEncrypter.EncryptionException
- if the encryption could not be performedpublic static java.lang.String decryptDES3(java.lang.String encryptedStr) throws StringEncrypter.EncryptionException
StringEncrypter
using same internal key
used by encryptDES3(String)
.encryptedStr
- the encrypted string to decrypt.
if null or empty, the returnStringEncrypter.EncryptionException
- if the decryption could not be performedpublic static java.lang.String conceal(java.lang.String clearStr)
clearStr
- the String to encryptpublic static java.lang.String reveal(java.lang.String concealedStr)
concealedStr
- the String to encryptpublic static java.lang.String buildID(java.lang.String str, java.lang.String charRange)
str
- the String to used as base for the IDcharRange
- a perl5 char range. All the chars out of this
range will be ignored (e.g. "0-9a-z_A-Z" to keep only alpha-num
chars)public static java.lang.String buildID(java.lang.String str)
str
- the String to used as base for the IDpublic static java.lang.String buildCamelID(java.lang.String str)
str
- the String to used as base for the IDpublic static java.lang.String buildUID(java.lang.String str, java.util.Set<java.lang.String> strSet)
str
- the String to used as base for the IDstrSet
- the set of String of existing idspublic static void mainTestBuildID(java.lang.String[] args)
public static java.lang.String escapePercent(java.lang.String url)
url
- the utf-8 string to escapepublic static java.lang.String escapeRegexp(java.lang.String string)
string
- the regexp string to be escapedescapeRegexp(String,boolean)
public static java.lang.String escapeRegexp(java.lang.String string, boolean basicRegexp)
string
- the regexp string to be escapedbasicRegexp
- if true convert * and ? to Perl5 regular expressionpublic static java.lang.String escapeChars(java.lang.String str, java.lang.String charsToEscape)
Example:
Util.escapeChar("ab|cde%fg|hi=j", "|="); // -> ab%7ccde%25fg%7chi%3dj
str
- the stringcharsToEscape
- a string containing all the chararacters to escapecharToEscape
escapedpublic static java.lang.String unescapeChar(java.lang.String str)
Example:
Util.unescapeChar("ab%7ccde%25fg%7chij"); // -> ab|cde%fg|hij
str
- the stringcharToUnescape
unescapedpublic static java.lang.String escapeLuceneQuery(java.lang.String str)
str
- the string to escapepublic static void mainTestEscapeLuceneQuery(java.lang.String[] args)
public static java.lang.String replace(java.lang.String str, java.lang.String match, java.lang.String rep)
str
- the input Stringmatch
- a Perl5 regexprep
- a Perl5 replace patternpublic static java.lang.String replace(java.lang.String str, java.lang.String pattern)
str
- the input Stringpattern
- the Perl5 substitution pattern (e.g. s!regexp!replace!)public static java.lang.String replace(java.lang.String text, java.lang.String regexp, RegexpSubstitution substitution) throws org.apache.oro.text.regex.MalformedPatternException
text
- the textregexp
- the regexpsubstitution
- the RegexpSubstitution function called.org.apache.oro.text.regex.MalformedPatternException
- if an error has occurred.public static java.lang.String replace(java.lang.String text, org.apache.oro.text.regex.Pattern pattern, RegexpSubstitution substitution)
text
- the textpattern
- the patternsubstitution
- the RegexpSubstitution function called.public static java.lang.String replaceAll(java.lang.String input, java.lang.String searchString, java.lang.String replaceString)
input
- represents input stringsearchString
- represents substring for replacereplaceString
- represents replaced string valuepublic static java.lang.String removeBlankLines(java.lang.String str)
str
- the String to be cleanedpublic static java.lang.String escapeBackslash(java.lang.String str)
str
- the String to escape@Deprecated public static java.lang.String removeJavaScriptQuote(java.lang.String str)
str
- the String to escape@Deprecated public static java.lang.String encodeJavaScriptQuote(java.lang.String str)
str
- the String to encode@Deprecated public static java.lang.String escapeJavaScriptQuote(java.lang.String str)
str
- the String to escapepublic static java.lang.String escapeJavaStringChar(java.lang.String str)
str
- the String to escapepublic static java.lang.String getFirstSentences(java.lang.String text, int limit)
text
- the string to get the first sentence.limit
- how many sentences to get (return the original text if limit <0).public static void mainSwapArray(java.lang.String[] args)
public static void mainRemoveArray(java.lang.String[] args)
public static java.lang.String truncateHtml(java.lang.String text, int length, boolean trim)
Use HtmlUtil.truncate(String, int, String)
for advanced HTML support.
text
- the HTML content to be truncatedlength
- the length to keep.trim
- if true trims the input textpublic static java.lang.String truncate(java.lang.String str, int length)
str
- the String to truncatelength
- the length to truncate topublic static java.lang.String truncate(java.lang.String str, int length, java.lang.String suffix)
str
- the String to truncatelength
- the length to truncate tosuffix
- the suffix to add if the string has been truncatedpublic static java.lang.String html2Ascii(java.lang.String str)
Contrary to the behavior implied by the method name, the returned text may contained unicode characters.
Important limitation note : as of current implementation, the conversion
is performed using regular expression. This processing can lead to StackErrorOverflow
when a large and invalid HTML content is specified. If you don't need to preserve
and convert spaces from the HTML, uses html2text(String)
.
More information on this problem in JIRA issue
JCMS-2628
str
- the html to converthtml2text(String)
@Deprecated public static java.lang.String html2text(java.lang.String html)
HtmlUtil.html2text(String)
html
- the html from which text should be extractedpublic static java.lang.String surround(java.lang.String inside, java.lang.String begin, java.lang.String end)
inside
- The text to be surrounded.begin
- The text at the beginning.end
- The text at the end.public static java.lang.String surroundWithTag(java.lang.String inside, java.lang.String tag)
inside
- The text to be surrounded.tag
- The tagpublic static java.lang.String decodeUrl(java.lang.String str)
public static java.lang.String encodeUrl(java.lang.String s)
URLEncoder.encode(String, String)
,
but space is encoded with %20 and '/' is not encoded.s
- String
to be translated.String
.public static java.lang.String encodeUrl(java.lang.String s, java.lang.String enc)
URLEncoder.encode(String, String)
,
but space is encoded with %20 and '/' is not encoded.s
- String
to be translated.enc
- String
encodingString
.public static java.lang.String encodeCookie(java.lang.String src)
public static java.lang.String decodeCookie(java.lang.String src)
public static java.lang.String isoLatin1ToEntities(java.lang.String src)
src
- the String to convertpublic static java.lang.String entitiesToIsoLatin1(java.lang.String src)
src
- the String to convertpublic static java.lang.String encodeHtmlBasicEntities(java.lang.String src)
src
- the String to convertpublic static java.lang.String decodeHtmlBasicEntities(java.lang.String src)
src
- the String to convertpublic static java.lang.String performEncoding(java.lang.String src, java.util.HashMap transMap)
src
- the String to converttransMap
- the translation mappublic static java.lang.String performDecoding(java.lang.String src, java.util.HashMap transMap)
src
- the String to converttransMap
- the translation mappublic static java.lang.String performEncodeDecode(java.lang.String src, java.util.HashMap transMap, boolean decode)
src
- the String to convert. If src is null, return src.transMap
- the translation map. If transMap is null, return src.decode
- if true use values else use keyspublic static java.lang.String encodeIntArray(int[] array)
public static int[] decodeIntArray(java.lang.String param)
public static java.lang.String encodeIntArray(int[] array, char separator)
public static int[] decodeIntArray(java.lang.String param, char separator)
public static java.lang.String encodeStringArray(java.lang.String[] array)
public static java.lang.String[] decodeStringArray(java.lang.String param)
public static java.lang.String encodeStringArray(java.lang.String[] array, char separator)
public static java.lang.String[] decodeStringArray(java.lang.String param, char separator)
public static java.lang.String encodeObject(java.lang.Object obj)
obj
- the object to be encodedpublic static java.lang.Object decodeObject(java.lang.String encoded)
encoded
- the String that contains the encoded objectpublic static boolean isNumber(java.lang.String str)
str
- the String to be checkedpublic static int[] toIntArray(java.lang.Object[] objs, int def)
String
or a Integer
) to a int
objs
- the object array to convertdef
- default int value to use is object is empty, not a String
nor a Integer
int[]
or null if objs is nulltoInt(Object, int)
public static int toInt(java.lang.Object obj, int def)
String
or a Integer
) to a int
obj
- the object to convertdef
- default int value to use is object is empty, not a String
nor a Integer
int
public static float toFloat(java.lang.Object obj, float def)
String
or a Float
) to a float
obj
- the object to convertdef
- default float value to use is object is empty, not a String
nor a Float
float
public static byte toByte(java.lang.Object obj, byte def)
String
or a Byte
) to a byte
obj
- the object to convertdef
- default byte value to use is object is empty, not a String
nor a Byte
byte
public static short toShort(java.lang.Object obj, short def)
String
or a Short
) to a short
obj
- the object to convertdef
- default short value to use is object is empty, not a String
nor a Short
short
public static long toLong(java.lang.Object obj, long def)
String
or a Long
) to a long
obj
- the object to convertdef
- default long value to use is object is empty, not a String
nor a Long
long
public static double toDouble(java.lang.Object obj, double def)
String
or a Double
) to a double
obj
- the object to convertdef
- default double value to use is object is empty, not a String
nor a Double
double
public static char toChar(java.lang.Object obj, char def)
String
or a Character
) to a char
obj
- the object to convertdef
- default char value to use is object is empty, not a String
nor a Character
char
public static boolean toBoolean(java.lang.Object obj, boolean def)
obj
- the object to convertdef
- default boolean value to use is object is empty, not a String
nor a Boolean
boolean
public static java.util.Date toDate(java.lang.String str, java.lang.String format, java.util.Locale loc, java.util.Date def)
str
- the String to parseformat
- the date Format (can be null)loc
- the Locale tio use (can be null)def
- the default Date to return if errors append.@Deprecated public static java.util.Locale toLocale(java.lang.String str, java.util.Locale def)
public static java.lang.String formatSize(long size, java.util.Locale locale)
size
- the size to formatlocale
- the locale to use for the unitpublic static java.lang.String formatFileSize(long size)
The format used is plain text.
size
- the size to formatpublic static java.lang.String formatFileSize(long size, java.util.Locale locale)
The format used is HTML (with detailled abbreviations).
size
- the size to formatlocale
- the locale to use for the unitpublic static java.lang.String formatFileSize(long size, java.util.Locale locale, boolean htmlDisplay)
size
- the size to formatlocale
- the locale to use for the unithtmlDisplay
- if true, uses an html format, with detailled abbreviation, otherwise, use only plain textpublic static java.lang.String[] getFileSizeWidgetElt(long size)
Example :
long KILOBYTES = 1024; long MEGABYTES = 1024*KILOBYTES; long GIGABYTES = 1024*MEGABYTES; long TERABYTES = 1024*GIGABYTES; Util.getFileSizeWidgetElt(768) -> { "768", "" } Util.getFileSizeWidgetElt(2*KILOBYTES+512) -> { "2", "KB" } Util.getFileSizeWidgetElt(3*MEGABYTES + 2*KILOBYTES + 512) -> { "3", "MB" } Util.getFileSizeWidgetElt(4*GIGABYTES + 3*MEGABYTES + 2*KILOBYTES + 512) -> { "4", "GB" } Util.getFileSizeWidgetElt(5*TERABYTES + 4*GIGABYTES + 3*MEGABYTES + 2*KILOBYTES + 512) -> { "5", "TB" }
size
- the real size[0]
is the value, converted in the proper unit, [1]
is the unit (empty string for bytes value, "KB", "MB", "GB" or "TB").convertFileSizeWidgetElt(String, String)
public static long convertFileSizeWidgetElt(java.lang.String value, java.lang.String unit)
Example :
long KILOBYTES = 1024; long MEGABYTES = 1024*KILOBYTES; long GIGABYTES = 1024*MEGABYTES; long TERABYTES = 1024*GIGABYTES; Util.convertFileSizeWidgetElt("768", ""); -> 768 Util.convertFileSizeWidgetElt("2", "KB"); -> 2048 (== 2*KILOBYTES) Util.convertFileSizeWidgetElt("3", "MB"); -> 3145728 (== 3*MEGABYTES) Util.convertFileSizeWidgetElt("4", "GB"); -> 4294967296 (== 4*GIGABYTES) Util.convertFileSizeWidgetElt("5", "TB"); -> 5497558138880 (== 5*TERABYTES)
value
- the size, expressed in the unit specified in the parameter "unit"unit
- the unit in english, from following values : empty string for bytes value, "KB", "MB", "GB" or "TB"getFileSizeWidgetElt(long)
public static java.lang.String[] getFileSizeUnitLabels(java.util.Locale locale)
Example :
Util.getFileSizeUnitLabels(Locale.ENGLISH); -> { "","KB","MB","GB","TB" } Util.getFileSizeUnitLabels(Locale.FRENCH); -> { "","Ko","Mo","Go","To" } Util.getFileSizeUnitLabels(new Locale("tlh")); -> { "","KB","MB","GB","TB" }
locale
- the Locale in which to retrieve the label@Deprecated public static java.lang.String formatDuration(java.util.Date begin, java.util.Date end)
DateUtil.formatDuration(Date,Date)
insteadbegin
- the begin dateend
- the end date@Deprecated public static java.lang.String formatDuration(java.util.Date begin, java.util.Date end, java.util.Locale locale)
DateUtil.formatDuration(Date,Date,Locale)
insteadbegin
- the begin dateend
- the end datelocale
- the locale to use@Deprecated public static java.lang.String formatDuration(long time)
DateUtil.formatDuration(long)
insteadtime
- the duration to format (in milliseconds)@Deprecated public static java.lang.String formatDuration(long time, java.util.Locale locale)
DateUtil.formatDuration(long,Locale)
insteadtime
- the duration to format (in milliseconds)locale
- the locale to use@Deprecated public static void mainTestFormatDuration(java.lang.String[] args)
DateUtil.mainTestFormatDuration(String[])
insteadargs
- arguments@Deprecated public static long roundDuration(long duration)
DateUtil.roundDuration(long)
insteadAs of current implementation, the following rules are applied
Util.formatDuration(Util.roundDuration(38000)); // 38 s => 38 s Util.formatDuration(Util.roundDuration(76000)); // 1 min 16 s => 1 min 16 s Util.formatDuration(Util.roundDuration(1564512)); // 26 min 4 s => 26 min Util.formatDuration(Util.roundDuration(5890000)); // 1 h 38 min 10 s => 1 h 38 min Util.formatDuration(Util.roundDuration(33165000)); // 9 h 12 min 45 s => 9 h Util.formatDuration(Util.roundDuration(35025000)); // 9 h 43 min 45 s => 10 h Util.formatDuration(Util.roundDuration(130993000)); // 1 day 12 h 23 min 13 s => 1 day 12 h Util.formatDuration(Util.roundDuration(236158000)); // 2 days 17 h 35 min 58 s => 2 days 18 h Util.formatDuration(Util.roundDuration(731675000)); // 8 days 11 h 14 min 35 s => 8 days Util.formatDuration(Util.roundDuration(5934547000L)); // 68 days 16 h 29 min 7 s => 68 days
duration
- a duration in millisecondspublic static java.lang.String generatePassword()
public static java.lang.String generatePassword(int length)
length
- the length of the password to be generatedpublic static java.lang.String generatePronounceablePassword(int pwdLength)
pwdLength
- The length of the password to be generatedpublic static java.lang.String getStackTrace(java.lang.Throwable throwable)
throwable
- the exception or throwable to printpublic static java.lang.String getCurrentStackTrace()
public static boolean forceFullGarbageCollection(long timeout)
timeout
- in millisecond if timeout is reached stop the GC forcingpublic static java.lang.String getClassShortName(java.lang.Object object)
object
- the objectpublic static java.lang.String getClassShortName(java.lang.Class clazz)
clazz
- the classpublic static java.lang.String getClassShortName(java.lang.String fullname)
fullname
- the full class namepublic static java.util.Set<java.lang.String> getClassFiles(java.lang.String realPath, java.lang.String fullname, boolean java)
realPath
- the Webapp realpath (i.e. C:/project/appserver/webapps/webapp-name)fullname
- the Class fullname (i.e. com.jalios.jcms.Category)java
- boolean true to include java filepublic static java.util.Set<java.lang.String> getPackageClassFiles(java.lang.String realPath, java.lang.String fullPackage, boolean sources, java.lang.String excludesPattern)
realPath
- the Webapp realpath (i.e. C:/project/appserver/webapps/webapp-name)fullPackage
- the Package fullname (i.e. com.jalios.jcms.Category)sources
- boolean true to include java fileexcludesPattern
- Ant-style path patterns to exclude files or folders (see AntPathMatcher
)public static java.lang.String getClassNameFromFilename(java.lang.String filename)
filename
- the filename of the classnull
if an error occurred.public static java.lang.Class getFirstCommonClass(java.lang.Class parent, java.lang.Class child)
parent
- parent classchild
- child classpublic static java.util.List getSuperclassList(java.lang.Class clazz, java.lang.Class ancestor, boolean addClass, boolean addAncestor)
clazz
- the class to extract the ancestorsancestor
- the greater ancestoraddClass
- if true, add the class in the listaddAncestor
- if true, add the ancestor in the listpublic static java.lang.String escapeHtml(java.lang.String str)
str
- the string to escape@Deprecated public static java.lang.String escapeHtmlQuote(java.lang.String str)
str
- the String to escape@Deprecated public static java.lang.String escapeInputQuote(java.lang.String str)
str
- the string to escape, e.g. : 'Hello "World" !
'Hello "World" !
'public static int indexOf(java.lang.Object elem, java.lang.Object[] array)
elem
- an object.array
- an array that may contain elem
Object.equals(Object)
@Deprecated public static java.lang.String formatIso8601Date(java.util.Date date)
DateUtil.formatIso8601Date(Date)
instead1999-01-01T14:07:00+0100
).date
- the date to format.DateUtil.parseIso8601Date(String)
@Deprecated public static java.util.Date parseIso8601Date(java.lang.String source)
DateUtil.parseIso8601Date(String)
instead1999-01-01T14:07:00+0100
).source
- the string to be parsedDateUtil.formatIso8601Date(Date)
@Deprecated public static java.lang.String formatW3cDate(java.util.Date date)
DateUtil.formatW3cDate(Date)
instead1999-01-01T14:07:00+01:00
).date
- the date to format.DateUtil.parseW3cDate(String)
@Deprecated public static java.util.Date parseW3cDate(java.lang.String source)
DateUtil.parseW3cDate(String)
instead1999-01-01T14:07:00+01:00
).source
- the string to be parsedDateUtil.formatW3cDate(Date)
@Deprecated public static java.lang.String formatRfc822Date(java.util.Date date)
DateUtil.formatRfc822Date(Date)
insteadFri, 1 Jan 1999 14:07:00 +0100
).
For more details, see http://www.w3.org/Protocols/rfc822/rfc822.txt section 5.1date
- the date to format.@Deprecated public static java.util.Date parseRfc822Date(java.lang.String source)
DateUtil.parseRfc822Date(String)
insteadsource
- the string to be parsed@Deprecated public static java.lang.String formatNoSpaceDate(java.util.Date date)
DateUtil.formatNoSpaceDate(Date)
insteaddate
- the date to format.@Deprecated public static java.util.Date parseNoSpaceDate(java.lang.String source)
DateUtil.parseNoSpaceDate(String)
insteadsource
- the string to be parsed@Deprecated public static boolean isToday(java.util.Date date)
DateUtil.isToday(Date)
insteaddate
- the date to check@Deprecated public static boolean isYesterday(java.util.Date date)
DateUtil.isYesterday(Date)
insteaddate
- the date to check@Deprecated public static boolean isTomorrow(java.util.Date date)
DateUtil.isTomorrow(Date)
insteaddate
- the date to check@Deprecated public static boolean isSameDay(java.util.Date date1, java.util.Date date2)
DateUtil.isSameDay(Date,Date)
insteaddate1
- the first date to checkdate2
- the second date to checkpublic static boolean hasAppenderDefined(org.apache.log4j.Logger logger)
Logger
has any appender defined.logger
- the Logger to check@Deprecated public static java.util.Date getNewDateWithoutMillis()
DateUtil.getNewDateWithoutMillis()
insteadpublic static boolean validateRegexp(java.lang.String regexp)
regexp
- The pattern to validatepublic static java.lang.String reduceBlankLines(java.lang.String text)
text
- the original textpublic static java.lang.String randomString(int length)
public static int exec(java.util.List<java.lang.String> cmdList) throws java.io.IOException, java.lang.InterruptedException
cmdList
- list containing the command to call and its arguments.java.io.IOException
- if an error occursjava.lang.InterruptedException
- if an error occurspublic static int exec(java.lang.String... cmdarray) throws java.io.IOException, java.lang.InterruptedException
cmdarray
- array containing the command to call and its arguments.java.io.IOException
- if an error occursjava.lang.InterruptedException
- if an error occurspublic static int exec(java.lang.String[] cmdarray, java.io.OutputStream stdout, java.io.OutputStream stderr) throws java.io.IOException, java.lang.InterruptedException
cmdarray
- array containing the command to call and its arguments.stdout
- the OutputStream for stdout (ignored if null)stderr
- the OutputStream for stderr (ignored if null)java.io.IOException
- if an error occursjava.lang.InterruptedException
- if an error occurspublic static int exec(java.lang.String[] cmdarray, java.lang.StringBuilder stdout, java.lang.StringBuilder stderr) throws java.io.IOException, java.lang.InterruptedException
cmdarray
- array containing the command to call and its arguments.stdout
- the result of the stdout (ignored if null)stderr
- the result of the stderr (ignored if null)java.io.IOException
- if an error occursjava.lang.InterruptedException
- if an error occurspublic static java.lang.Class<?> getCommonSuperClass(java.lang.Class<?>... classes)
classes
- the classes for which superclass must be found, must not be null nor emptypublic static byte[] getBytesUtf8(java.lang.String string)
String
into a sequence of bytes using the given
UTF-8 charset, storing the result into a
new byte array.
This method is provided as convenient method and as a workaround for
performance bottleneck of Java native string.getBytes("UTF-8");
method.
See issue issue http://issues.jalios.com/browse/JCMS-2570 for more information.
string
- The string to be encodedpublic static java.lang.String getStringUtf8(byte[] bytes)
String
using the UTF-8 charset.
The length of the new String
is a function of the charset, and
hence may not be equal to the length of the byte array.
This method is provided as convenient method and as a workaround for
performance bottleneck of Java native new String(bytes, "UTF-8")
method.
See issue issue http://issues.jalios.com/browse/JCMS-2570 for more information.
bytes
- The bytes to be decoded into characterspublic static <T> java.util.Set<java.util.Set<T>> getBatchSet(java.util.Collection<T> coll, int batchSize)
Example :
List<String> abcdeList = Arrays.asList(new String[] {"a", "b", "c", "d", "e"}); Set<Set<String>> batchSet = Util.getBatchSet(abcdeList, 2); assertEquals(3, batchSet.size()); Iterator<Set<String>> batchIterator = batchSet.iterator(); assertEquals("a,b", Util.join(batchIterator.next(), ",")); assertEquals("c,d", Util.join(batchIterator.next(), ",")); assertEquals("e", Util.join(batchIterator.next(), ""));
coll
- a collection of object, may be null (empty set returned)batchSize
- the size of subset to be create, must be a positive integer otherwiseCopyright © 2001-2010 Jalios SA. All Rights Reserved.