Class Util


  • public class Util
    extends java.lang.Object
    This class provides a set of static methods which perform various utility operations.
    Version:
    $Revision: 135381 $
    Author:
    Olivier Dedieu, Jean-Philippe Encausse, Olivier Jaquemet, Nicolas Dos Santos
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method 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 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 <K,​V>
      java.util.Map<K,​V>
      cleanMap​(java.util.Map<K,​V> map)
      Removes all the entry of the given map with an empty value
      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.

      WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
      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)
      Deprecated.
      using MD5 algorithm for "encryption" is completely unsecure, don't.
      If you need to encrypt data, use a dedicated library.
      static java.lang.String cryptUnix​(java.lang.String str)
      Deprecated.
      using this algorythm for "encryption" is completely unsecure.
      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 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.

      WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
      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 escapeJavaScriptQuote​(java.lang.String str)
      Deprecated.
      use com.jalios.jcms.HttpUtil.encodeForJavaScript
      static java.lang.String escapeJavaStringChar​(java.lang.String str)
      Escape all the invalid char in Java String: '\' -> "\\" CR -> "\n" '"' -> \"
      static java.lang.String escapeLuceneQuery​(java.lang.String str)
      Escape Lucene special chars used in classic QueryParser.
      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.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 int exec​(java.util.List<java.lang.String> cmdList)
      Executes the specified command and arguments in a separate process.
      static boolean forceFullGarbageCollection​(long timeout)
      Force the garbage collection
      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 formatSize​(long size, java.util.Locale locale)
      This method format the given number using International System prefix (aka metric system).
      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.
      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 <K,​V>
      java.util.Map<K,​V>
      getCleanMap​(java.util.Map<K,​V> map)
      Returns a copy of the given map without the entry with an empty value.
      The copy preserves the type for TreeMap, LinkedHashMap and HashMap.
      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[] getFileSizeUnitHTMLLabels​(java.util.Locale locale)
      Retrieve an array containing I18Ned labels to express file size, from bytes to petabytes.
      static java.lang.String[] getFileSizeUnitLabels​(java.util.Locale locale)
      Retrieve an array containing I18Ned labels to express file size, from bytes to petabytes.
      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 java.lang.String[] getFileSizeWidgetUnit​(java.util.Locale locale)
      Retrieve an array containing I18Ned labels to express file size, from bytes to petaabytes.
      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​(java.util.Map<K,​V> map)
      Returns a new HashMap filled with the given map (if it is not null)
      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 <T> java.util.HashSet<T> getHashSet​(T... array)
      Returns a new HashSet filled with the given objects (skip null object).
      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​(java.util.Map<K,​V> map)
      Returns a new LinkedHashMap filled with the given map (if it is not null)
      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 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.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 <T> T getNext​(java.util.Collection<T> coll, T item)
      Returns the next item of the given collection (or null if the collection is empty).
      static <T> T getNext​(T[] array, T item)
      Returns the next item of the given array (or null if the array is empty).
      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​(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​(short[] array)
      Returns the size of the given array.
      static int getSize​(java.lang.Object[] array)
      Returns the size of the given array.
      static int getSize​(java.lang.String str)
      Returns the size of the given String.
      static int getSize​(java.util.Collection coll)
      Returns the size of the given collection.
      static int getSize​(java.util.Map map)
      Returns the size of the given map.
      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​(java.util.Map<K,​V> map)
      Returns a new TreeMap filled with the given map (if it is not null)
      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 <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)
      Deprecated.
      since jcms-9.0.0
      static int indexOf​(java.lang.Object elem, java.lang.Object[] array)
      Searches for the first occurrence 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 isConcealed​(java.lang.String str)  
      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​(double[] array)
      Returns true if this array 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​(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.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​(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​(java.lang.String s)
      Returns true if this string is null or empty (once trimmed).
      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​(java.util.Map<?,​?> map)
      Returns true if this map is null or empty.
      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 isNodeChild​(TreeNode parentNode, TreeNode child)
      Test if a node is a child of an other node
      Return false if child == node.
      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​(double[] array1, double[] array2)
      Returns true if array1 has same content than array2.
      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​(long[] array1, long[] array2)
      Returns true if array1 has same content than array2.
      static boolean isSameContent​(short[] array1, short[] array2)
      Returns true if array1 has same content than array2.
      static boolean isSameContent​(java.lang.Object[] array1, java.lang.Object[] 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 isSameContent​(java.util.Collection col1, java.util.Collection col2)
      Returns true if col1 has same content than col2.
      static boolean isSameContent​(java.util.Date date1, java.util.Date date2)
      Returns true if date1 has same content than date2.
      static boolean isSameContent​(java.util.List list1, java.util.List list2)
      Returns true if list1 has same content than list2.
      static boolean isSameContent​(java.util.Map map1, java.util.Map map2)
      Returns true if map1 has same content than map2.
      static boolean isSameContent​(java.util.Set set1, java.util.Set set2)
      Returns true if set1 has same content than set2.
      static boolean isSameContent​(org.jdom.Element elt1, org.jdom.Element elt2)
      Returns true if elt1 has same content than elt2.
      static boolean isValidEmail​(java.lang.String email)
      Checks that the given email is empty or has a valid email syntax.
      static boolean isValidEmail​(java.lang.String[] emails)
      Returns true if all the given emails are either null, empty or valid.
      static boolean isValidEmail​(java.util.Collection<java.lang.String> emails)
      Returns true if all the given emails are either null, empty or valid.
      static boolean isValidEmail​(java.util.Map emailMap)
      Returns true if all the given emails contained as value of the map are either null, empty or valid.
      static boolean isValidString​(java.lang.String[] strings, java.util.function.Predicate<java.lang.String> p)
      Returns true if all the given strings are either null, empty or valid.
      static boolean isValidString​(java.lang.String string, java.util.function.Predicate<java.lang.String> p)
      Return true if the given string is null, empty or valid.
      static boolean isValidString​(java.util.Collection<java.lang.String> strings, java.util.function.Predicate<java.lang.String> p)
      Returns true if all the given strings are either null, empty or valid.
      static boolean isValidString​(java.util.Map stringMap, java.util.function.Predicate<java.lang.String> p)
      Returns true if all the given strings contained as value of the map are either null, empty or valid.
      static boolean isValidUri​(java.lang.String uri)
      Return true if the given uri is null, empty or valid.
      static boolean isValidUri​(java.lang.String[] uris)
      Returns true if all the given uris are either null, empty or valid.
      static boolean isValidUri​(java.util.Collection<java.lang.String> uris)
      Returns true if all the given uris are either null, empty or valid.
      static boolean isValidUri​(java.util.Map uriMap)
      Returns true if all the given uris contained as value of the map are either null, empty or valid.
      static boolean isValidUrl​(java.lang.String url)
      Return true if the given url is null, empty or valid.
      static boolean isValidUrl​(java.lang.String[] urls)
      Returns true if all the given urls are either null, empty or valid.
      static boolean isValidUrl​(java.util.Collection<java.lang.String> urls)
      Returns true if all the given urls are either null, empty or valid.
      static boolean isValidUrl​(java.util.Map urlMap)
      Returns true if all the given urls contained as value of the map are either null, empty or valid.
      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​(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​(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 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​(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 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 java.util.Map json2map​(java.lang.String json)
      Returns the Map from the given JSON.
      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 mainTestGeneratePassword​(java.lang.String[] args)  
      static void mainTestJoin​(java.lang.String[] args)  
      static java.lang.String map2json​(java.util.Map map)
      Returns the JSON for the given Map.
      static java.lang.String md5Base64​(java.lang.String str)
      Calculates the MD5 digest and returns the value as a base64 string.
      static double mean​(java.util.Collection<? extends java.lang.Number> values)
      Returns the mean of the collection of values.
      static <T> java.util.Set<T> mergeSet​(java.util.Set<T> originalSet, java.util.Set<T>... sets)
      Merge the variations of sets that have diverged from the same original set.
      static boolean notEmpty​(int[] array)
      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.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​(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​(java.lang.String s)
      Returns true if this string is not null nor empty (once trimmed).
      static boolean notEmpty​(java.util.Collection<?> c)
      Returns true if this collection is not null nor empty.
      static boolean notEmpty​(java.util.Map<?,​?> map)
      Returns true if this map is not null nor empty.
      static java.lang.Double parseDouble​(java.lang.String str)
      Parse string into Double.
      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 repeat​(java.lang.String pattern, int count)
      Repeat a String pattern count times
      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 replace​(java.lang.String input, java.util.regex.Pattern regex, MatcherCallback callback)
      Searches a string for a specified regular expression, and returns a new string where the specified values are replaced.
      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 replaceAll​(java.lang.String input, java.lang.String searchString, java.lang.String replaceString)
      Replace all occurrences 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 <T> java.util.List<java.util.List<T>> sliceList​(java.util.List<T> list, int max)
      Slices the given list in a list of sub list containing less than max value per list.
      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 <T extends java.util.Collection>
      java.util.List<T>
      splitCollection​(T coll, int max)
      Split the given collection in sub collections having max elements.
      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 double sum​(java.util.Collection<? extends java.lang.Number> values)
      Returns the sum of the collection of numbers.
      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 java.lang.Object[] toArray​(java.lang.Object obj, java.lang.Object[] defaultValues)
      Converts an object value to an arrays of Object.
      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.lang.Integer toInteger​(java.lang.Object obj, java.lang.Integer defaultValue)
      Converts an object value to an Integer.
      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 java.lang.Number toNumber​(java.lang.Object obj, java.lang.Number defaultValue)
      Converts an object value to a Number.
      static java.lang.Number[] toNumberArray​(java.lang.Object obj, java.lang.Number[] defaultValues)
      Converts an object value to a Number array.
      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 toString​(java.lang.Object obj, java.lang.String defaultValue)
      Converts an object value to a String.
      static java.lang.String[] toStringArray​(java.lang.Object obj, java.lang.String[] defaultValues)
      Converts an object value to a String array.
      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 truncate​(java.lang.String str, int length, java.util.Map<java.lang.String,​java.lang.String> truncatedMap)
      Returns a unique truncated string.
      static java.lang.String truncateHtml​(java.lang.String text, int length, boolean trim)
      Truncate an HTML string.
      static java.lang.String truncateVarchar​(java.lang.String v)
      Truncates the given value to be compliant with standard VARCHAR limit (ie 255 chars)
      static java.util.List<java.lang.String> truncateVarchar​(java.util.List<java.lang.String> list)
      Truncates the content of the given list to be compliant with standard VARCHAR limit (ie 255 chars)
      static java.util.Set<java.lang.String> truncateVarchar​(java.util.Set<java.lang.String> set)
      Truncates the content of the given set to be compliant with standard VARCHAR limit (ie 255 chars)
      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 ' '.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UNSTABLE_TEST_ENABLED

        public static final java.lang.String UNSTABLE_TEST_ENABLED
        See Also:
        Constant Field Values
      • EMPTY_TREESET

        public static final java.util.TreeSet EMPTY_TREESET
        The empty TreeSet (immutable).
        Use emptyTreeSet() for generics compliance.
      • regexpEscaped1

        public static final java.util.HashMap<java.lang.String,​java.lang.String> regexpEscaped1
      • regexpEscaped2

        public static final java.util.HashMap<java.lang.String,​java.lang.String> regexpEscaped2
      • regexpEscaped3

        public static final java.util.HashMap<java.lang.String,​java.lang.String> regexpEscaped3
      • hexaPercentPattern

        protected static org.apache.oro.text.regex.Pattern hexaPercentPattern
      • hexaPercentSubst

        protected static org.apache.oro.text.regex.Perl5Substitution hexaPercentSubst
      • hexaPercentCompiler

        protected static org.apache.oro.text.regex.Perl5Compiler hexaPercentCompiler
      • cookieTransTable

        public static final java.util.HashMap<java.lang.String,​java.lang.String> cookieTransTable
      • isoLatin1_xml

        public static final java.util.HashMap<java.lang.String,​java.lang.String> isoLatin1_xml
      • basicEntitiesEncodingMap

        public static final java.util.HashMap basicEntitiesEncodingMap
      • basicEntitiesDecodingMap

        public static final java.util.HashMap basicEntitiesDecodingMap
      • FILE_SIZE_UNIT_DIV

        public static int FILE_SIZE_UNIT_DIV
      • URL_VALIDATOR_AUTHORITY_REGEX

        public static final java.lang.String URL_VALIDATOR_AUTHORITY_REGEX
        Regular expressions used to manually validate URL authorities if IANA domain name validation isn't desired.
        Since:
        JCMS-6942
        See Also:
        Constant Field Values
    • Method Detail

      • emptyTreeSet

        public static final <T> java.util.TreeSet<T> emptyTreeSet()
        Returns the empty TreeSet (immutable). Unlike the like-named field, this method is parameterized.

        This example illustrates the type-safe way to obtain an empty set:

         TreeSet<String> s = Util.emptyTreeSet();
         
        Returns:
        always return the same instance #EMPTY_TREESET
        See Also:
        EMPTY_TREESET
      • getKey

        public 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.
        Parameters:
        map - the Map to searhc on
        value - the value to search
        Returns:
        the key associated to a given value
      • getKeys

        public 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.
        Parameters:
        map - the Map to searhc on
        value - the value to search
        Returns:
        a Set of keys associated to a the given value
      • updateListMap

        public 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. Create a List of values if key already exists. If boolean "lazy" is false always create a List.
        Parameters:
        map - Map to work with
        key - Object key of the Map
        value - Object value of the map
        lazy - boolean true to create List only after 2 elements
      • getChildListMap

        public static java.lang.Object getChildListMap​(java.util.Map map,
                                                       java.lang.String key)
        Returns the first Value matching the given key
        Parameters:
        map - the Map
        key - Object key of the Map
        Returns:
        Object or null if key does not match
      • getChildrenListMap

        public static java.util.List getChildrenListMap​(java.util.Map map,
                                                        java.lang.String key)
        Returns values matching the given key.
        Parameters:
        map - the Map
        key - Object key of the Map
        Returns:
        List or null if key does not match
      • getChildrenListMap

        public static java.util.List getChildrenListMap​(java.util.Map map,
                                                        java.lang.String[] keys)
        Returns a new List of values matching the ordered given keys.
        Parameters:
        map - the Map
        keys - Object key of the Map
        Returns:
        List or null if key does not match
      • reverseMap

        public 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.
        Type Parameters:
        K - key
        V - value
        Parameters:
        originalMap - original map
        reverseMap - reverse map
        Returns:
        the reverse map
        Since:
        jcms-4.0
      • compareMap

        public 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.
        Parameters:
        map1 - the first map
        map2 - the second map.
        Returns:
        the common entry (from map1) or null.
        Since:
        jcms-5.7.0
      • isMapFilled

        public static <K,​V> boolean isMapFilled​(java.util.Map<K,​V> map)
        Returns true if the given map contains at least one value not empty.
        Parameters:
        map - the map.
        Returns:
        true if the given map contains at least one value not empty.
        Since:
        jcms-5.7.0
      • addAll

        public 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.
        Parameters:
        collection - Collection
        enu - Enumeration
        Returns:
        Collection
        Since:
        jcms-4.0
      • addAll

        public 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.
        Parameters:
        collection - the collection
        it - the iterator
        Returns:
        the collection
        Since:
        jcms-6.0.0
      • startsWith

        public 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
        Parameters:
        str - the String to match
        coll - a Collection of String that may be start of str
        Returns:
        The matching starting string or null
        Since:
        jcms-5.7.0
      • getString

        public 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.
        Parameters:
        obj - the object
        defaultValue - the default value
        Returns:
        the default value if the given object is null or if obj.toString() is null or empty
      • getString

        public 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. Check that the index, array are valid.
        Parameters:
        array - the object array
        index - the index
        defaultValue - the default value
        Returns:
        String
        Since:
        jcms-4.0
      • getObject

        public static java.lang.Object getObject​(java.lang.Object[] array,
                                                 int index,
                                                 java.lang.Object defaultValue)
      • getInt

        public static int getInt​(int[] array,
                                 int index,
                                 int defaultValue)
      • getBoolean

        public static boolean getBoolean​(boolean[] array,
                                         int index,
                                         boolean defaultValue)
      • getSize

        public static int getSize​(java.lang.String str)
        Returns the size of the given String. Returns 0 if the String is null.
        Parameters:
        str - the String.
        Returns:
        the size of the given String. Returns 0 if the String is null.
        Since:
        jcms-6.0.0
      • getSize

        public static int getSize​(java.lang.Object[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - the array.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-6.0.0
      • getSize

        public static int getSize​(byte[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of byte.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(short[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of short.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(int[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of int.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(long[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of long.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(float[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of float.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(double[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of double.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(boolean[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of boolean.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(char[] array)
        Returns the size of the given array. Returns 0 if the array is null.
        Parameters:
        array - an array of char.
        Returns:
        the size of the given array. Returns 0 if the array is null.
        Since:
        jcms-7.0.0
      • getSize

        public static int getSize​(java.util.Collection coll)
        Returns the size of the given collection. Returns 0 if the collection is null.
        Parameters:
        coll - the collection.
        Returns:
        the size of the given collection. Returns 0 if the collection is null.
        Since:
        jcms-6.0.0
      • getSize

        public static int getSize​(java.util.Map map)
        Returns the size of the given map. Returns 0 if the map is null.
        Parameters:
        map - the map.
        Returns:
        the size of the given map. Returns 0 if the map is null.
        Since:
        jcms-6.0.0
      • notEmpty

        public static boolean notEmpty​(java.io.File file)
        Returns true if this File is not null nor empty.
        Parameters:
        file - the file to test
        Returns:
        true if the file is not empty.
      • isEmpty

        public static boolean isEmpty​(java.io.File file)
        Returns true if this file is null or empty.
        Parameters:
        file - the file to test
        Returns:
        true if the file is empty.
      • notEmpty

        public static boolean notEmpty​(java.io.File file,
                                       java.io.FileFilter fileFilter)
        Returns true if this File is not null nor empty.
        Parameters:
        file - the file to test
        fileFilter - the filter
        Returns:
        true if the file is not empty.
      • isEmpty

        public static boolean isEmpty​(java.io.File file,
                                      java.io.FileFilter fileFilter)
        Returns true if this file is null or empty.
        Parameters:
        file - the file to test
        fileFilter - the filter
        Returns:
        true if the file is empty.
      • notEmpty

        public static boolean notEmpty​(java.lang.Object object)
        Returns true if this object is not null nor empty.
        Parameters:
        object - the object to test
        Returns:
        true if the object is not empty.
      • isEmpty

        public static boolean isEmpty​(java.lang.Object object)
        Returns true if this object is null or empty.
        Parameters:
        object - the object to test
        Returns:
        true if the object is empty.
      • notEmpty

        public static boolean notEmpty​(int[] array)
        Returns true if this array is not null nor empty.
        Parameters:
        array - the array to test
        Returns:
        true
      • isEmpty

        public static boolean isEmpty​(int[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(long[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(byte[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(short[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(float[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(double[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(boolean[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • isEmpty

        public static boolean isEmpty​(char[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • notEmpty

        public static boolean notEmpty​(java.lang.Object[] array)
        Returns true if this array is not null nor empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is not empty.
      • isEmpty

        public static boolean isEmpty​(java.lang.Object[] array)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty.
      • notEmpty

        public static boolean notEmpty​(java.lang.Object[] array,
                                       boolean recursive)
        Returns true if this array is not null nor empty.
        Parameters:
        array - the array to test
        recursive - check if arrays elements are empty
        Returns:
        true if the array is not empty.
      • isEmpty

        public static boolean isEmpty​(java.lang.Object[] array,
                                      boolean recursive)
        Returns true if this array is null or empty.
        Parameters:
        array - the array to test
        recursive - check if arrays elements are empty
        Returns:
        true if the array is empty.
      • notEmpty

        public static boolean notEmpty​(java.util.Collection<?> c)
        Returns true if this collection is not null nor empty.
        Parameters:
        c - the collection to test
        Returns:
        true if the collection is not empty.
      • isEmpty

        public static boolean isEmpty​(java.util.Collection<?> c)
        Returns true if this collection is null or empty.
        Parameters:
        c - the collection to test
        Returns:
        true if the collection is empty.
      • isEmpty

        public static boolean isEmpty​(java.util.Collection<?> c,
                                      boolean deep)
        Returns true if this collection is null or empty.
        Parameters:
        c - the collection to test
        deep - to call Util.isEmpty on content otherwise check only == null
        Returns:
        true if the collection is empty.
        Since:
        jcms-4.2
      • notEmpty

        public static boolean notEmpty​(java.util.Map<?,​?> map)
        Returns true if this map is not null nor empty.
        Parameters:
        map - the map to test
        Returns:
        true if the map is not empty.
        Since:
        jcms-4.1
      • isEmpty

        public static boolean isEmpty​(SQLQueryResult sqr)
        Returns true if this SQLQueryResult is null or empty.
        Parameters:
        sqr - the SQLQueryResult to test
        Returns:
        true if the SQLQueryResult is empty.
        Since:
        jcms-4.1
      • notEmpty

        public static boolean notEmpty​(SQLQueryResult map)
        Returns true if this SQLQueryResult is not null nor empty.
        Parameters:
        map - the SQLQueryResult to test
        Returns:
        true if the SQLQueryResult is empty.
        Since:
        jcms-4.1
      • isEmpty

        public static boolean isEmpty​(java.util.Map<?,​?> map)
        Returns true if this map is null or empty.
        Parameters:
        map - the map to test
        Returns:
        true if the map is empty.
        Since:
        jcms-4.1
      • mainTestEmpty

        public static void mainTestEmpty​(java.lang.String[] args)
      • join

        public 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. Uses the toString() method for each iterated Object.
        Parameters:
        col - the collection
        sep - the separator
        Returns:
        a String which contains all the iterated objects.
      • join

        public 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. Uses the toString() method for each iterated Object.
        Parameters:
        col - the collection
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        a String which contains all the iterated objects.
        Since:
        jcms-4.0
      • join

        public 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. Uses the toString() method for each iterated Object.
        Parameters:
        it - the iterator of the collection
        sep - the separator
        Returns:
        a String which contains all the iterated objects.
      • join

        public 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. Uses the toString() method for each iterated Object.
        Parameters:
        it - the iterator of the collection
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        a String which contains all the iterated objects.
        Since:
        jcms-4.0
      • joinMap

        public 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.
         Map<String, Object> map = new LinkedHashMap<String, Object>(); 
         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] }"
         
        Parameters:
        map - the map to join a
        keyValueSep - the separator to use between key and the value
        entrySep - the separator to use between each entry
        Returns:
        a new string (returns an empty string if map was null or empty)
      • listMap

        public static void listMap​(java.util.Map<?,​?> map)
        Lists a map on System.out.
        Parameters:
        map - the map to list
      • listMap

        public static void listMap​(java.util.Map<?,​?> map,
                                   java.io.PrintStream out)
        Lists a map on the given PrintStream.
        Parameters:
        map - the map to list
        out - the PrintStream to use to list the map
      • listMap

        public 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.
        Parameters:
        map - the map to list
        out - the PrintStream to use to list the map
        sep - the separator
      • listDictionary

        public static void listDictionary​(java.util.Dictionary<?,​?> dict)
        Lists a Dictionnary on System.out.
        Parameters:
        dict - the Dictionnary to list
      • listDictionary

        public static void listDictionary​(java.util.Dictionary<?,​?> dict,
                                          java.io.PrintStream out)
        Lists a Dictionnary on the given PrintStream.
        Parameters:
        dict - the Dictionnary to list
        out - the PrintStream to use to list the dictionnary
      • listDictionary

        public 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.
        Parameters:
        dict - the dictionnary to list
        out - the PrintStream to use to list the dictionnar
        sep - the separator
      • subMap

        public 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.
        Parameters:
        map - Map to work on
        keys - Set of key to remove
        Returns:
        Map a new HashMap or TreeMap contain map values without specified keys
      • interMap

        public 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.
        Parameters:
        map - Map to work on
        keys - Set of key
        Returns:
        Map a new HashMap or TreeMap contain map values with specified keys
      • prefixSet

        public 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
        Parameters:
        set - Set of String
        prefix - a String to prefix
        Returns:
        Set a new set
      • unionSet

        public static java.util.Set<?> unionSet​(java.util.Set<?>... sets)
        Returns the union of an array of Set. The result set does not contains null item.
        Parameters:
        sets - an array of Set
        Returns:
        the union Set (same class as the first set)
      • unionSet

        public static java.util.Set unionSet​(java.util.Set set1,
                                             java.util.Set set2)
        Returns the union of two Set.
        Parameters:
        set1 - the first Set
        set2 - the second Set
        Returns:
        the union Set
      • unionSet

        public static java.util.Set unionSet​(java.util.Set set1,
                                             java.util.Set set2,
                                             java.util.Set set3)
        Returns the union of three Set.
        Parameters:
        set1 - the first Set
        set2 - the second Set
        set3 - the thrid Set
        Returns:
        the union Set
      • interSet

        public static java.util.Set interSet​(java.util.Set... sets)
        Returns the intersection of an array of Set.
        Parameters:
        sets - an array of Set
        Returns:
        a new 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.
      • interSet

        public static java.util.Set interSet​(java.util.Set set1,
                                             java.util.Set set2)
        Returns the intersection of two Set.
        Parameters:
        set1 - the first Set
        set2 - the second Set
        Returns:
        the intersection Set
      • interSet

        public static java.util.Set interSet​(java.util.Set set1,
                                             java.util.Set set2,
                                             java.util.Set set3)
        Returns the intersection of three Set.
        Parameters:
        set1 - the first Set
        set2 - the second Set
        set3 - the thrid Set
        Returns:
        the intersection Set
      • subSet

        public static java.util.Set subSet​(java.util.Set... sets)
        Returns the subset of an array of Set. The subset contains all the elements of the first Set without those of the other Set.
        Parameters:
        sets - an array of Set
        Returns:
        the subset Set (same class as the first set)
      • subSet

        public static java.util.Set subSet​(java.util.Set set1,
                                           java.util.Set set2)
        Returns the subset of an array of Set. The subset contains all the elements of the first Set without those of the second Set.
        Parameters:
        set1 - the first Set
        set2 - the second Set
        Returns:
        the subset Set
      • subSet

        public 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. The subset contains all the elements of the first Set without those of the second and third Set.
        Parameters:
        set1 - the first Set
        set2 - the second Set
        set3 - the third Set
        Returns:
        the subset Set
      • mergeSet

        public static <T> java.util.Set<T> mergeSet​(java.util.Set<T> originalSet,
                                                    java.util.Set<T>... sets)
        Merge the variations of sets that have diverged from the same original set.
        Type Parameters:
        T - any type
        Parameters:
        originalSet - the original set
        sets - the new sets that have diverged from the original set
        Returns:
        the merge of the new sets based on originalSet.
        Since:
        jcms-10.0.6
      • getArrayList

        @SafeVarargs
        public static <T> java.util.ArrayList<T> getArrayList​(T... array)
        Returns a new ArrayList filled with the given objects (skip null object).
        Type Parameters:
        T - any type
        Parameters:
        array - a varargs of objects
        Returns:
        a new ArrayList filled with the given objects.
        Since:
        jcms-6.1.0
      • getArrayList

        @SafeVarargs
        public static <T> java.util.ArrayList<T> getArrayList​(boolean skipNull,
                                                              boolean trim,
                                                              T... array)
        Type Parameters:
        T - any type
        Parameters:
        skipNull - remove null object
        trim - if true remove the null at the end of the array
        array - a varargs of objects
        Returns:
        a new ArrayList filled with the given objects.
        Since:
        jcms-7.1.0
      • getHashSet

        @SafeVarargs
        public static <T> java.util.HashSet<T> getHashSet​(T... array)
        Returns a new HashSet filled with the given objects (skip null object).
        Type Parameters:
        T - any type
        Parameters:
        array - a varargs of objects
        Returns:
        a new HashSet filled with the given objects.
        Since:
        jcms-6.0.1
      • getTreeSet

        @SafeVarargs
        public static <T> java.util.TreeSet<T> getTreeSet​(T... array)
        Returns a new TreeSet filled with the given objects (skip null object).
        Type Parameters:
        T - any type
        Parameters:
        array - a varargs of objects
        Returns:
        a new TreeSet filled with the given objects.
        Since:
        jcms-6.0.1
      • getHashMap

        public 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).
        Type Parameters:
        K - any type
        V - any type
        Parameters:
        key - the first key to be added
        value - the first value to be added
        Returns:
        a HashMap filled with the given key/value pair.
        Since:
        jcms-5.7.3
      • getHashMap

        public 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)
        Type Parameters:
        K - any type
        V - any type
        Parameters:
        map - the map to be added
        Returns:
        a new HashMap filled with the given map.
        Since:
        jcms-6.0.0
      • getTreeMap

        public 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).
        Type Parameters:
        K - any type
        V - any type
        Parameters:
        key - the first key to be added
        value - the first value to be added
        Returns:
        a TreeMap filled with the given key/value pair.
        Since:
        jcms-5.7.3
      • getTreeMap

        public 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)
        Type Parameters:
        K - any type
        V - any type
        Parameters:
        map - the map to be added
        Returns:
        a new TreeMap filled with the given map.
        Since:
        jcms-6.0.0
      • getLinkedHashMap

        public 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).
        Type Parameters:
        K - any type
        V - any type
        Parameters:
        key - the first key to be added
        value - the first value to be added
        Returns:
        a LinkedHashMap filled with the given key/value pair.
        Since:
        jcms-5.7.3
      • getLinkedHashMap

        public 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)
        Type Parameters:
        K - any type
        V - any type
        Parameters:
        map - the map to be added
        Returns:
        a new LinkedHashMap filled with the given map.
        Since:
        jcms-6.0.0
      • getFirst

        public static <T> T getFirst​(java.util.Collection<T> coll)
        Returns the first item of the given collection (or null if the collection is empty).
        Parameters:
        coll - the collection
        Returns:
        the first item of the given collection (or null if the collection is empty).
        Since:
        jcms-6.0.0
      • getFirst

        public static <T> T getFirst​(T[] array)
        Returns the first item of the given array (or null if the array is empty).
        Parameters:
        array - the array
        Returns:
        the first item of the given array (or null if the array is empty).
        Since:
        jcms-6.0.0
      • getNext

        public static <T> T getNext​(java.util.Collection<T> coll,
                                    T item)
        Returns the next item of the given collection (or null if the collection is empty).
        Parameters:
        coll - the collection
        item - the item
        Returns:
        the next item of the given collection (or null if the collection is empty).
        Since:
        jcms-9.0.0
      • getNext

        public static <T> T getNext​(T[] array,
                                    T item)
        Returns the next item of the given array (or null if the array is empty).
        Parameters:
        array - the array
        item - the item
        Returns:
        the next item of the given array (or null if the array is empty).
        Since:
        jcms-9.0.0
      • getLast

        public static <T> T getLast​(java.util.SortedSet<T> set)
        Returns the last item of the given SortedSet (or null if the SortedSet is empty).
        Parameters:
        set - the SortedSet
        Returns:
        the last item of the given SortedSet (or null if the SortedSet is empty).
        Since:
        jcms-8.0.0
      • getLast

        public static <T> T getLast​(java.util.List<T> list)
        Returns the last item of the given List (or null if the List is empty).
        Parameters:
        list - the List
        Returns:
        the last item of the given List (or null if the List is empty).
        Since:
        jcms-8.0.0
      • getLast

        public static <T> T getLast​(T[] array)
        Returns the last item of the given array (or null if the array is empty).
        Parameters:
        array - the array
        Returns:
        the last item of the given array (or null if the array is empty).
        Since:
        jcms-8.0.0
      • addInMapHashSet

        public 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.
        Parameters:
        map - the map
        key - the key
        value - the value
        Since:
        jcms-7.0.0
      • removeFromMapHashSet

        public 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.
        Parameters:
        map - the map
        key - the key
        value - the value
        Since:
        jcms-7.0.0
      • addInMapLinkedHashSet

        public 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. This method have an underlying LinkedHashSEt to guarantee iteration order.
        Parameters:
        map - the map
        key - the key
        value - the value
        Since:
        jcms-7.0.0
      • removeFromMapLinkedHashSet

        public 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. This method have an underlying LinkedHashSet to guarantee iteration order.
        Parameters:
        map - the map
        key - the key
        value - the value
        Since:
        jcms-7.0.0
      • cleanMap

        public static <K,​V> java.util.Map<K,​V> cleanMap​(java.util.Map<K,​V> map)
        Removes all the entry of the given map with an empty value
        Parameters:
        map - the map to clean
        Returns:
        the given map (for method chaining)
        Since:
        jcms-10.0.0
      • getCleanMap

        public static <K,​V> java.util.Map<K,​V> getCleanMap​(java.util.Map<K,​V> map)
        Returns a copy of the given map without the entry with an empty value.
        The copy preserves the type for TreeMap, LinkedHashMap and HashMap. For other Map types, the copy is an HashMap.
        If the map parameter is null, it returns a new HashMap.
        Parameters:
        map - the map to copy
        Returns:
        a copy of the given map without the entry with an empty value.
        Since:
        jcms-10.0.0
      • cleanCollection

        public static <T> java.util.Collection<T> cleanCollection​(java.util.Collection<T> coll)
        Remove the null entries of the given collection. Caution, this method changes the content of the given collection.
        Parameters:
        coll - the collection to be cleaned
        Returns:
        the given collection without null entries.
        Since:
        jcms-4.1
      • collectionToCleanSet

        public 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.
        Parameters:
        coll - the collection
        Returns:
        a set which contains all the non empty element of the given collection.
        Since:
        jcms-5.5.0
      • stringArrayToCleanSet

        public 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.
        Parameters:
        array - the array
        Returns:
        a set which contains all the non empty cells of the given array.
        Since:
        jcms-5.5.0
      • addAll

        public 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.
        Parameters:
        array - the array to copy from
        coll - the collection to copy to
        Returns:
        the collection
        Since:
        jcms-4.1.1
      • addAll

        public 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"]
         
        Type Parameters:
        T - the component type of the array
        Parameters:
        array1 - 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
        Returns:
        The new array, 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.
        Throws:
        java.lang.IllegalArgumentException - if the array types are incompatible
      • putAll

        public 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.
        Parameters:
        array - the array to copy from
        map - the collection to copy to
        value - the value to set
        Returns:
        the collection
        Since:
        jcms-5.7
      • swapArray

        public static int[] swapArray​(int[] array,
                                      int from,
                                      int to,
                                      boolean roll,
                                      boolean copy)
        Swap two cells of an int array.
        Parameters:
        array - the array
        from - 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 start
        copy - return a copy of of the array
        Returns:
        int[]
      • swapArray

        public static boolean[] swapArray​(boolean[] array,
                                          int from,
                                          int to,
                                          boolean roll,
                                          boolean copy)
        Swap two cells of a boolean array.
        Parameters:
        array - the array of array
        from - 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 start
        copy - return a copy of of the array
        Returns:
        boolean[]
      • swapArray

        public static java.lang.Object[] swapArray​(java.lang.Object[] array,
                                                   int from,
                                                   int to,
                                                   boolean roll,
                                                   boolean copy)
        Swap two cells of an Object array.
        Parameters:
        array - the array of array
        from - 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 start
        copy - return a copy of of the array
        Returns:
        Object[]
      • insertArray

        public static int[] insertArray​(int[] array,
                                        int index,
                                        int elt)
        Insert an element into an int array and return a duplicate copy of it.
        Parameters:
        array - the array
        index - 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 inserted
        Returns:
        a new int[]
      • insertArray

        public static boolean[] insertArray​(boolean[] array,
                                            int index,
                                            boolean elt)
        Insert an element into a boolean array and return a duplicate copy of it.
        Parameters:
        array - the array
        index - 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 inserted
        Returns:
        a new boolean[]
      • insertArray

        public 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.
        Parameters:
        array - the array
        index - 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 inserted
        Returns:
        Object[]
      • removeArray

        public static java.lang.Object[] removeArray​(java.lang.Object[] array,
                                                     int index)
        Remove an element of an Array of object
        Parameters:
        array - the array of object
        index - the location of the element to be removed from
        Returns:
        Object[] remove a copy of the array without the element. If the index is bad then return the original array
      • removeArray

        public static java.lang.Object[] removeArray​(java.lang.Object[] array,
                                                     java.lang.Object obj)
        Remove an element of an Array of object
        Parameters:
        array - the array of object
        obj - the object to be removed
        Returns:
        Object[] remove a copy of the array without the element. If the index is bad then return the original array
      • removeArray

        public static int[] removeArray​(int[] array,
                                        int index)
        Remove an element of an Array of int
        Parameters:
        array - the array of int
        index - the location of the element to be removed from
        Returns:
        int[] remove a copy of the array without the element. If the index is bad then return the original array
      • removeArray

        public static boolean[] removeArray​(boolean[] array,
                                            int index)
        Remove an element of an Array of boolean
        Parameters:
        array - the array of boolean
        index - the location of the element to be removed from
        Returns:
        boolean[] remove a copy of the array without the element. If the index is bad then return the original array
      • removeArray

        public static java.lang.Object[] removeArray​(java.lang.Object[] array,
                                                     int from,
                                                     int to)
        Remove n elements of an Array of object
        Parameters:
        array - the array of int
        from - the location of the first element to be removed from
        to - the location of the last element to be removed from
        Returns:
        Object[] remove a copy of the array without the element. If the from or to is bad then return the original array
      • removeArray

        public static int[] removeArray​(int[] array,
                                        int from,
                                        int to)
        Remove n elements of an Array of int
        Parameters:
        array - the array of int
        from - the location of the first element to be removed from
        to - the location of the last element to be removed from
        Returns:
        int[] remove a copy of the array without the element. If the from or to is bad then return the original array
      • removeArray

        public static boolean[] removeArray​(boolean[] array,
                                            int from,
                                            int to)
        Remove n elements of an Array of boolean
        Parameters:
        array - the array of boolean
        from - the location of the first element to be removed from
        to - the location of the last element to be removed from
        Returns:
        boolean[] remove a copy of the array without the element. If the from or to is bad then return the original array
      • isSameContent

        public static boolean isSameContent​(boolean[] array1,
                                            boolean[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a boolean array
        array2 - a boolean array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(byte[] array1,
                                            byte[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a byte array
        array2 - a byte array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(char[] array1,
                                            char[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a char array
        array2 - a char array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(double[] array1,
                                            double[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a double array
        array2 - a double array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(float[] array1,
                                            float[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a float array
        array2 - a float array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(int[] array1,
                                            int[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - an int array
        array2 - an int array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(long[] array1,
                                            long[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a long array
        array2 - a long array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(short[] array1,
                                            short[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - a short array
        array2 - a short array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(java.lang.Object[] array1,
                                            java.lang.Object[] array2)
        Returns true if array1 has same content than array2.
        Parameters:
        array1 - an object array
        array2 - an object array
        Returns:
        true if array1 has same content than array2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(java.util.Collection col1,
                                            java.util.Collection col2)
        Returns true if col1 has same content than col2.
        Parameters:
        col1 - a Collection (a Set or a List)
        col2 - a Collection (a Set if col1 is a Set or a List if col1 is a List)
        Returns:
        true if col1 has same content than col2
        Since:
        jcms-9.0.3
        See Also:
        isSameContent(Set, Set), isSameContent(List, List)
      • isSameContent

        public static boolean isSameContent​(java.util.Set set1,
                                            java.util.Set set2)
        Returns true if set1 has same content than set2.
        Parameters:
        set1 - a Set
        set2 - a Set
        Returns:
        true if set1 has same content than set2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(java.util.List list1,
                                            java.util.List list2)
        Returns true if list1 has same content than list2.
        Parameters:
        list1 - a List
        list2 - a List
        Returns:
        true if list1 has same content than list2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(java.util.Map map1,
                                            java.util.Map map2)
        Returns true if map1 has same content than map2.
        Parameters:
        map1 - a Map
        map2 - a Map
        Returns:
        true if map1 has same content than map2 (note: null == empty)
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(java.lang.String str1,
                                            java.lang.String str2)
        Returns true if str1 has same content than str2.
        Parameters:
        str1 - a String
        str2 - a String
        Returns:
        true if str1 has same content than str2
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(java.util.Date date1,
                                            java.util.Date date2)
        Returns true if date1 has same content than date2.
        Parameters:
        date1 - a Date
        date2 - a Date
        Returns:
        true if date1 has same content than date2
        Since:
        jcms-2.2
      • isSameContent

        public static boolean isSameContent​(org.jdom.Element elt1,
                                            org.jdom.Element elt2)
        Returns true if elt1 has same content than elt2.
        Parameters:
        elt1 - a JDom Element
        elt2 - a JDom Element
        Returns:
        true if elt1 has same content than elt2
        Since:
        jcms-2.2
      • splitCollection

        public static <T extends java.util.Collection> java.util.List<T> splitCollection​(T coll,
                                                                                         int max)
        Split the given collection in sub collections having max elements.
        Parameters:
        coll - the collection to split
        max - the max element for each sub collections
        Returns:
        a list of the splitted collections.
        Since:
        jcms-10.0.0
      • getTreeDescendantSet

        public static java.util.TreeSet getTreeDescendantSet​(TreeNode node)
        Returns a TreeSet with all descendant of the given treenode, (excluding the node itself)
        Parameters:
        node - the node
        Returns:
        a TreeSet with all descendant of the given treenode, (excluding the node itself)
      • getTreeDescendantSet

        public static java.util.Set getTreeDescendantSet​(TreeNode node,
                                                         java.util.Set nodeSet)
      • getAllChildrenSet

        public static java.util.TreeSet getAllChildrenSet​(TreeNode node)
        Returns a TreeSet with all children of the given treenode, (including the node itself)
        Parameters:
        node - the node
        Returns:
        a TreeSet with all children of the given treenode, (including the node itself)
      • getAllChildren

        public 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.
        Parameters:
        node - the parent node
        nodeSet - the set to fill, if null, returns null
        Returns:
        the given set, filled with children and node.
      • isChildNode

        public static boolean isChildNode​(TreeNode node,
                                          TreeNode child)
        Test if a node is a child of an other node
        Return false if child == node
        Parameters:
        node - the parent node
        child - the node to seek
        Returns:
        boolean if the child is a child or subchild of node
      • isNodeChild

        public static boolean isNodeChild​(TreeNode parentNode,
                                          TreeNode child)

        Test if a node is a child of an other node
        Return false if child == node.

        Works like isChildNode(TreeNode, TreeNode) but use reverse algorithm using parent instead of children

        Use this method with Top/Down cached TreeNode

        Parameters:
        parentNode - the parent node
        child - the node to seek
        Returns:
        boolean if the child is a child or subchild of node
      • notEmpty

        public static boolean notEmpty​(java.lang.String s)
        Returns true if this string is not null nor empty (once trimmed).
        Parameters:
        s - the string to test
        Returns:
        true if the string is not empty.
      • isEmpty

        public static boolean isEmpty​(java.lang.String s)
        Returns true if this string is null or empty (once trimmed).
        Parameters:
        s - the string to test
        Returns:
        true if the string is empty.
      • splitToIntArray

        public static int[] splitToIntArray​(java.lang.String str,
                                            java.lang.String delim)
        Splits a String into an array of int.
        Parameters:
        str - the String to split
        delim - the delimiter (same as StringTokenizer)
        Returns:
        an array of String.
        See Also:
        splitToList(String, String), StringTokenizer
      • split

        public static java.lang.String[] split​(java.lang.String str,
                                               java.lang.String delim)
        Splits a String into an array of String.
        Parameters:
        str - the String to split
        delim - the delimiter (same as StringTokenizer)
        Returns:
        an array of String.
        See Also:
        splitToList(String, String), StringTokenizer
      • splitToList

        public static java.util.ArrayList<java.lang.String> splitToList​(java.lang.String str,
                                                                        java.lang.String delim)
        Splits a String into a list of String.
        Parameters:
        str - the String to split
        delim - the delimiter (same as StringTokenizer)
        Returns:
        an ArrayList of String.
        See Also:
        StringTokenizer
      • split

        public static java.lang.String[] split​(java.lang.String str,
                                               char delim,
                                               java.lang.String emptyToken)
        Splits a String into an array of String. This method does NOT work as split(str, delim) based on StringTokenizer. This one, checks for empty token. For instance, splitting "A||BC|" with '|' as delim and "EMPTY" as empty token will return: String[] {"A", "EMPTY", "BC", "EMPTY"}
        Parameters:
        str - the String to split
        delim - the delimiter
        emptyToken - the value to used when encounter an empty token
        Returns:
        an array of String.
        Since:
        jcms-3.0
      • splitWithPattern

        public 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. For each match, add group(1) if not empty otherwise adds group(0).

        Example1 (without group(1)):
        text: foo [one: 1] [two: 2] bar [three: 3] bar
        pattern: "\\[([^\\]]+)\\]"
        returns String[] {"one: 1", "two: 2", "three: 3" }

        Example2 (with group(1)):
        text: foo [one: 1] [two: 2] bar [three: 3] bar
        pattern: "\\[[^\\]]+\\]"
        returns String[] {"[one: 1]", "[two: 2]", "[three: 3]" }

        Parameters:
        text - the text to split.
        pattern - the pattern to split with.
        Returns:
        an array of String (never null)
        Since:
        jcms-5.7.2
      • trimEnd

        public static java.lang.String trimEnd​(java.lang.String str)
        Trim the end of a String
        Parameters:
        str - the String to trim
        Returns:
        String the trimmed String
      • getMatch

        public 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
        Parameters:
        regexp - the regular expression
        str - the String to match
        group - the group to match
        Returns:
        String the matching group
      • getMatch

        public 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
        Parameters:
        pattern - java.util.regex.Pattern
        str - the String to match
        group - the group to match
        Returns:
        String the matching group
      • wordWrap

        public 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("", *) = ""
         
        Parameters:
        str - the String to be word wrapped, may be null
        width - the column to wrap the words at, less than 1 is treated as 1
        Returns:
        a line with newlines inserted, null if null input TODO: replace with jakarta WordUtils.wrap()
      • wordWrap

        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("", *, *, *) = ""
         
        Parameters:
        str - the String to be word wrapped, may be null
        wrapLength - the column to wrap the words at, less than 1 is treated as 1
        newLineStr - the string to insert for a new line, null uses the system property line separator
        wrapLongWords - true if long words (such as URLs) should be wrapped
        Returns:
        a line with newlines inserted, null if null input TODO: replace with jakarta WordUtils.wrap()
      • mainTestGeneratePassword

        public static void mainTestGeneratePassword​(java.lang.String[] args)
      • mainTestJoin

        public static void mainTestJoin​(java.lang.String[] args)
      • join

        public static java.lang.String join​(java.lang.Object[] array,
                                            java.lang.String sep)
        Joins an array of String with the given separator.
        Parameters:
        array - the array of String to join.
        sep - the separator
        Returns:
        the join String.
      • join

        public 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.
        Parameters:
        array - the array of String to join.
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        the join String.
        Since:
        jcms-4.0
      • join

        public static java.lang.String join​(int[] array,
                                            java.lang.String sep)
        Joins an array of int with the given separator.
        Parameters:
        array - the array of int to join.
        sep - the separator
        Returns:
        the join String.
      • join

        public 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.
        Parameters:
        array - the array of int to join.
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        the join String.
        Since:
        jcms-4.0
      • join

        public 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
        Parameters:
        str - the strings to be joined.
        Returns:
        String
      • join

        public static java.lang.String join​(long[] array,
                                            java.lang.String sep)
        Joins an array of long with the given separator.
        Parameters:
        array - the array of long to join.
        sep - the separator
        Returns:
        the join String.
        Since:
        jcms-5.5
      • join

        public 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.
        Parameters:
        array - the array of long to join.
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        the join String.
        Since:
        jcms-5.5
      • join

        public static java.lang.String join​(double[] array,
                                            java.lang.String sep)
        Joins an array of double with the given separator.
        Parameters:
        array - the array of long to join.
        sep - the separator
        Returns:
        the join String.
        Since:
        jcms-5.5
      • join

        public 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.
        Parameters:
        array - the array of double to join.
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        the join String.
        Since:
        jcms-5.5
      • join

        public static java.lang.String join​(boolean[] array,
                                            java.lang.String sep)
        Joins an array of boolean with the given separator.
        Parameters:
        array - the array of boolean to join.
        sep - the separator
        Returns:
        the join String.
      • join

        public 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.
        Parameters:
        array - the array of boolean to join.
        sep - the separator
        max - the maximum of item to join
        suffix - the suffix to add if the maximum has been reached
        Returns:
        the join String.
        Since:
        jcms-4.0
      • toWordLine

        public 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).
        Parameters:
        str - the string to split
        Returns:
        the result String
        Since:
        jcms-2.2
      • repeat

        public static java.lang.String repeat​(java.lang.String pattern,
                                              int count)
        Repeat a String pattern count times
        Parameters:
        pattern - the pattern
        count - the number of times the pattern must be repeated
        Returns:
        a String containing the result
      • arrayContains

        public static boolean arrayContains​(java.lang.Object[] array,
                                            java.lang.Object key)
        Test if an array contains a given object. Return true if the test with '==' operator or 'equals' method returns true.
        Parameters:
        array - the array to be searched.
        key - the value to be searched for.
        Returns:
        true if the array contains the given object.
      • trim

        public static java.lang.String[] trim​(java.lang.String[] array)
        Remove the trailing empty cells of the given String array. E.g. trimString(new String[] {"", "x", "", "y", null, ""}) returns {"", "x", "y"}.
        Parameters:
        array - the array to be trimmed
        Returns:
        the trimmed array
      • trimStringArray

        public static java.lang.String[] trimStringArray​(java.lang.String[] array)
        Remove the trailing empty cells of the given String array. E.g. trimStringArray(new String[] {"", "x", "", "y", null, ""}) returns {"", "x", "y"}.
        Parameters:
        array - the array to be trimmed
        Returns:
        the trimmed array
      • trimList

        public 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.
        Type Parameters:
        T - any type
        Parameters:
        list - the list to be trimmed
        Returns:
        a copy of the given list without any null values at the end.
        Since:
        jcms-5.7.0
      • cleanStringArray

        public 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). Each string is trimed.
        Parameters:
        array - the array to be cleaned
        Returns:
        the cleaned array
      • cleanObjectArray

        public static java.lang.Object[] cleanObjectArray​(java.lang.Object[] array)
        Creates a new array that contains all elements of the given array without null.
        Parameters:
        array - the array to be cleaned
        Returns:
        the cleaned array
        Since:
        jcms-5.0.5
      • unaccentuate

        public static java.lang.String unaccentuate​(java.lang.String str)
        Removes all the accentuate chars of the given string. The following accentuate chars are supported: À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Œ Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö œ ù ú û ü ý þ ÿ
        Parameters:
        str - the String to unaccentuate.
        Returns:
        an unaccentuate String.
      • unaccentuateRegexp

        public static java.lang.String unaccentuateRegexp​(java.lang.String str)
        Build an unaccentuated version of the given regexp. E.g. char 'e' is replaced by (e|é|è|ê|ë).
        Parameters:
        str - the String of the regexp to unaccentuate.
        Returns:
        an unaccentuate String.
      • recapitalize

        public static java.lang.String recapitalize​(java.lang.String str)
        Force the first char of a String to be a uppercase char.
        Parameters:
        str - the String to proceed
        Returns:
        the result String
      • uncapitalize

        public static java.lang.String uncapitalize​(java.lang.String str)
        Force the first char of a String to be a lowercase char.
        Parameters:
        str - the String to proceed
        Returns:
        the result String
        Since:
        jcms-2.2
      • cryptUnix

        public static java.lang.String cryptUnix​(java.lang.String str)
        Deprecated.
        using this algorythm for "encryption" is completely unsecure. Do NOT use.
        Encrypt the given string with the Unix crypt algorithm
        Parameters:
        str - the String to encrypt
        Returns:
        the encrypted string
        Since:
        jcms-4.0
      • cryptMD5

        public static java.lang.String cryptMD5​(java.lang.String str)
        Deprecated.
        using MD5 algorithm for "encryption" is completely unsecure, don't.
        If you need to encrypt data, use a dedicated library.
        If you need to validate passwords or other kind of authentication digest, use strong algorithm such as BCrypt.
        If you need to hash data for signing or other basic use case, use DigestUtils from Apache Commons Codec.
        And if you absolutely need the same contract for backward compatibility, use md5Base64(String) which provides exactly the same behavior with a method name which does not implying it can be used for encryption.
        Encrypt the given string with the MD5 algorithm and BASE64
        Parameters:
        str - the String to encrypt
        Returns:
        the encrypted string
        Since:
        jcms-4.0
      • md5Base64

        public static java.lang.String md5Base64​(java.lang.String str)
        Calculates the MD5 digest and returns the value as a base64 string.

        This method is provided for backward compatibility to replace the deprecated method cryptMD5(String).
        For any new developpement, prefer the use of DigestUtils.md5Hex from Apache Commons Codec.

        Parameters:
        str - the data to digest
        Returns:
        MD5 digest as a base64 string
        Since:
        jcms-10.0.0 DEVJCMS-2504
      • encodeBASE64

        public static java.lang.String encodeBASE64​(java.lang.String str)
        Encode the given string using BASE64 algorithm. The output is chuncked every 76 character. Equivalent to 'Util.encodeBase64(str, true)'
        Parameters:
        str - the String to encode
        Returns:
        the encoded string
        Since:
        jcms-5.5.0
      • encodeBASE64

        public static java.lang.String encodeBASE64​(java.lang.String str,
                                                    boolean isChunck)
        Encode the given string using BASE64 algorithm.
        Parameters:
        str - the string to encode
        isChunck - - if true this encoder will chunk the base64 output into 76 character blocks
        Returns:
        the encoded string
        Since:
        jcms-6.0
      • decodeBASE64

        public static java.lang.String decodeBASE64​(java.lang.String str)
        Decode the given string using BASE64 algorithm
        Parameters:
        str - the String to decode
        Returns:
        the decoded string
        Since:
        jcms-5.5.0
      • encryptDES3

        public static java.lang.String encryptDES3​(java.lang.String clearStr)
                                            throws StringEncrypter.EncryptionException
        Encrypt the specified string using DESede StringEncrypter with an internal key.

        WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
        Parameters:
        clearStr - the string to encrypt.
        Returns:
        the encrypted string prefixed, or null/empty string if the specified clearStr was null/empty.
        Throws:
        StringEncrypter.EncryptionException - if the encryption could not be performed
        Since:
        jcms-5.7.0
      • decryptDES3

        public static java.lang.String decryptDES3​(java.lang.String encryptedStr)
                                            throws StringEncrypter.EncryptionException
        Decrypt the specified string using DESede StringEncrypter using same internal key used by encryptDES3(String).
        Parameters:
        encryptedStr - the encrypted string to decrypt. if null or empty, the return
        Returns:
        the decrypted string, or null/empty string if the specified encryptedStr was null/empty
        Throws:
        StringEncrypter.EncryptionException - if the decryption could not be performed
        Since:
        jcms-5.7.0
      • conceal

        public static java.lang.String conceal​(java.lang.String clearStr)
        Conceal the given string with an internally choosen encryption algorithm.

        WARNING: This method is not mathematically safe and is only used to hide sensitive data on first look.
        WARNING: This method will return the clear text string if the string could not be encrypted.
        Parameters:
        clearStr - the String to encrypt
        Returns:
        the encrypted string
        Since:
        jcms-5.7
      • reveal

        public static java.lang.String reveal​(java.lang.String concealedStr)
        Reveal the specified hidden string with an internally choosen encryption algorithm.
        Parameters:
        concealedStr - the String to encrypt
        Returns:
        the encrypted string
        Since:
        jcms-5.7
      • isConcealed

        public static boolean isConcealed​(java.lang.String str)
      • buildID

        public 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.
        Parameters:
        str - the String to used as base for the ID
        charRange - 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)
        Returns:
        the ID
        Since:
        jcms-4.0.1
      • buildID

        public 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.
        Parameters:
        str - the String to used as base for the ID
        Returns:
        the ID
        Since:
        jcms-4.0
      • buildCamelID

        public 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.
        Parameters:
        str - the String to used as base for the ID
        Returns:
        the ID
        Since:
        jcms-5.7.0
      • buildUID

        public 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. Add a number to the id if it already exists.
        Parameters:
        str - the String to used as base for the ID
        strSet - the set of String of existing ids
        Returns:
        the ID
      • mainTestBuildID

        public static void mainTestBuildID​(java.lang.String[] args)
      • escapePercent

        public static java.lang.String escapePercent​(java.lang.String url)
        This method replace % in wrong hexa character by '_' character
        Parameters:
        url - the utf-8 string to escape
        Returns:
        String the escaped String
      • escapeRegexp

        public static java.lang.String escapeRegexp​(java.lang.String string)
        Escape a (OROMatcher) regular expression with support of basic regexp (* and ?). Example: (a*b?) will be escaped into \(a.*b.?\).
        Parameters:
        string - the regexp string to be escaped
        Returns:
        the escaped string
        See Also:
        escapeRegexp(String,boolean)
      • escapeRegexp

        public static java.lang.String escapeRegexp​(java.lang.String string,
                                                    boolean basicRegexp)
        Escape a (OROMatcher) regular expression with support of basic regexp (* and ?). Example: (a*b?) will be escaped into \(a.*b.?\).
        Parameters:
        string - the regexp string to be escaped
        basicRegexp - if true convert * and ? to Perl5 regular expression
        Returns:
        the escaped string
        Since:
        jcms-4.1
      • escapeChars

        public static java.lang.String escapeChars​(java.lang.String str,
                                                   java.lang.String charsToEscape)
        Escape specified characters in a String.

        Example:

         Util.escapeChar("ab|cde%fg|hi=j", "|="); // -> ab%7ccde%25fg%7chi%3dj
         
        Parameters:
        str - the string
        charsToEscape - a string containing all the chararacters to escape
        Returns:
        a new String with all charToEscape escaped
      • unescapeChar

        public static java.lang.String unescapeChar​(java.lang.String str)
        Unescape escaped character in a String. Character to unescape are prepended with ESCAPE_CHAR.

        Example:

         Util.unescapeChar("ab%7ccde%25fg%7chij"); // -> ab|cde%fg|hij
         
        Parameters:
        str - the string
        Returns:
        a new String with all charToUnescape unescaped
      • escapeLuceneQuery

        public static java.lang.String escapeLuceneQuery​(java.lang.String str)
        Escape Lucene special chars used in classic QueryParser. I.e. + - && || ! ( ) { } [ ] ^ " ~ * ? : \ (see https://lucene.apache.org/core/6_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html)
        Parameters:
        str - the string to escape
        Returns:
        the escaped string
        Since:
        jcms-4.0
      • replace

        public 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)
        Parameters:
        str - the input String
        match - a Perl5 regexp
        rep - a Perl5 replace pattern
        Returns:
        the modified String
      • replace

        public static java.lang.String replace​(java.lang.String str,
                                               java.lang.String pattern)
        Search and replace a string by another one
        Parameters:
        str - the input String
        pattern - the Perl5 substitution pattern (e.g. s!regexp!replace!)
        Returns:
        the modified String
      • replace

        public static java.lang.String replace​(java.lang.String text,
                                               java.lang.String regexp,
                                               RegexpSubstitution substitution)
                                        throws org.apache.oro.text.regex.MalformedPatternException
        Replaces the given regexp in the given text with the given substitution function.
        Parameters:
        text - the text
        regexp - the regexp
        substitution - the RegexpSubstitution function called.
        Returns:
        the result text or the given text if there is null parameter
        Throws:
        org.apache.oro.text.regex.MalformedPatternException - if an error has occurred.
        Since:
        jcms-6.0.0
      • replace

        public 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.
        Parameters:
        text - the text
        pattern - the pattern
        substitution - the RegexpSubstitution function called.
        Returns:
        the result text or the given text if there is null parameter
        Since:
        jcms-6.0.0
      • replace

        public static java.lang.String replace​(java.lang.String input,
                                               java.util.regex.Pattern regex,
                                               MatcherCallback callback)
        Searches a string for a specified regular expression, and returns a new string where the specified values are replaced.
         Pattern regex = Pattern.compile("\\d+");
         String result = StringReplacer.replace("test6test12hoho", regex, (Matcher m) -> {
         return "" + (Integer.parseInt(m.group()) * 2);
         });
         
        Parameters:
        input - the input String
        regex - Regular expression that will be replaced by the new value
        callback - callback to return the replacement text
        Returns:
        A new String, where the specified regular expression has been replaced by the new value
      • replaceAll

        public static java.lang.String replaceAll​(java.lang.String input,
                                                  java.lang.String searchString,
                                                  java.lang.String replaceString)
        Replace all occurrences of searchString with replaceString in input string. DO NOT use any regular expressions.
        Parameters:
        input - represents input string
        searchString - represents substring for replace
        replaceString - represents replaced string value
        Returns:
        new string with replaced values
        Since:
        jcms-5.5.0
      • removeBlankLines

        public static java.lang.String removeBlankLines​(java.lang.String str)
        Cleans the given string : remove pure blank lines and remove leadings white spaces. This method has been rewritten in jcms-5.0.1 and is about twice faster than the previous implementation.
        Parameters:
        str - the String to be cleaned
        Returns:
        the cleaned String
        Since:
        jcms-4.0
      • escapeBackslash

        public static java.lang.String escapeBackslash​(java.lang.String str)
        Escape all the '\' in the given String ('\\')
        Parameters:
        str - the String to escape
        Returns:
        the escaped String
      • escapeJavaStringChar

        public static java.lang.String escapeJavaStringChar​(java.lang.String str)
        Escape all the invalid char in Java String:
        • '\' -> "\\"
        • CR -> "\n"
        • '"' -> \"
        Parameters:
        str - the String to escape
        Returns:
        the escaped String
      • escapeJavaScriptQuote

        @Deprecated
        public static java.lang.String escapeJavaScriptQuote​(java.lang.String str)
        Deprecated.
        use com.jalios.jcms.HttpUtil.encodeForJavaScript
        Escape JavaScript quotes
        • ' -> \'
        • " -> \"
        Parameters:
        str - the String to escape
        Returns:
        the escaped String
        Since:
        jcms-2.2
      • getFirstSentences

        public static java.lang.String getFirstSentences​(java.lang.String text,
                                                         int limit)
        Get the first sentences in a given string.
        Parameters:
        text - the string to get the first sentence.
        limit - how many sentences to get (return the original text if limit <0).
        Returns:
        a string containing the first sentences.
      • mainSwapArray

        public static void mainSwapArray​(java.lang.String[] args)
      • mainRemoveArray

        public static void mainRemoveArray​(java.lang.String[] args)
      • truncateHtml

        public static java.lang.String truncateHtml​(java.lang.String text,
                                                    int length,
                                                    boolean trim)
        Truncate an HTML string.

        - Prevents html tags to be split in the middle of the attributes.
        That is, the string "the image: <img src='some.jpg' border='0'>"
        will end "the image: "

        - Warning: do not prevent opened tag not to be closed:
        with a string "go there: <a href='hello'>a link</a>"
        you can end with "go there: <a href='hello'>a lin" which is invalid html

        Use HtmlUtil.truncate(String, int, String) for advanced HTML support.

        Parameters:
        text - the HTML content to be truncated
        length - the length to keep.
        trim - if true trims the input text
        Returns:
        the truncated text
      • truncate

        public static java.lang.String truncate​(java.lang.String str,
                                                int length)
        Truncates the given String.
        Parameters:
        str - the String to truncate
        length - the length to truncate to
        Returns:
        the truncated string
        Since:
        jcms-6.1.0
      • truncate

        public static java.lang.String truncate​(java.lang.String str,
                                                int length,
                                                java.lang.String suffix)
        Truncates the given String
        Parameters:
        str - the String to truncate
        length - the length to truncate to
        suffix - the suffix to add if the string has been truncated
        Returns:
        the truncated string
        Since:
        jcms-4.0.2
      • truncate

        public static java.lang.String truncate​(java.lang.String str,
                                                int length,
                                                java.util.Map<java.lang.String,​java.lang.String> truncatedMap)
        Returns a unique truncated string. If str <= length it returns str if str > length it returns a truncated version of str that has not been already used.

        When call twice with the same too long string it returns the same truncated string.

        Example:

        Map<String,String> truncatedMap = new HashMap<String,String>()
        Util.truncate("co", 4, truncatedMap) => "co"
        Util.truncate("comm", 4, truncatedMap) => "comm"
        Util.truncate("common1", 4, truncatedMap) => "com0"
        Util.truncate("common2", 4, truncatedMap) => "com1"
        Util.truncate("common3", 4, truncatedMap) => "com2"
        Util.truncate("common1", 4, truncatedMap) => "com0"
        Util.truncate("common4", 4, truncatedMap) => "com3"

        The method must be called with the same length attribute each time it is called with the same truncatedMap

        Parameters:
        str - the String to truncate
        length - the length to truncate to
        truncatedMap - a map to memorize the truncation
        Returns:
        a unique truncated string.
        Since:
        jcms-10.0.0
      • html2Ascii

        @Deprecated
        public static java.lang.String html2Ascii​(java.lang.String str)
        Deprecated.
        since jcms-9.0.0
        Convert the specified string from HTML to raw text, preserving and converting as much spaces as possibles (space, <br>, carriage return, line feeds, ...).

        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 HtmlUtil.html2text(String).
        More information on this problem in JIRA issue JCMS-2628

        Parameters:
        str - the html to convert
        Returns:
        the text converted
        See Also:
        HtmlUtil.html2text(String)
      • surround

        public 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. Otherwise, returns an empty text.
        Parameters:
        inside - The text to be surrounded.
        begin - The text at the beginning.
        end - The text at the end.
        Returns:
        The given text surrounded.
      • surroundWithTag

        public static java.lang.String surroundWithTag​(java.lang.String inside,
                                                       java.lang.String tag)
        Surround a given text (the first argument) with a html tag. If the text is empty, returns an empty text. If the tag is empty, returns the original text.
        Parameters:
        inside - The text to be surrounded.
        tag - The tag
        Returns:
        The text surrounded.
      • decodeUrl

        public static java.lang.String decodeUrl​(java.lang.String str)
      • encodeUrl

        public 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.
        Parameters:
        s - String to be translated.
        Returns:
        the translated String.
      • encodeUrl

        public 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.
        Parameters:
        s - String to be translated.
        enc - String encoding
        Returns:
        the translated String.
      • encodeCookie

        public static java.lang.String encodeCookie​(java.lang.String src)
      • decodeCookie

        public static java.lang.String decodeCookie​(java.lang.String src)
      • isoLatin1ToEntities

        public static java.lang.String isoLatin1ToEntities​(java.lang.String src)
        Convert all the isoLatin1 accent into XML entities (e.g. 'é' -> &eacute;)
        Parameters:
        src - the String to convert
        Returns:
        the converted String
      • entitiesToIsoLatin1

        public static java.lang.String entitiesToIsoLatin1​(java.lang.String src)
        Does the opposite of isoLatin1ToEntities.
        Parameters:
        src - the String to convert
        Returns:
        the converted String
      • encodeHtmlBasicEntities

        public static java.lang.String encodeHtmlBasicEntities​(java.lang.String src)
        Encode given string according to the following table.
        • " : &quot;
        • ' : &#039;
        • < : &lt;
        • > : &gt;
        • & : &amp;
        Parameters:
        src - the String to convert
        Returns:
        the converted String
      • decodeHtmlBasicEntities

        public static java.lang.String decodeHtmlBasicEntities​(java.lang.String src)
        Does the opposite job of encodeHtmlBasicEntities.
        Parameters:
        src - the String to convert
        Returns:
        the converted String
      • performEncoding

        public 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.
        Parameters:
        src - the String to convert
        transMap - the translation map
        Returns:
        the converted String
      • performDecoding

        public 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.
        Parameters:
        src - the String to convert
        transMap - the translation map
        Returns:
        the converted String
      • performEncodeDecode

        public 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. If encoding replace occurence of keys with values. If decoding replace occurence of values with keys
        Parameters:
        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 keys
        Returns:
        the converted String
      • encodeIntArray

        public static java.lang.String encodeIntArray​(int[] array)
      • decodeIntArray

        public static int[] decodeIntArray​(java.lang.String param)
      • encodeIntArray

        public static java.lang.String encodeIntArray​(int[] array,
                                                      char separator)
      • decodeIntArray

        public static int[] decodeIntArray​(java.lang.String param,
                                           char separator)
      • encodeStringArray

        public static java.lang.String encodeStringArray​(java.lang.String[] array)
      • decodeStringArray

        public static java.lang.String[] decodeStringArray​(java.lang.String param)
      • encodeStringArray

        public static java.lang.String encodeStringArray​(java.lang.String[] array,
                                                         char separator)
      • decodeStringArray

        public static java.lang.String[] decodeStringArray​(java.lang.String param,
                                                           char separator)
      • encodeObject

        public static java.lang.String encodeObject​(java.lang.Object obj)
        Returns the encoded objected as a String.
        Parameters:
        obj - the object to be encoded
        Returns:
        the encoded objected as a String.
        Since:
        jcms-6.0.0
        See Also:
        decodeObject(String)
      • decodeObject

        public static java.lang.Object decodeObject​(java.lang.String encoded)
        Returns the object decoded from the given String.

        Warning: This method uses object deserialization, NEVER use with untrusted data.

        Parameters:
        encoded - the String that contains the encoded object
        Returns:
        the object decoded from the given String.
        Since:
        jcms-6.0.0
        See Also:
        encodeObject(Object)
      • toArray

        public static java.lang.Object[] toArray​(java.lang.Object obj,
                                                 java.lang.Object[] defaultValues)
        Converts an object value to an arrays of Object.
        Parameters:
        obj - object to convert, may be null
        defaultValues - array of default values used when the specified object could not be converted.
        Returns:
        array of Object
      • toString

        public static java.lang.String toString​(java.lang.Object obj,
                                                java.lang.String defaultValue)
        Converts an object value to a String.
        Parameters:
        obj - object containing a string, may be null
        defaultValue - default value used when the specified object could not be converted.
        Returns:
        String created from the object
      • toStringArray

        public static java.lang.String[] toStringArray​(java.lang.Object obj,
                                                       java.lang.String[] defaultValues)
        Converts an object value to a String array.
        Parameters:
        obj - object containing strings, may be null
        defaultValues - array of default values used when the specified object could not be converted.
        Returns:
        String array created from the object
      • isNumber

        public static boolean isNumber​(java.lang.String str)
        Returns true if the given string only contains 0-9 characters
        Parameters:
        str - the String to be checked
        Returns:
        true if the given string only contains 0-9 characters
      • toNumber

        public static java.lang.Number toNumber​(java.lang.Object obj,
                                                java.lang.Number defaultValue)
        Converts an object value to a Number.
        Parameters:
        obj - object containing a number, may be null
        defaultValue - default value used when the specified object could not be converted.
        Returns:
        Number created from the object
      • toNumberArray

        public static java.lang.Number[] toNumberArray​(java.lang.Object obj,
                                                       java.lang.Number[] defaultValues)
        Converts an object value to a Number array.
        Parameters:
        obj - object containing numbers, may be null
        defaultValues - array of default values used when the specified object could not be converted.
        Returns:
        Number array created from the object
      • toInteger

        public static java.lang.Integer toInteger​(java.lang.Object obj,
                                                  java.lang.Integer defaultValue)
        Converts an object value to an Integer.
        Parameters:
        obj - object containing an integer, may be null
        defaultValue - default value used when the specified object could not be converted.
        Returns:
        Integer created from the object
      • toIntArray

        public static int[] toIntArray​(java.lang.Object[] objs,
                                       int def)
        Convert an Object[] (assert to be either a String or a Integer) to a int
        Parameters:
        objs - the object array to convert
        def - default int value to use is object is empty, not a String nor a Integer
        Returns:
        a int[] or null if objs is null
        Since:
        jcms-5.6.0
        See Also:
        toInt(Object, int)
      • toInt

        public static int toInt​(java.lang.Object obj,
                                int def)
        Convert an Object (assert to be either a String or a Integer) to a int
        Parameters:
        obj - the object to convert
        def - default int value to use is object is empty, not a String nor a Integer
        Returns:
        a int
        Since:
        jcms-4.0
      • toFloat

        public static float toFloat​(java.lang.Object obj,
                                    float def)
        Convert an Object (assert to be either a String or a Float) to a float
        Parameters:
        obj - the object to convert
        def - default float value to use is object is empty, not a String nor a Float
        Returns:
        a float
        Since:
        jcms-4.0
      • toByte

        public static byte toByte​(java.lang.Object obj,
                                  byte def)
        Convert an Object (assert to be either a String or a Byte) to a byte
        Parameters:
        obj - the object to convert
        def - default byte value to use is object is empty, not a String nor a Byte
        Returns:
        a byte
        Since:
        jcms-4.0
      • toShort

        public static short toShort​(java.lang.Object obj,
                                    short def)
        Convert an Object (assert to be either a String or a Short) to a short
        Parameters:
        obj - the object to convert
        def - default short value to use is object is empty, not a String nor a Short
        Returns:
        a short
        Since:
        jcms-4.0
      • toLong

        public static long toLong​(java.lang.Object obj,
                                  long def)
        Convert an Object (assert to be either a String or a Long) to a long
        Parameters:
        obj - the object to convert
        def - default long value to use is object is empty, not a String nor a Long
        Returns:
        a long
        Since:
        jcms-4.0
      • toDouble

        public static double toDouble​(java.lang.Object obj,
                                      double def)
        Convert an Object (assert to be either a String or a Double) to a double
        Parameters:
        obj - the object to convert
        def - default double value to use is object is empty, not a String nor a Double
        Returns:
        a double
        Since:
        jcms-4.0
      • parseDouble

        public static java.lang.Double parseDouble​(java.lang.String str)
        Parse string into Double.

        Support most common decimal mark and grouping seperator without using any Locale specific behavior.

        Parameters:
        str - the string to parse
        Returns:
        a Double instance or null if str could not be parsed
      • toChar

        public static char toChar​(java.lang.Object obj,
                                  char def)
        Convert an Object (assert to be either a String or a Character) to a char
        Parameters:
        obj - the object to convert
        def - default char value to use is object is empty, not a String nor a Character
        Returns:
        a char
        Since:
        jcms-4.0
      • toBoolean

        public static boolean toBoolean​(java.lang.Object obj,
                                        boolean def)
        Convert an Object (assert to be either a String or a Boolean) to a boolean
        Parameters:
        obj - the object to convert
        def - default boolean value to use is object is empty, not a String nor a Boolean
        Returns:
        a boolean
        Since:
        jcms-4.0
      • toDate

        public 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
        Parameters:
        str - the String to parse
        format - the date Format (can be null)
        loc - the Locale tio use (can be null)
        def - the default Date to return if errors append.
        Returns:
        the converted Date
      • formatSize

        public static java.lang.String formatSize​(long size,
                                                  java.util.Locale locale)
        This method format the given number using International System prefix (aka metric system).

        Example: 4096 -> 4k, 532923 -> 520.43k

        Parameters:
        size - the size to format
        locale - the locale to use for the unit
        Returns:
        the formatted file size
      • formatFileSize

        public static java.lang.String formatFileSize​(long size)
        This method format the given size on the greatest unit. Example: 4096 -> 4 KB, 532923 -> 520.43 KB Use default locale.

        The format used is plain text.

        Parameters:
        size - the size to format
        Returns:
        the formatted file size
      • formatFileSize

        public static java.lang.String formatFileSize​(long size,
                                                      java.util.Locale locale)
        This method format the given size on the greatest unit. Example: 4096 -> 4 KB, 532923 -> 520.43 KB

        The format used is HTML (with detailled abbreviations).

        Parameters:
        size - the size to format
        locale - the locale to use for the unit
        Returns:
        the formatted file size
      • formatFileSize

        public static java.lang.String formatFileSize​(long size,
                                                      java.util.Locale locale,
                                                      boolean htmlDisplay)
        This method format the given size on the greatest unit. Example: 4096 -> 4 KB, 532923 -> 520.43 KB
        Parameters:
        size - the size to format
        locale - the locale to use for the unit
        htmlDisplay - if true, uses an html format, with detailled abbreviation, otherwise, use only plain text
        Returns:
        the formatted file size
      • getFileSizeWidgetElt

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

        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" }
         
        Parameters:
        size - the real size
        Returns:
        a array of 2 strings :
        [0] is the value, converted in the proper unit,
        [1] is the unit (empty string for bytes value, "KB", "MB", "GB" or "TB").
        See Also:
        convertFileSizeWidgetElt(String, String)
      • convertFileSizeWidgetElt

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

        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)
         
        Parameters:
        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"
        Returns:
        the real value in bytes
        See Also:
        getFileSizeWidgetElt(long)
      • getFileSizeWidgetUnit

        public static java.lang.String[] getFileSizeWidgetUnit​(java.util.Locale locale)
        Retrieve an array containing I18Ned labels to express file size, from bytes to petaabytes.

        Example :

         Util.getFileSizeUnitLabels(Locale.ENGLISH);
         -> { "","KB","MB","GB","TB", "PB" }
         Util.getFileSizeUnitLabels(Locale.FRENCH);
         -> { "","Ko","Mo","Go","To", "Po" }
         Util.getFileSizeUnitLabels(new Locale("tlh"));
         -> { "","KB","MB","GB","TB", "PB" }
         
        Parameters:
        locale - the Locale in which to retrieve the label
        Returns:
        an array of 6 labels, in the specified Locale if it exists, otherwise in english, never return null.
      • getFileSizeUnitLabels

        public static java.lang.String[] getFileSizeUnitLabels​(java.util.Locale locale)
        Retrieve an array containing I18Ned labels to express file size, from bytes to petabytes.

        Example :

         Util.getFileSizeUnitLabels(Locale.ENGLISH);
         -> { "b","KB","MB","GB","TB", "PB" }
         Util.getFileSizeUnitLabels(Locale.FRENCH);
         -> { "o","Ko","Mo","Go","To", "Po" }
         Util.getFileSizeUnitLabels(new Locale("tlh"));
         -> { "B","KB","MB","GB","TB", "PB" }
         
        Parameters:
        locale - the Locale in which to retrieve the label
        Returns:
        an array of 6 labels, in the specified Locale if it exists, otherwise in english, never return null.
      • getFileSizeUnitHTMLLabels

        public static java.lang.String[] getFileSizeUnitHTMLLabels​(java.util.Locale locale)
        Retrieve an array containing I18Ned labels to express file size, from bytes to petabytes.

        Example :

         Util.getFileSizeUnitLabels(Locale.ENGLISH);
         -> { "<abbr title=\"bytes\">B</abbr>","<abbr title=\"kilo bytes\">KB</abbr>","<abbr title=\"mega bytes\">MB</abbr>","<abbr title=\"giga
         bytes\">GB</abbr>","<abbr title=\"tera bytes\">TB</abbr>","<abbr title=\"peta octets\">PB</abbr>" }
         Util.getFileSizeUnitLabels(Locale.FRENCH);
         -> { "<abbr title=\"octets\">o</abbr>","<abbr title=\"kilo octets\">Ko</abbr>","<abbr title=\"mega octets\">Mo</abbr>","<abbr title=\"giga
         octets\">Go</abbr>","<abbr title=\"tera octets\">To</abbr>","<abbr title=\"peta octets\">Po</abbr>" }
         Util.getFileSizeUnitLabels(new Locale("tlh"));
         -> { "<abbr title=\"bytes\">B</abbr>","<abbr title=\"kilo bytes\">KB</abbr>","<abbr title=\"mega bytes\">MB</abbr>","<abbr title=\"giga
         bytes\">GB</abbr>","<abbr title=\"tera bytes\">TB</abbr>","<abbr title=\"peta octets\">PB</abbr>" }
         
        Parameters:
        locale - the Locale in which to retrieve the label
        Returns:
        an array of 6 labels, in the specified Locale if it exists, otherwise in english, never return null.
      • generatePassword

        public static java.lang.String generatePassword()
        Generates a basic password (consonnants / voyels) of 8 characters.
        Returns:
        the generated password
        Since:
        jcms-4.0
      • generatePassword

        public static java.lang.String generatePassword​(int length)
        Generates a basic password (consonnants / voyels) of the specified length.
        Parameters:
        length - the length of the password to be generated
        Returns:
        the generated password
        Since:
        jcms-4.0
      • generatePronounceablePassword

        public static java.lang.String generatePronounceablePassword​(int pwdLength)
        Generates pronounceable passwords of specified length. See www.multicians.org/thvv/gpw.html for history and info. Tom Van Vleck
        Parameters:
        pwdLength - The length of the password to be generated
        Returns:
        The generated password
        Since:
        jcms-4.0
      • getStackTrace

        public static java.lang.String getStackTrace​(java.lang.Throwable throwable)
        This method print the stack trace into a String and return it. This is a convenient method for JSP that doesn't have PrintWriter.
        Parameters:
        throwable - the exception or throwable to print
        Returns:
        String the full stack trace.
      • getCurrentStackTrace

        public static java.lang.String getCurrentStackTrace()
        Returns the current StackTrace in a String.
        Returns:
        the current StackTrace in a String.
        Since:
        jcms-6.1.2
      • forceFullGarbageCollection

        public static boolean forceFullGarbageCollection​(long timeout)
        Force the garbage collection
        Parameters:
        timeout - in millisecond if timeout is reached stop the GC forcing
        Returns:
        false if the timeout has been reached
      • getClassShortName

        public static java.lang.String getClassShortName​(java.lang.Object object)
        Returns the short name of the given object's class (e.g. String for java.lang.String)
        Parameters:
        object - the object
        Returns:
        the short name of the object's class
        Since:
        jcms-4.1
      • getClassShortName

        public static java.lang.String getClassShortName​(java.lang.Class clazz)
        Returns the short name of the given class (e.g. String for java.lang.String)
        Parameters:
        clazz - the class
        Returns:
        the short name of the class
      • getClassShortName

        public static java.lang.String getClassShortName​(java.lang.String fullname)
        Returns the short name of the given class name (e.g. String for java.lang.String)
        Parameters:
        fullname - the full class name
        Returns:
        the short name of the class
      • getClassFiles

        public 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. Pay attention to ending / to parameter.
        Parameters:
        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 file
        Returns:
        Set a set of relative path (i.e. WEB-INF/classes/com/jalios/jcms/Category.class)
      • getPackageClassFiles

        public 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. Pay attention to ending / to parameter.
        Parameters:
        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 file
        excludesPattern - Ant-style path patterns to exclude files or folders (see AntPathMatcher)
        Returns:
        Set a set of relative path (i.e. WEB-INF/classes/com/jalios/jcms/Category.class)
      • getClassNameFromFilename

        public 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")
        Parameters:
        filename - the filename of the class
        Returns:
        the class name or null if an error occurred.
        Since:
        jcms-5.5.0
      • getFirstCommonClass

        public 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. If child is null return parent.
        Parameters:
        parent - parent class
        child - child class
        Returns:
        Class
      • getSuperclassList

        public 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.
        Parameters:
        clazz - the class to extract the ancestors
        ancestor - the greater ancestor
        addClass - if true, add the class in the list
        addAncestor - if true, add the ancestor in the list
        Returns:
        a list from the given class to the ancestor class
        Since:
        jcms-4.2
      • escapeHtml

        public static java.lang.String escapeHtml​(java.lang.String str)
        Escapes some special HTML characters such as <, >, & and ". If str is null return an empty string.
        Parameters:
        str - the string to escape
        Returns:
        the escaped string
      • indexOf

        public static int indexOf​(java.lang.Object elem,
                                  java.lang.Object[] array)
        Searches for the first occurrence of the given argument in a given array, testing for equality using the equals method.
        Parameters:
        elem - an object.
        array - an array that may contain elem
        Returns:
        the index of the first occurrence of the argument in this * list; returns -1 if the object is not found.
        See Also:
        Object.equals(Object)
      • hasAppenderDefined

        public static boolean hasAppenderDefined​(org.apache.log4j.Logger logger)
        Checks if the given Logger has any appender defined.
        Parameters:
        logger - the Logger to check
        Returns:
        true if logger has any appender defined, false otherwise
        Since:
        jcms-5.0.5
      • validateRegexp

        public static boolean validateRegexp​(java.lang.String regexp)
        Tell if a String is a valid Perl 5 regexp.
        Parameters:
        regexp - The pattern to validate
        Returns:
        true if it is a valid Perl 5 syntax
        Since:
        JCMS-6.0
      • reduceBlankLines

        public 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.
        Parameters:
        text - the original text
        Returns:
        the text, right trimed and with less line feed.
      • randomString

        public static java.lang.String randomString​(int length)
      • exec

        public static int exec​(java.util.List<java.lang.String> cmdList)
                        throws java.io.IOException,
                               java.lang.InterruptedException
        Executes the specified command and arguments in a separate process.

        Warning: This method execute a system command. If unfiltered input is passed to this API, it can lead to arbitrary command execution.
        Only use with trusted input.

        Parameters:
        cmdList - list containing the command to call and its arguments.
        Returns:
        the exit code
        Throws:
        java.io.IOException - if an error occurs
        java.lang.InterruptedException - if an error occurs
        Since:
        jcms-6.1.2
      • exec

        public static int exec​(java.lang.String... cmdarray)
                        throws java.io.IOException,
                               java.lang.InterruptedException
        Executes the specified command and arguments in a separate process.

        Warning: This method execute a system command. If unfiltered input is passed to this API, it can lead to arbitrary command execution.
        Only use with trusted input.

        Parameters:
        cmdarray - array containing the command to call and its arguments.
        Returns:
        the exit code
        Throws:
        java.io.IOException - if an error occurs
        java.lang.InterruptedException - if an error occurs
        Since:
        jcms-6.1.2
      • exec

        public static int exec​(java.lang.String[] cmdarray,
                               java.io.OutputStream stdout,
                               java.io.OutputStream stderr)
                        throws java.io.IOException,
                               java.lang.InterruptedException
        Executes the specified command and arguments in a separate process.

        Warning: This method execute a system command. If unfiltered input is passed to this API, it can lead to arbitrary command execution.
        Only use with trusted input.

        Parameters:
        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)
        Returns:
        the exit code
        Throws:
        java.io.IOException - if an error occurs
        java.lang.InterruptedException - if an error occurs
        Since:
        jcms-6.1.2
      • exec

        public static int exec​(java.lang.String[] cmdarray,
                               java.lang.StringBuilder stdout,
                               java.lang.StringBuilder stderr)
                        throws java.io.IOException,
                               java.lang.InterruptedException
        Executes the specified command and arguments in a separate process.

        Warning: This method execute a system command. If unfiltered input is passed to this API, it can lead to arbitrary command execution.
        Only use with trusted input.

        Parameters:
        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)
        Returns:
        the exit code
        Throws:
        java.io.IOException - if an error occurs
        java.lang.InterruptedException - if an error occurs
        Since:
        jcms-6.1.2
      • getCommonSuperClass

        public static java.lang.Class<?> getCommonSuperClass​(java.lang.Class<?>... classes)
        Retrieve the common super class of the specified classes. The following rules applies (CSC stands for Common Super Class):
        • CSC of null and any type is null.
        • CSC of interface and any class is the interface if the class implements it, or Object otherwise.
        • CSC of interface and any other interface is whichever interface extends (including indirectly) the other one, or Object if neither does.
        • CSC of primitive type and any distinct type is null.
        • CSC of array type and any distinct class is Object.
        Parameters:
        classes - the classes for which superclass must be found, must not be null nor empty
        Returns:
        the common class
      • getBytesUtf8

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

        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.

        Parameters:
        string - The string to be encoded
        Returns:
        The resultant byte array
        Since:
        jcms-7.1
      • getStringUtf8

        public static java.lang.String getStringUtf8​(byte[] bytes)
        Decode the specified array of bytes into a new 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.

        Parameters:
        bytes - The bytes to be decoded into characters
        Returns:
        The resultant String
        Since:
        jcms-7.1
      • getBatchSet

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

        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(), ""));
         
        Parameters:
        coll - a collection of object, may be null (empty set returned)
        batchSize - the size of subset to be create, must be a positive integer otherwise
        Returns:
        a Set containing subset of objects, never return null, always return at least one set of one empty batch
        Since:
        jcms-7.1.2
      • sum

        public static double sum​(java.util.Collection<? extends java.lang.Number> values)
        Returns the sum of the collection of numbers.
        Parameters:
        values - the values to sum
        Returns:
        the sum of the collection of numbers.
        Since:
        jcms-9.0.0
      • mean

        public static double mean​(java.util.Collection<? extends java.lang.Number> values)
        Returns the mean of the collection of values.
        Parameters:
        values - the values to compute the mean
        Returns:
        the mean of the collection of values.
        Since:
        jcms-9.0.0
      • sliceList

        public static <T> java.util.List<java.util.List<T>> sliceList​(java.util.List<T> list,
                                                                      int max)
        Slices the given list in a list of sub list containing less than max value per list.
        Parameters:
        list - the original list
        max - the maximum size of each sub list
        Returns:
        a List of sub list containing the original values with less than max value per sub list.
        Since:
        jcms-9.0.2
      • map2json

        public static java.lang.String map2json​(java.util.Map map)
        Returns the JSON for the given Map.
        Parameters:
        map - the Map.
        Returns:
        the JSON for the given Map.
        Since:
        jcms-10.0.0
      • json2map

        public static java.util.Map json2map​(java.lang.String json)
        Returns the Map from the given JSON.
        Parameters:
        json - the JSON encoded map
        Returns:
        the Map from the given JSON.
        Since:
        jcms-10.0.0
      • isValidEmail

        public static boolean isValidEmail​(java.lang.String[] emails)
        Returns true if all the given emails are either null, empty or valid.
        Parameters:
        emails - the emails to test.
        Returns:
        true if all the given emails are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidEmail

        public static boolean isValidEmail​(java.lang.String email)
        Checks that the given email is empty or has a valid email syntax.
        Parameters:
        email - the email to test.
        Returns:
        true if the email is empty or valid
        Since:
        jcms-10.0.0
        See Also:
        MailUtil.checkEmail(String)
      • isValidEmail

        public static boolean isValidEmail​(java.util.Collection<java.lang.String> emails)
        Returns true if all the given emails are either null, empty or valid.
        Parameters:
        emails - the emails to test.
        Returns:
        true if all the given emails are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidEmail

        public static boolean isValidEmail​(java.util.Map emailMap)
        Returns true if all the given emails contained as value of the map are either null, empty or valid.
        Parameters:
        emailMap - a Map<String,String> or a Map<String,String[]>
        Returns:
        true if all the given emails contained as value of the map are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUrl

        public static boolean isValidUrl​(java.lang.String[] urls)
        Returns true if all the given urls are either null, empty or valid.
        Parameters:
        urls - the urls to test.
        Returns:
        true if all the given urls are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUrl

        public static boolean isValidUrl​(java.lang.String url)
        Return true if the given url is null, empty or valid.
        Parameters:
        url - the url to test.
        Returns:
        true if the given url is null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUrl

        public static boolean isValidUrl​(java.util.Collection<java.lang.String> urls)
        Returns true if all the given urls are either null, empty or valid.
        Parameters:
        urls - the urls to test.
        Returns:
        true if all the given urls are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUrl

        public static boolean isValidUrl​(java.util.Map urlMap)
        Returns true if all the given urls contained as value of the map are either null, empty or valid.
        Parameters:
        urlMap - a Map<String,String> or a Map<String,String[]>
        Returns:
        true if all the given urls contained as value of the map are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUri

        public static boolean isValidUri​(java.lang.String[] uris)
        Returns true if all the given uris are either null, empty or valid.
        Parameters:
        uris - the uris to test.
        Returns:
        true if all the given uris are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUri

        public static boolean isValidUri​(java.lang.String uri)
        Return true if the given uri is null, empty or valid.
        Parameters:
        uri - the uri to test.
        Returns:
        true if the given uri is null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUri

        public static boolean isValidUri​(java.util.Collection<java.lang.String> uris)
        Returns true if all the given uris are either null, empty or valid.
        Parameters:
        uris - the uris to test.
        Returns:
        true if all the given uris are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidUri

        public static boolean isValidUri​(java.util.Map uriMap)
        Returns true if all the given uris contained as value of the map are either null, empty or valid.
        Parameters:
        uriMap - a Map<String,String> or a Map<String,String[]>
        Returns:
        true if all the given uris contained as value of the map are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidString

        public static boolean isValidString​(java.lang.String string,
                                            java.util.function.Predicate<java.lang.String> p)
        Return true if the given string is null, empty or valid.
        Parameters:
        string - the url to test.
        p - the Predicate to validate the string
        Returns:
        true if the given string is null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidString

        public static boolean isValidString​(java.lang.String[] strings,
                                            java.util.function.Predicate<java.lang.String> p)
        Returns true if all the given strings are either null, empty or valid.
        Parameters:
        strings - the strings to test.
        p - the Predicate to validate the string
        Returns:
        true if all the given strings are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidString

        public static boolean isValidString​(java.util.Collection<java.lang.String> strings,
                                            java.util.function.Predicate<java.lang.String> p)
        Returns true if all the given strings are either null, empty or valid.
        Parameters:
        strings - the strings to test.
        p - the Predicate to validate the string
        Returns:
        true if all the given strings are either null, empty or valid.
        Since:
        jcms-10.0.0
      • isValidString

        public static boolean isValidString​(java.util.Map stringMap,
                                            java.util.function.Predicate<java.lang.String> p)
        Returns true if all the given strings contained as value of the map are either null, empty or valid.
        Parameters:
        stringMap - a Map<String,String> or a Map<String,String[]>
        p - the Predicate to validate the string
        Returns:
        true if all the given strings contained as value of the map are either null, empty or valid.
        Since:
        jcms-10.0.0
      • truncateVarchar

        public static java.lang.String truncateVarchar​(java.lang.String v)
        Truncates the given value to be compliant with standard VARCHAR limit (ie 255 chars)
        Parameters:
        v - the value
        Returns:
        the given value if length is less than 255 or a truncated version.
        Since:
        jcms-9.0.5
      • truncateVarchar

        public static java.util.List<java.lang.String> truncateVarchar​(java.util.List<java.lang.String> list)
        Truncates the content of the given list to be compliant with standard VARCHAR limit (ie 255 chars)
        Parameters:
        list - the list
        Returns:
        the received list with value truncated to 255 chars.
        Since:
        jcms-9.0.5
      • truncateVarchar

        public static java.util.Set<java.lang.String> truncateVarchar​(java.util.Set<java.lang.String> set)
        Truncates the content of the given set to be compliant with standard VARCHAR limit (ie 255 chars)
        Parameters:
        set - the set
        Returns:
        the received set with value truncated to 255 chars.
        Since:
        jcms-9.0.5