Package com.im.commons.util
Class Utils
- java.lang.Object
-
- com.im.commons.util.Utils
-
public final class Utils extends java.lang.Object- Author:
- Tim Dudgeon
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsIgnoreCase(java.lang.String[] vals, java.lang.String item)Does this array of strings contain the specified item (case is ignored).static booleancontainsIgnoreCase(java.util.Collection<java.lang.String> vals, java.lang.String item)Does this collection of strings contain the specified item (case is ignored).static java.lang.StringcreateGuid()static java.lang.StringfindFreeName(java.lang.String name, java.lang.Iterable<? extends java.lang.String> forbidden, java.lang.String prefix, java.lang.String suffix, boolean caseInsensitive)Gets a unique name variant.static java.lang.StringgenerateMD5String(java.lang.String str)static java.lang.Stringnormalize(java.lang.String s)Gets the normalized version of a string.
-
-
-
Method Detail
-
createGuid
public static java.lang.String createGuid()
-
generateMD5String
public static java.lang.String generateMD5String(java.lang.String str)
-
containsIgnoreCase
public static boolean containsIgnoreCase(java.lang.String[] vals, java.lang.String item)Does this array of strings contain the specified item (case is ignored).
-
containsIgnoreCase
public static boolean containsIgnoreCase(java.util.Collection<java.lang.String> vals, java.lang.String item)Does this collection of strings contain the specified item (case is ignored).
-
findFreeName
public static java.lang.String findFreeName(java.lang.String name, java.lang.Iterable<? extends java.lang.String> forbidden, java.lang.String prefix, java.lang.String suffix, boolean caseInsensitive)Gets a unique name variant. This method returns thenameor its modification that does not exist among theforbiddennames.The typical usecase for this method is to find a new available name for an object (eg. a file or a table), which will not conflict with the names of existing objects. The list of existing names is passed in as the
forbiddenparameter. The initial variant of the new name is passed in as thenameparameter.It is guaranteed that this method will return the initial
namewithout any modification if it is not among theforbiddenvariants. Otherwise this method will transform thenameaccording to the following pattern with<N>starting at1and incrementing until a unique name variant is found.prefix + name + suffix + <N>- Parameters:
name- The initial name. Must not benulland must not be empty.forbidden- The list of name variants that are to be skipped.prefix- A string to prepend when transformingname. Can benullor empty.suffix- A string to append when transformingname. Can benullor empty.caseInsensitive- Iftruethe name variants will be compared in case-insensitive manner.- Returns:
- The name variant that is not among the
forbiddenvariants list. - Since:
- 6.3
-
normalize
public static java.lang.String normalize(java.lang.String s)
Gets the normalized version of a string. This method transforms the input string using the following rules.- Remove all accents and/or diacritic marks.
- Replace all characters except letters and digits with the underscore character ('_').
- Prepend a letter if the string does not start with one.
- Parameters:
s- The string to normalize.- Returns:
- The normalized string.
- Since:
- 6.3
-
-