edu.internet2.middleware.grouperClient.util
Class GrouperClientCommonUtils

java.lang.Object
  extended by edu.internet2.middleware.grouperClient.util.GrouperClientCommonUtils
Direct Known Subclasses:
GrouperClientUtils

public class GrouperClientCommonUtils
extends java.lang.Object

utility methods for grouper.

Author:
mchyzer

Nested Class Summary
static class GrouperClientCommonUtils.CommandResult
          The results of executing a command.
 
Field Summary
static java.lang.String DATE_FORMAT
          string format of dates
static java.lang.String DATE_MINUTES_SECONDS_FORMAT
          format including minutes and seconds: yyyy/MM/dd HH:mm:ss
static java.lang.String DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
          format including minutes and seconds: yyyyMMdd HH:mm:ss
static int DEFAULT_BUFFER_SIZE
          The name says it all.
static java.lang.String EMPTY
          The empty String "".
static java.lang.Object[] EMPTY_OBJECT_ARRAY
          An empty immutable Object array.
static java.lang.String[] EMPTY_STRING_ARRAY
          An empty immutable String array.
static int INDEX_NOT_FOUND
          Represents a failed index search.
static java.lang.String LOG_ERROR
           
static int NOT_FOUND
          special number when a number is not found
static long ONE_GB
          The number of bytes in a gigabyte.
static long ONE_KB
          The number of bytes in a kilobyte.
static long ONE_MB
          The number of bytes in a megabyte.
static java.lang.String TIMESTAMP_FORMAT
          format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSS
static java.lang.String TIMESTAMP_NO_SLASH_FORMAT
          format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS
 
Constructor Summary
GrouperClientCommonUtils()
           
 
Method Summary
static java.lang.String abbreviate(java.lang.String str, int maxWidth)
          Abbreviates a String using ellipses.
static java.lang.String abbreviate(java.lang.String str, int offset, int maxWidth)
          Abbreviates a String using ellipses.
static java.lang.String absolutePath(java.io.File file)
          absolute path null safe
static
<T> void
addIfNotThere(java.util.Collection<T> list, java.util.Collection<T> listToAdd)
          add each element of listToAdd if it is not already in list
static void append(java.lang.StringBuilder result, java.lang.String separatorIfResultNotEmpty, java.lang.String stringToAppend)
          append and maybe put a separator in there
static java.lang.String argAfter(java.lang.String[] args, java.lang.String argBefore)
          return the arg after the argBefore, or null if not there, or exception if argBefore is not found
static java.lang.String argKey(java.lang.String option)
          from a command line arg, get the key.
static java.util.Map<java.lang.String,java.lang.String> argMap(java.lang.String[] args)
          add an option: --whatever=val to a map of options where --whatever is key, and val is value
static java.lang.Boolean argMapBoolean(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key)
          get the value from the argMap
static boolean argMapBoolean(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key, boolean required, boolean defaultValue)
          get the value from the argMap, throw exception if not there and required
static java.util.List<java.lang.String> argMapFileList(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key, boolean required)
          get the list from comma separated from the argMap, throw exception if not there and required
static java.lang.Integer argMapInteger(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key, boolean required, java.lang.Integer defaultValue)
          get the value from the argMap, throw exception if not there and required
static java.util.List<java.lang.String> argMapList(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key, boolean required)
          get the list from comma separated from the argMap, throw exception if not there and required
static java.util.Set<java.lang.String> argMapSet(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key, boolean required)
          get the set from comma separated from the argMap, throw exception if not there and required
static java.lang.String argMapString(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key, boolean required)
          get the value from the argMap, throw exception if not there and required
static java.sql.Timestamp argMapTimestamp(java.util.Map<java.lang.String,java.lang.String> argMap, java.util.Map<java.lang.String,java.lang.String> argMapNotUsed, java.lang.String key)
          get the value from the argMap, throw exception if not there and required
static java.lang.String argValue(java.lang.String option)
          from a command line arg, get the key.
static void assertion(boolean isTrue, java.lang.String reason)
          If false, throw an assertException, and give a reason
static void assignField(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String fieldName, java.lang.Object dataToAssign, boolean callOnSupers, boolean overrideSecurity, boolean typeCast, java.lang.Class<? extends java.lang.annotation.Annotation> annotationWithValueOverride)
          assign data to a field
static void assignField(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String fieldName, java.lang.Object dataToAssign, java.lang.Class<? extends java.lang.annotation.Annotation> annotationWithValueOverride)
          assign data to a field.
static void assignField(java.lang.reflect.Field field, java.lang.Object invokeOn, java.lang.Object dataToAssign, boolean overrideSecurity, boolean typeCast)
          assign data to a field
static void assignField(java.lang.reflect.Field field, java.lang.Object invokeOn, java.lang.Object dataToAssign, boolean overrideSecurity, boolean typeCast, java.lang.Class<? extends java.lang.annotation.Annotation> annotationWithValueOverride)
          assign data to a field
static void assignField(java.lang.Object invokeOn, java.lang.String fieldName, java.lang.Object dataToAssign)
          assign data to a field.
static void assignSetter(java.lang.Object invokeOn, java.lang.String fieldName, java.lang.Object dataToAssign, boolean typeCast)
          assign data to a setter.
static
<T> java.util.List<T>
batchList(java.util.Collection<T> collection, int batchSize, int batchIndex)
          retrieve a batch by 0 index.
static int batchNumberOfBatches(java.util.Collection<?> collection, int batchSize)
          If batching this is the number of batches
static int batchNumberOfBatches(int count, int batchSize)
          If batching this is the number of batches
static java.math.BigDecimal bigDecimalObjectValue(java.lang.Object input)
          Convert an object to a byte, allow nulls
static java.lang.Boolean booleanObjectValue(java.lang.Object object)
          get the Boolean value for an object
static boolean booleanValue(java.lang.Object object)
          get the boolean value for an object, cant be null or blank
static boolean booleanValue(java.lang.Object object, boolean defaultBoolean)
          get the boolean value for an object
static java.lang.String byteCountToDisplaySize(long size)
          Returns a human-readable version of the file size (original is in bytes).
static java.lang.Byte byteObjectValue(java.lang.Object input)
          Convert an object to a byte, allow nulls
static byte byteValue(java.lang.Object input)
          convert an object to a byte
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String methodName)
          helper method for calling a method with no params (could be in superclass)
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String methodName, java.lang.Object paramTypesOrArrayOrList, java.lang.Object paramsOrListOrArray)
          helper method for calling a method (could be in superclass)
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String methodName, java.lang.Object paramTypesOrArrayOrList, java.lang.Object paramsOrListOrArray, boolean callOnSupers)
          helper method for calling a method
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String methodName, java.lang.Object paramTypesOrArrayOrList, java.lang.Object paramsOrListOrArray, boolean callOnSupers, boolean overrideSecurity)
          helper method for calling a method
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.String methodName)
          helper method for calling a static method up the stack.
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.String methodName, boolean callOnSupers)
          helper method for calling a static method with no params
static java.lang.Object callMethod(java.lang.Class theClass, java.lang.String methodName, java.lang.Object paramTypesOrArrayOrList, java.lang.Object paramsOrListOrArray)
          helper method for calling a static method up the stack
static java.lang.Object callMethod(java.lang.Object invokeOn, java.lang.String methodName)
          helper method for calling a method with no params (could be in superclass), will override security
static java.lang.String capitalize(java.lang.String str)
          Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char).
static java.lang.Character charObjectValue(java.lang.Object input)
          get the Character wrapper value for the input
static char charValue(java.lang.Object input)
          convert an object to a char
static java.lang.String classesString(java.lang.Object object)
          print the simple names of a list of classes
static java.lang.ClassLoader classLoader()
          fast class loader
static java.lang.String className(java.lang.Object object)
          null safe classname method, gets the unenhanced name
static java.lang.String classNameCollection(java.lang.Object object)
          null safe classname method, max out at 20
static
<T> T
clone(T object, java.util.Set<java.lang.String> fieldsToClone)
          clone an object, assign primitives, Strings, maps of string attributes.
static
<T> void
cloneFields(T object, T result, java.util.Set<java.lang.String> fieldsToClone)
          clone an object, assign primitives, Strings, maps of string attributes.
static
<T> T
cloneValue(T value)
          helper method to clone the value of a field.
static void closeQuietly(java.sql.Connection connection)
          close a connection null safe and dont throw exception
static void closeQuietly(java.io.InputStream input)
          Unconditionally close an InputStream.
static void closeQuietly(java.io.OutputStream output)
          Unconditionally close an OutputStream.
static void closeQuietly(java.io.Reader input)
          Unconditionally close an Reader.
static void closeQuietly(java.sql.ResultSet resultSet)
          close a resultSet null safe and dont throw exception
static void closeQuietly(java.sql.Statement statement)
          close a statement null safe and dont throw exception
static void closeQuietly(java.io.Writer writer)
          close a writer quietly
static java.util.Set<java.lang.String> compareObjectFields(java.lang.Object first, java.lang.Object second, java.util.Set<java.lang.String> fieldsToCompare, java.lang.String mapPrefix)
          compare two objects, compare primitives, Strings, maps of string attributes.
static java.net.URL computeUrl(java.lang.String resourceName, boolean canBeNull)
          compute a url of a resource
static
<T> T
construct(java.lang.Class<T> theClass, java.lang.Class[] types, java.lang.Object[] args)
          construct an instance by reflection
static boolean contains(java.lang.Object[] array, java.lang.Object objectToFind)
          Checks if the object is in the given array.
static boolean contains(java.lang.String str, char searchChar)
          Checks if String contains a search character, handling null.
static boolean contains(java.lang.String str, java.lang.String searchStr)
          Checks if String contains a search String, handling null.
static java.lang.String convertLongToChar(long theLong)
          this method takes a long (less than 62) and converts it to a 1 character string (a-z, A-Z, 0-9)
static java.lang.String convertLongToCharSmall(long theLong)
          this method takes a long (less than 36) and converts it to a 1 character string (A-Z, 0-9)
static java.lang.String convertLongToString(long theLong)
          convert a long to a string by converting it to base 62 (26 lower, 26 upper, 10 digits)
static java.lang.String convertLongToStringSmall(long theLong)
          convert a long to a string by converting it to base 36 (26 upper, 10 digits)
static void convertToRuntimeException(java.lang.Exception e)
          convert an exception to a runtime exception
static void copy(java.io.File fromFile, java.io.File toFile)
          copy a file to a new file
static int copy(java.io.InputStream input, java.io.OutputStream output)
          Copy bytes from an InputStream to an OutputStream.
static void copy(java.io.InputStream input, java.io.Writer output)
          Copy bytes from an InputStream to chars on a Writer using the default character encoding of the platform.
static void copy(java.io.InputStream input, java.io.Writer output, java.lang.String encoding)
          Copy and convert bytes from an InputStream to chars on a Writer, using the specified encoding.
static int copy(java.io.Reader input, java.io.Writer output)
          Copy chars from a Reader to a Writer.
static long copyLarge(java.io.InputStream input, java.io.OutputStream output)
          Copy bytes from a large (over 2GB) InputStream to an OutputStream.
static void createParentDirectories(java.io.File file)
          Create the parent directories for a file if they do not already exist
static java.lang.String dateToString(java.util.Date date)
          convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23
static java.util.Date dateValue(java.lang.Object inputObject)
           Convert an object to a java.util.Date.
static java.lang.String defaultIfBlank(java.lang.String string, java.lang.String defaultStringIfBlank)
          return the string or the other if the first is blank
static java.lang.String defaultIfEmpty(java.lang.String str, java.lang.String defaultStr)
          Returns either the passed in String, or if the String is empty or null, the value of defaultStr.
static
<T> T
defaultIfNull(T theValue, T defaultIfTheValueIsNull)
          genericized method to see if first is null, if so then return second, else first.
static java.lang.String defaultString(java.lang.String str)
          Returns either the passed in String, or if the String is null, an empty String ("").
static java.lang.String defaultString(java.lang.String str, java.lang.String defaultStr)
          Returns either the passed in String, or if the String is null, the value of defaultStr.
static void deleteCreateFile(java.io.File file)
          delete and create a new file.
static void deleteFile(java.io.File file)
          Delete a file, throw exception if cannot
static void deleteRecursiveDirectory(java.lang.String dirName)
          clear out all files recursively in a directory, including the directory itself
static java.lang.Double doubleObjectValue(java.lang.Object input, boolean allowNullBlank)
          get the Double value of an object
static double doubleValue(java.lang.Object input)
          get the double value of an object
static double doubleValueNoError(java.lang.Object input)
          get the double value of an object, do not throw an exception if there is an error
static boolean endsWith(java.lang.StringBuilder str, java.lang.String end)
           
static
<E extends java.lang.Enum<?>>
E
enumValueOfIgnoreCase(java.lang.Class<E> theEnumClass, java.lang.String string, boolean exceptionOnNotFound)
          do a case-insensitive matching
static boolean equals(java.lang.Object object1, java.lang.Object object2)
          Compares two objects for equality, where either one or both objects may be null.
static boolean equals(java.lang.String first, java.lang.String second)
          null safe string compare
static boolean equalsIgnoreCase(java.lang.String str1, java.lang.String str2)
          equalsignorecase
static java.lang.String escapeUrlDecode(java.lang.String string)
          unescape url chars (e.g.
static java.lang.String escapeUrlEncode(java.lang.String string)
          escape url chars (e.g.
static void execCommand(java.lang.String command)
          This will execute a command, and split spaces for args (might not be what you want if you are using quotes)
static GrouperClientCommonUtils.CommandResult execCommand(java.lang.String[] arguments)
          This will execute a command (with args).
static GrouperClientCommonUtils.CommandResult execCommand(java.lang.String[] arguments, boolean exceptionOnExitValueNeZero)
          This will execute a command (with args).
static java.lang.String extensionFromName(java.lang.String name)
          get the extension from name.
static java.lang.reflect.Field field(java.lang.Class theClass, java.lang.String fieldName, boolean callOnSupers, boolean throwExceptionIfNotFound)
          get a field object for a class, potentially in superclasses
static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass, java.lang.Class fieldType, boolean includeStaticFields)
          return a set of Strings for a class and type.
static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class<?> fieldType, boolean includeSuperclassToStopAt, boolean includeStaticFields, boolean includeFinalFields)
          get all field names from a class, including superclasses (if specified)
static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class<?> fieldType, boolean includeSuperclassToStopAt, boolean includeStaticFields, boolean includeFinalFields, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotationToIngore)
          get all field names from a class, including superclasses (if specified).
static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotationToIngore)
          get all field names from a class, including superclasses (if specified) (up to and including the specified superclass).
static java.util.Set<java.lang.reflect.Field> fields(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation, boolean includeAnnotation)
          get all fields from a class, including superclasses (if specified) (up to and including the specified superclass).
static java.util.Set<java.lang.reflect.Field> fields(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class fieldType, boolean includeSuperclassToStopAt, boolean includeStaticFields, boolean includeFinalFields, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation, boolean includeAnnotation)
          get all fields from a class, including superclasses (if specified)
static java.lang.Object fieldValue(java.lang.Class theClass, java.lang.Object invokeOn, java.lang.String fieldName, boolean callOnSupers, boolean overrideSecurity)
          find out a field value
static java.lang.Object fieldValue(java.lang.reflect.Field field, java.lang.Object invokeOn)
          get the value of a field, override security if needbe
static java.lang.Object fieldValue(java.lang.reflect.Field field, java.lang.Object invokeOn, boolean overrideSecurity)
          get the value of a field
static java.lang.Object fieldValue(java.lang.Object invokeOn, java.lang.String fieldName)
          find out a field value (invoke on supers, override security)
static java.lang.String fileCanonicalPath(java.io.File file)
          get canonical path of file
static java.io.File fileFromResourceName(java.lang.String resourceName)
          get a file name from a resource name
static java.io.InputStream fileOrClasspathInputstream(java.lang.String typeAndLocation, java.lang.String logHint)
          file or classpath location
static java.lang.Float floatObjectValue(java.lang.Object input, boolean allowNullBlank)
          get the Float value of an object
static float floatValue(java.lang.Object input)
          get the float value of an object
static float floatValueNoError(java.lang.Object input)
          get the float value of an object, do not throw an exception if there is an error
static java.lang.Class forName(java.lang.String origClassName)
          Returns the class object.
static java.lang.Object get(java.lang.Object arrayOrCollection, int index)
          Get a specific index of an array or collection (note for collections and iterating, it is more efficient to get an iterator and iterate
static java.lang.Throwable getCause(java.lang.Throwable throwable)
          Introspects the Throwable to obtain the cause.
static java.lang.Throwable getCause(java.lang.Throwable throwable, java.lang.String[] methodNames)
          Introspects the Throwable to obtain the cause.
static java.lang.String getFullStackTrace(java.lang.Throwable throwable)
          A way to get the entire nested stack-trace of an throwable.
static java.lang.reflect.Method getter(java.lang.Class theClass, java.lang.String fieldName, boolean callOnSupers, boolean throwExceptionIfNotFound)
          get a getter method object for a class, potentially in superclasses
static java.lang.reflect.Method getterHelper(java.lang.Class theClass, java.lang.String fieldName, java.lang.String getterName, boolean callOnSupers, boolean throwExceptionIfNotFound)
          get a setter method object for a class, potentially in superclasses
static java.lang.String getterNameFromPropertyName(java.lang.String propertyName)
          generate getBb from bb
static java.util.Set<java.lang.reflect.Method> getters(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation, java.lang.Boolean includeAnnotation)
          get all getters from a class, including superclasses (if specified) (up to and including the specified superclass).
static java.lang.Throwable[] getThrowables(java.lang.Throwable throwable)
          Returns the list of Throwable objects in the exception chain.
static boolean hasOption(int options, int option)
          see if options have a specific option by int bits
static java.lang.String hostname()
          get the hostname of this machine
static char incrementChar(char theChar)
          increment a character (A-Z then 0-9)
static char[] incrementStringInt(char[] string)
          Increment a string with A-Z and 0-9 (no lower case so case insensitive apps like windows IE will still work)
static java.lang.String indent(java.lang.String string, boolean failIfTypeNotFound)
           this method will indent xml or json.
static int indexOf(java.lang.Object[] array, java.lang.Object objectToFind)
          Find the index of the given object in the array.
static int indexOf(java.lang.Object[] array, java.lang.Object objectToFind, int startIndex)
          Find the index of the given object in the array starting at the given index.
static boolean injectInException(java.lang.Throwable t, java.lang.String message)
          If we can, inject this into the exception, else return false
static java.lang.Integer intObjectValue(java.lang.Object input, boolean allowNullBlank)
          get the Integer value of an object
static int intValue(java.lang.Object input)
          convert an object to a int
static int intValue(java.lang.Object input, int valueIfNull)
          convert an object to a int
static int intValueNoError(java.lang.Object input)
          get the int value of an object, do not throw an exception if there is an error
static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object invokeOn)
          Safely invoke a reflection method that takes no args
static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object invokeOn, java.lang.Object paramsOrListOrArray)
          Safely invoke a reflection method
static boolean isAscii(char input)
          is ascii char
static boolean isBlank(java.lang.Object input)
          See if the input is null or if string, if it is empty or blank (whitespace)
static boolean isBlank(java.lang.String str)
          Checks if a String is whitespace, empty ("") or null.
static boolean isEmpty(java.lang.String str)
           Checks if a String is empty ("") or null.
static boolean isGetter(java.lang.reflect.Method method)
          if the method name starts with get, and takes no args, and returns something, then getter
static boolean isNestedThrowable(java.lang.Throwable throwable)
          Checks whether this Throwable class can store a cause.
static boolean isNotBlank(java.lang.String str)
           
static boolean isScalar(java.lang.Class<?> type)
          see if a class is a scalar (not bean, not array or list, etc)
static boolean isSetter(java.lang.reflect.Method method)
          if the method name starts with get, and takes no args, and returns something, then getter
static boolean isThrowableNested()
          Checks if the Throwable class has a getCause method.
static java.util.Iterator iterator(java.lang.Object collection)
          null safe iterator getter if the type if collection
static java.io.File jarFile(java.lang.Class sampleClass)
          get a jar file from a sample class
static java.lang.String join(java.util.Iterator iterator, char separator)
          Joins the elements of the provided Iterator into a single String containing the provided elements.
static java.lang.String join(java.util.Iterator iterator, java.lang.String separator)
          Joins the elements of the provided Iterator into a single String containing the provided elements.
static java.lang.String join(java.lang.Object[] array)
          Joins the elements of the provided array into a single String containing the provided list of elements.
static java.lang.String join(java.lang.Object[] array, char separator)
          Joins the elements of the provided array into a single String containing the provided list of elements.
static java.lang.String join(java.lang.Object[] array, java.lang.String separator)
          Joins the elements of the provided array into a single String containing the provided list of elements.
static java.lang.String leftPad(java.lang.String str, int size)
          Left pad a String with spaces (' ').
static java.lang.String leftPad(java.lang.String str, int size, char padChar)
          Left pad a String with a specified character.
static java.lang.String leftPad(java.lang.String str, int size, java.lang.String padStr)
          Left pad a String with a specified String.
static int length(java.lang.Object arrayOrCollection)
          Null safe array length or map
static int lengthAscii(java.lang.String input)
          find the length of ascii chars (non ascii are counted as two)
static java.lang.Long longObjectValue(java.lang.Object input, boolean allowNullBlank)
          get the Long value of an object
static long longValue(java.lang.Object input)
          convert an object to a long
static long longValue(java.lang.Object input, long valueIfNull)
          convert an object to a long
static long longValueNoError(java.lang.Object input)
          get the long value of an object, do not throw an exception if there is an error
static
<K,V> void
mapDifferences(java.util.Map<K,V> first, java.util.Map<K,V> second, java.util.Set<K> differences, java.lang.String prefix)
          see if two maps are the equivalent (based on number of entries, and the equals() method of the keys and values)
static
<K,V> boolean
mapEquals(java.util.Map<K,V> first, java.util.Map<K,V> second)
          see if two maps are the equivalent (based on number of entries, and the equals() method of the keys and values)
static java.lang.String mapToString(java.util.Map map)
          convert a set to a string (comma separate)
static java.lang.String MapToString(java.util.Map map)
          Deprecated. use mapToString(map)
static java.lang.reflect.Method method(java.lang.Class<?> theClass, java.lang.String methodName, java.lang.Object paramTypesOrArrayOrList, java.lang.Class<?> superclassToStopAt, boolean includeSuperclassToStopAt, boolean isStaticOrInstance, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation, boolean includeAnnotation)
          get the set of methods
static java.util.Set<java.lang.String> methodNames(java.lang.Class<?> theClass, java.lang.Class<?> superclassToStopAt, boolean includeSuperclassToStopAt, boolean includeStaticMethods)
          simple method to get method names
static void methodsHelper(java.lang.Class<?> theClass, java.lang.Class<?> superclassToStopAt, boolean includeSuperclassToStopAt, boolean includeStaticMethods, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation, boolean includeAnnotation, java.util.Set<java.lang.reflect.Method> methodSet)
          get the set of methods
static void mkdirs(java.io.File dir)
          Create directories, throw exception if not possible.
static int monthInt(java.lang.String mon)
          convert a month string to an int (1 indexed).
static java.io.File newFileUniqueName(java.lang.String parentDirName, java.lang.String namePrefix, java.lang.String nameSuffix, boolean createFile)
           make a new file in the name prefix dir.
static
<T> T
newInstance(java.lang.Class<T> theClass)
          Construct a class
static
<T> T
newInstance(java.lang.Class<T> theClass, boolean allowPrivateConstructor)
          Construct a class
static java.lang.Object next(java.lang.Object arrayOrCollection, java.util.Iterator iterator, int index)
          If array, get the element based on index, if Collection, get it based on iterator.
static
<T> java.util.List<T>
nonNull(java.util.List<T> list)
          make sure a list is non null.
static
<K,V> java.util.Map<K,V>
nonNull(java.util.Map<K,V> map)
          make sure it is non null, if null, then give new map
static
<T> java.util.Set<T>
nonNull(java.util.Set<T> set)
          make sure a list is non null.
static
<T> T[]
nonNull(T[] array, java.lang.Class<?> theClass)
          make sure a array is non null.
static boolean nullOrBlank(java.lang.Object object)
          is an object null or blank
static java.lang.String oracleStandardNameFromJava(java.lang.String javaName)
          get the oracle underscore name e.g.
static long packInts(int first, int second)
          pack two ints into a long.
static java.lang.String parentStemNameFromName(java.lang.String name)
          get the parent stem name from name.
static java.lang.String prefixOrSuffix(java.lang.String startString, java.lang.String separator, boolean isPrefix)
          get the prefix or suffix of a string based on a separator
static void propertiesCacheClear()
          clear properties cache (e.g.
static java.util.Properties propertiesFromFile(java.io.File file)
          read properties from file
static java.util.Properties propertiesFromResourceName(java.lang.String resourceName)
          read properties from a resource, dont modify the properties returned since they are cached
static java.util.Properties propertiesFromResourceName(java.lang.String resourceName, boolean useCache, boolean exceptionIfNotExist, java.lang.Class<?> classInJar, java.lang.StringBuilder callingLog)
          read properties from a resource, dont modify the properties returned since they are cached
static java.util.Map<java.lang.String,java.lang.String> propertiesThreadLocalOverrideMap(java.lang.String propertiesFileName)
          override map for properties in thread local to be used in a web server or the like, based on property file name
static java.lang.String propertiesValue(java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.util.Map<java.lang.String,java.lang.String> overrideMap2, java.lang.String key)
          get a value (trimmed to e) from a property file
static java.lang.String propertiesValue(java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String key)
          get a value (trimmed to e) from a property file
static java.lang.String propertiesValue(java.util.Properties properties, java.lang.String key)
          get a value (trimmed to e) from a property file
static java.lang.String propertiesValue(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String propertyName, boolean required)
          get a boolean property, or the default if cant find.
static boolean propertiesValueBoolean(java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.util.Map<java.lang.String,java.lang.String> overrideMap2, java.lang.String propertyName, boolean defaultValue)
          get a boolean property, or the default if cant find
static boolean propertiesValueBoolean(java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String propertyName, boolean defaultValue)
          get a boolean property, or the default if cant find
static boolean propertiesValueBoolean(java.util.Properties properties, java.lang.String propertyName, boolean defaultValue)
          get a boolean property, or the default if cant find
static boolean propertiesValueBoolean(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String propertyName, boolean defaultValue, boolean required)
          get a boolean property, or the default if cant find.
static int propertiesValueInt(java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.util.Map<java.lang.String,java.lang.String> overrideMap2, java.lang.String propertyName, int defaultValue)
          get a int property, or the default if cant find
static int propertiesValueInt(java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String propertyName, int defaultValue)
          get a int property, or the default if cant find
static int propertiesValueInt(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String propertyName, int defaultValue, boolean required)
          get an int property, or the default if cant find.
static java.lang.String propertyName(java.lang.reflect.Method method)
          If this is a getter or setter, then get the property name
static java.lang.Class propertyType(java.lang.Class theClass, java.lang.String propertyName)
          use reflection to get a property type based on getter or setter or field
static boolean propertyValidateValueBoolean(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String key, boolean required, boolean exceptionOnError)
          make sure a value is boolean in properties
static boolean propertyValidateValueClass(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String key, java.lang.Class<?> classType, boolean required, boolean exceptionOnError)
          make sure a property is a class of a certain type
static boolean propertyValidateValueInt(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String key, boolean required, boolean exceptionOnError)
          make sure a value is int in properties
static boolean propertyValidateValueRequired(java.lang.String resourceName, java.util.Properties properties, java.util.Map<java.lang.String,java.lang.String> overrideMap, java.lang.String key, boolean exceptionOnError)
          make sure a value exists in properties
static java.lang.Object propertyValue(java.lang.Object object, java.lang.String property)
          this assumes the property exists, and is a simple property
static java.lang.String readFileIntoString(java.io.File file)
           
static java.lang.String readFileToString(java.io.File file, java.lang.String encoding)
           Reads the contents of a file into a String.
static java.lang.String readFromFileIfFile(java.lang.String in, boolean disableExternalFileLookup)
          if the input is a file, read string from file.
static java.lang.String readFromFileIfFileExists(java.lang.String in, boolean disableExternalFileLookup)
          if the input is a file, read string from file.
static java.lang.String readResourceIntoString(java.lang.String resourceName, boolean allowNull)
           
static java.lang.String readResourceIntoString(java.lang.String resourceName, java.lang.Class<?> classInJar)
          read resource into string
static java.lang.Object remove(java.lang.Object arrayOrCollection, int index)
          Remove the iterator or index
static java.lang.Object remove(java.lang.Object arrayOrCollection, java.util.Iterator iterator, int index)
          Remove the iterator or index
static void removeEnd(java.lang.StringBuilder str, java.lang.String remove)
          remove end if there
static java.lang.String removeEnd(java.lang.String str, java.lang.String remove)
          Removes a substring only if it is at the end of a source string, otherwise returns the source string.
static void renameTo(java.io.File fromFile, java.io.File toFile)
          rename a file to another file and throw runtime exception if not ok
static java.lang.String repeat(java.lang.String str, int repeat)
          Repeat a String repeat times to form a new String.
static void replace(java.lang.StringBuffer outBuffer, java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith)
          replace a string or strings from a string, and put the output in a string buffer.
static void replace(java.lang.StringBuffer outBuffer, java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith, boolean recurse)
          replace a string or strings from a string, and put the output in a string buffer
static java.lang.String replace(java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith)
          replace a string or strings from a string, and put the output in a string buffer.
static java.lang.String replace(java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith, boolean recurse)
          replace a string or strings from a string, and put the output in a string buffer
static java.lang.String replace(java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith, boolean recurse, boolean removeIfFound)
          replace a string or strings from a string, and put the output in a string buffer
static java.lang.String replace(java.lang.String text, java.lang.String repl, java.lang.String with)
           Replaces all occurrences of a String within another String.
static java.lang.String replace(java.lang.String text, java.lang.String repl, java.lang.String with, int max)
           Replaces a String with another String inside a larger String, for the first max values of the search String.
static void replace(java.io.Writer outWriter, java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith)
          replace a string or strings from a string, and put the output in a string buffer.
static void replace(java.io.Writer outWriter, java.lang.String text, java.lang.Object searchFor, java.lang.Object replaceWith, boolean recurse)
          replace a string or strings from a string, and put the output in a string buffer
static java.lang.String replaceWhitespaceWithSpace(java.lang.String input)
          replace all whitespace with space
static java.lang.String responseBodyAsString(HttpMethodBase method)
          for testing, get the response body as a string
static java.util.concurrent.ExecutorService retrieveExecutorService()
           
static java.lang.String retrievePasswordFromStdin(boolean dontMask, java.lang.String prompt)
          retrieve a password from stdin
static char[] retrievePasswordFromStdin(java.io.InputStream in, java.lang.String prompt)
           
static java.lang.String rightPad(java.lang.String str, int size)
          Right pad a String with spaces (' ').
static java.lang.String rightPad(java.lang.String str, int size, char padChar)
          Right pad a String with a specified character.
static java.lang.String rightPad(java.lang.String str, int size, java.lang.String padStr)
          Right pad a String with a specified String.
static void rollbackQuietly(java.sql.Connection connection)
          rollback a connection quietly
static void saveStringIntoFile(java.io.File file, java.lang.String contents)
          save a string into a file, file does not have to exist
static boolean saveStringIntoFile(java.io.File file, java.lang.String contents, boolean onlyIfDifferentContents, boolean ignoreWhitespace)
          save a string into a file, file does not have to exist
static void serializeObjectToFile(java.io.Serializable object, java.io.File file)
          serialize an object to a file (create parent dir if necessary)
static java.lang.reflect.Method setter(java.lang.Class theClass, java.lang.String fieldName, boolean callOnSupers, boolean throwExceptionIfNotFound)
          get a setter method object for a class, potentially in superclasses
static java.lang.reflect.Method setterHelper(java.lang.Class theClass, java.lang.String fieldName, java.lang.String setterName, boolean callOnSupers, boolean throwExceptionIfNotFound)
          get a setter method object for a class, potentially in superclasses
static java.lang.String setterNameFromPropertyName(java.lang.String propertyName)
          generate setBb from bb
static java.util.Set<java.lang.reflect.Method> setters(java.lang.Class theClass, java.lang.Class superclassToStopAt, java.lang.Class<?> fieldType, boolean includeSuperclassToStopAt, java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation, boolean includeAnnotation)
          get all setters from a class, including superclasses (if specified)
static java.lang.String setToString(java.util.Set set)
          convert a set to a string (comma separate)
static java.lang.Short shortObjectValue(java.lang.Object input)
          get the Short value of an object.
static short shortValue(java.lang.Object input)
          convert an object to a short
static void sleep(long millis)
          sleep, if interrupted, throw runtime
static java.lang.String[] split(java.lang.String str)
          Splits the provided text into an array, using whitespace as the separator.
static java.lang.String[] split(java.lang.String str, char separatorChar)
          Splits the provided text into an array, separator specified.
static java.lang.String[] split(java.lang.String str, java.lang.String separatorChars)
          Splits the provided text into an array, separators specified.
static java.lang.String[] split(java.lang.String str, java.lang.String separatorChars, int max)
          Splits the provided text into an array with a maximum length, separators specified.
static java.lang.String[] splitByWholeSeparator(java.lang.String str, java.lang.String separator)
          Splits the provided text into an array, separator string specified.
static java.lang.String[] splitByWholeSeparator(java.lang.String str, java.lang.String separator, int max)
          Splits the provided text into an array, separator string specified.
static java.lang.String[] splitPreserveAllTokens(java.lang.String str)
          Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators.
static java.lang.String[] splitPreserveAllTokens(java.lang.String str, char separatorChar)
          Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators.
static java.lang.String[] splitPreserveAllTokens(java.lang.String str, java.lang.String separatorChars)
          Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
static java.lang.String[] splitPreserveAllTokens(java.lang.String str, java.lang.String separatorChars, int max)
          Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
static java.lang.String[] splitTrim(java.lang.String input, java.lang.String separator)
          split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)
static java.lang.String[] splitTrim(java.lang.String input, java.lang.String separator, boolean treatAdjacentSeparatorsAsOne)
          split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)
static java.util.List<java.lang.String> splitTrimToList(java.lang.String input, java.lang.String separator)
          split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)
static java.util.Date stringToDate(java.lang.String dateString)
          convert a string to a date using the standard web service pattern Note that HH is 0-23
static java.util.Date stringToDate2(java.lang.String input)
          take as input: yyyy/mm/dd yyyy-mm-dd dd-mon-yyyy yyyy/mm/dd hh:mm:ss dd-mon-yyyy hh:mm:ss yyyy/mm/dd hh:mm:ss.SSS dd-mon-yyyy hh:mm:ss.SSS
static java.sql.Timestamp stringToTimestamp(java.lang.String input)
          convert a string to timestamp based on the following formats: yyyyMMdd yyyy/MM/dd HH:mm:ss yyyy/MM/dd HH:mm:ss.SSS yyyy/MM/dd HH:mm:ss.SSSSSS
static java.lang.String stringValue(java.util.Date date)
          convert a date to the standard string yyyymmdd
static java.lang.String stringValue(java.lang.Object input)
          convert an object to a string
static java.lang.String stripEnd(java.lang.String str, java.lang.String stripChars)
          Strips any of a set of characters from the end of a String.
static java.lang.String stripLastSlashIfExists(java.lang.String input)
          strip the last slash (/ or \) from a string if it exists
static java.lang.String stripStart(java.lang.String str, java.lang.String stripChars)
          Strips any of a set of characters from the start of a String.
static java.lang.String substituteCommonVars(java.lang.String string)
          substitute common vars like $space$ and $newline$
static java.lang.String substringAfter(java.lang.String str, java.lang.String separator)
          Gets the substring after the first occurrence of a separator.
static java.lang.String substringAfterLast(java.lang.String str, java.lang.String separator)
          Gets the substring after the last occurrence of a separator.
static java.lang.String substringBefore(java.lang.String str, java.lang.String separator)
          Gets the substring before the first occurrence of a separator.
static java.lang.String substringBeforeLast(java.lang.String str, java.lang.String separator)
          Gets the substring before the last occurrence of a separator.
static java.lang.String suffixAfterChar(java.lang.String input, char theChar)
          return the suffix after a char.
static java.lang.String timestampToString(java.util.Date timestamp)
          Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS
static
<T> T[]
toArray(java.util.Collection collection, java.lang.Class<T> theClass)
          convert a list into an array of type of theClass
static java.lang.Object toArray(java.lang.Object objectOrArrayOrCollection)
          Convert a list to an array with the type of the first element e.g.
static
<T> java.util.List<T>
toList(T... objects)
          return a list of objects from varargs.
static java.util.List<java.lang.Class<?>> toListClasses(java.lang.Class<?>... classes)
          convert classes to a list
static
<T> java.util.List<T>
toListFromCollection(java.util.Collection<T> collection)
          convert a collection to a list (if already a list, keep it)
static java.util.Map<?,?> toMap(java.lang.Object... keysAndValues)
          keys and values go into map
static
<T> java.util.Set<T>
toSet(T... objects)
          return a set of objects from varargs.
static java.sql.Date toSqlDate(java.util.Date date)
          null safe convert from util date to sql date
static java.lang.String toString(java.io.InputStream input, java.lang.String encoding)
          Get the contents of an InputStream as a String.
static java.lang.String toStringForLog(java.lang.Object object)
          print out various types of objects
static java.lang.String toStringForLog(java.lang.Object object, int maxChars)
          print out various types of objects
static java.lang.String toStringSafe(java.lang.Object object)
          fail safe toString for Exception blocks, and include the stack if there is a problem with toString()
static java.sql.Timestamp toTimestamp(java.lang.Object input)
           Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd or yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS or yyyy/MM/dd HH:mm:ss.SSSSSS
static java.lang.String trim(java.lang.String str)
          trim whitespace from string
static java.lang.String trimToEmpty(java.lang.String str)
          trim to empty, convert null to empty
static java.lang.String truncateAscii(java.lang.String input, int requiredLength)
          find the length of ascii chars (non ascii are counted as two)
static
<T> T
typeCast(java.lang.Object value, java.lang.Class<T> theClass)
          If necessary, convert an object to another type.
static
<T> T
typeCast(java.lang.Object value, java.lang.Class<T> theClass, boolean convertNullToDefaultPrimitive, boolean useNewInstanceHooks)
          If necessary, convert an object to another type.
static java.lang.String uniqueId()
          get a unique string identifier based on the current time, this is not globally unique, just unique for as long as this server is running...
static int unpackInt(long theLong, boolean isFirst)
          take a long
static java.io.Serializable unserializeObjectFromFile(java.io.File file, boolean nullIfException, boolean deleteFileOnException)
          unserialize an object from a file if it exists
static void writeStringToFile(java.io.File file, java.lang.String data, java.lang.String encoding)
           Writes data to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_ERROR

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

ONE_KB

public static final long ONE_KB
The number of bytes in a kilobyte.

See Also:
Constant Field Values

ONE_MB

public static final long ONE_MB
The number of bytes in a megabyte.

See Also:
Constant Field Values

ONE_GB

public static final long ONE_GB
The number of bytes in a gigabyte.

See Also:
Constant Field Values

DATE_FORMAT

public static final java.lang.String DATE_FORMAT
string format of dates

See Also:
Constant Field Values

DATE_MINUTES_SECONDS_FORMAT

public static final java.lang.String DATE_MINUTES_SECONDS_FORMAT
format including minutes and seconds: yyyy/MM/dd HH:mm:ss

See Also:
Constant Field Values

DATE_MINUTES_SECONDS_NO_SLASH_FORMAT

public static final java.lang.String DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
format including minutes and seconds: yyyyMMdd HH:mm:ss

See Also:
Constant Field Values

TIMESTAMP_FORMAT

public static final java.lang.String TIMESTAMP_FORMAT
format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSS

See Also:
Constant Field Values

TIMESTAMP_NO_SLASH_FORMAT

public static final java.lang.String TIMESTAMP_NO_SLASH_FORMAT
format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS

See Also:
Constant Field Values

NOT_FOUND

public static final int NOT_FOUND
special number when a number is not found

See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The name says it all.

See Also:
Constant Field Values

EMPTY_STRING_ARRAY

public static final java.lang.String[] EMPTY_STRING_ARRAY
An empty immutable String array.


EMPTY_OBJECT_ARRAY

public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
An empty immutable Object array.


EMPTY

public static final java.lang.String EMPTY
The empty String "".

Since:
2.0
See Also:
Constant Field Values

INDEX_NOT_FOUND

public static final int INDEX_NOT_FOUND
Represents a failed index search.

Since:
2.1
See Also:
Constant Field Values
Constructor Detail

GrouperClientCommonUtils

public GrouperClientCommonUtils()
Method Detail

argAfter

public static java.lang.String argAfter(java.lang.String[] args,
                                        java.lang.String argBefore)
return the arg after the argBefore, or null if not there, or exception if argBefore is not found

Parameters:
args -
argBefore -
Returns:
the arg

append

public static void append(java.lang.StringBuilder result,
                          java.lang.String separatorIfResultNotEmpty,
                          java.lang.String stringToAppend)
append and maybe put a separator in there

Parameters:
result -
separatorIfResultNotEmpty -
stringToAppend -

byteCountToDisplaySize

public static java.lang.String byteCountToDisplaySize(long size)
Returns a human-readable version of the file size (original is in bytes).

Parameters:
size - The number of bytes.
Returns:
A human-readable display value (includes units).

hasOption

public static boolean hasOption(int options,
                                int option)
see if options have a specific option by int bits

Parameters:
options -
option -
Returns:
if the option is there

fileCanonicalPath

public static java.lang.String fileCanonicalPath(java.io.File file)
get canonical path of file

Parameters:
file -
Returns:
the path

suffixAfterChar

public static java.lang.String suffixAfterChar(java.lang.String input,
                                               char theChar)
return the suffix after a char. If the char doesnt exist, just return the string

Parameters:
input - string
theChar - char
Returns:
new string

oracleStandardNameFromJava

public static java.lang.String oracleStandardNameFromJava(java.lang.String javaName)
get the oracle underscore name e.g. javaNameHere -> JAVA_NAME_HERE

Parameters:
javaName - the java convention name
Returns:
the oracle underscore name based on the java name

mapEquals

public static <K,V> boolean mapEquals(java.util.Map<K,V> first,
                                      java.util.Map<K,V> second)
see if two maps are the equivalent (based on number of entries, and the equals() method of the keys and values)

Type Parameters:
K -
V -
Parameters:
first -
second -
Returns:
true if equal

mapDifferences

public static <K,V> void mapDifferences(java.util.Map<K,V> first,
                                        java.util.Map<K,V> second,
                                        java.util.Set<K> differences,
                                        java.lang.String prefix)
see if two maps are the equivalent (based on number of entries, and the equals() method of the keys and values)

Type Parameters:
K -
V -
Parameters:
first - map to check diffs
second - map to check diffs
differences - set of keys (with prefix) of the diffs
prefix - for the entries in the diffs (e.g. "attribute__"

sleep

public static void sleep(long millis)
sleep, if interrupted, throw runtime

Parameters:
millis -

injectInException

public static boolean injectInException(java.lang.Throwable t,
                                        java.lang.String message)
If we can, inject this into the exception, else return false

Parameters:
t -
message -
Returns:
true if success, false if not

uniqueId

public static java.lang.String uniqueId()
get a unique string identifier based on the current time, this is not globally unique, just unique for as long as this server is running...

Returns:
String

fileFromResourceName

public static java.io.File fileFromResourceName(java.lang.String resourceName)
get a file name from a resource name

Parameters:
resourceName - is the classpath location
Returns:
the file path on the system

computeUrl

public static java.net.URL computeUrl(java.lang.String resourceName,
                                      boolean canBeNull)
compute a url of a resource

Parameters:
resourceName -
canBeNull - if cant be null, throw runtime
Returns:
the URL

classLoader

public static java.lang.ClassLoader classLoader()
fast class loader

Returns:
the class loader

nonNull

public static <T> T[] nonNull(T[] array,
                              java.lang.Class<?> theClass)
make sure a array is non null. If null, then return an empty array. Note: this will probably not work for primitive arrays (e.g. int[])

Type Parameters:
T -
Parameters:
array -
theClass - to make array from
Returns:
the list or empty list if null

prefixOrSuffix

public static java.lang.String prefixOrSuffix(java.lang.String startString,
                                              java.lang.String separator,
                                              boolean isPrefix)
get the prefix or suffix of a string based on a separator

Parameters:
startString - is the string to start with
separator - is the separator to split on
isPrefix - if thre prefix or suffix should be returned
Returns:
the prefix or suffix, if the separator isnt there, return the original string

indent

public static java.lang.String indent(java.lang.String string,
                                      boolean failIfTypeNotFound)
 this method will indent xml or json.
 this is for logging or documentations purposes only and should
 not be used for a production use (since it is not 100% tested
 or compliant with all constructs like xml CDATA
 
 For xml, assumes elements either have text or sub elements, not both.
 No cdata, nothing fancy.
 
 If the input is <a><b><c>hey</c><d><e>there</e></d></b></a>
 It would output:
 <a>
   <b>
     <c>hey</c>
     <d>
       <e>there</e>
     </d>
   </b>
 </a>
 
 For json, if the input is: {"a":{"b\"b":{"c\\":"d"},"e":"f","g":["h":"i"]}}
 It would output:
 {
   "a":{
     "b\"b":{
       "c\\":"d"
     },
     "e":"f",
     "g":[
       "h":"i"
     ]
   }
 }
 
 
 

Parameters:
string -
failIfTypeNotFound -
Returns:
the indented string, 2 spaces per line

extensionFromName

public static java.lang.String extensionFromName(java.lang.String name)
get the extension from name. if name is a:b:c, name is c

Parameters:
name -
Returns:
the name

forName

public static java.lang.Class forName(java.lang.String origClassName)
Returns the class object.

Parameters:
origClassName - is fully qualified
Returns:
the class

newInstance

public static <T> T newInstance(java.lang.Class<T> theClass)
Construct a class

Type Parameters:
T - template type
Parameters:
theClass -
Returns:
the instance

newInstance

public static <T> T newInstance(java.lang.Class<T> theClass,
                                boolean allowPrivateConstructor)
Construct a class

Type Parameters:
T - template type
Parameters:
theClass -
allowPrivateConstructor - true if should allow private constructors
Returns:
the instance

parentStemNameFromName

public static java.lang.String parentStemNameFromName(java.lang.String name)
get the parent stem name from name. if already a root stem then just return null. e.g. if the name is a:b:c then the return value is a:b

Parameters:
name -
Returns:
the parent stem name or null if none

defaultIfBlank

public static java.lang.String defaultIfBlank(java.lang.String string,
                                              java.lang.String defaultStringIfBlank)
return the string or the other if the first is blank

Parameters:
string -
defaultStringIfBlank -
Returns:
the string or the default one

defaultIfNull

public static <T> T defaultIfNull(T theValue,
                                  T defaultIfTheValueIsNull)
genericized method to see if first is null, if so then return second, else first.

Type Parameters:
T -
Parameters:
theValue - first input
defaultIfTheValueIsNull - second input
Returns:
the first if not null, second if no

addIfNotThere

public static <T> void addIfNotThere(java.util.Collection<T> list,
                                     java.util.Collection<T> listToAdd)
add each element of listToAdd if it is not already in list

Type Parameters:
T -
Parameters:
list - to add to
listToAdd - each element will be added to list, or null if none

setToString

public static java.lang.String setToString(java.util.Set set)
convert a set to a string (comma separate)

Parameters:
set -
Returns:
the String

MapToString

@Deprecated
public static java.lang.String MapToString(java.util.Map map)
Deprecated. use mapToString(map)

convert a set to a string (comma separate)

Parameters:
map -
Returns:
the String

mapToString

public static java.lang.String mapToString(java.util.Map map)
convert a set to a string (comma separate)

Parameters:
map -
Returns:
the String

toStringForLog

public static java.lang.String toStringForLog(java.lang.Object object)
print out various types of objects

Parameters:
object -
Returns:
the string value

toStringForLog

public static java.lang.String toStringForLog(java.lang.Object object,
                                              int maxChars)
print out various types of objects

Parameters:
object -
maxChars - is the max chars that should be returned (abbreviate if longer), or -1 for any amount
Returns:
the string value

batchNumberOfBatches

public static int batchNumberOfBatches(int count,
                                       int batchSize)
If batching this is the number of batches

Parameters:
count - is size of set
batchSize -
Returns:
the number of batches

batchNumberOfBatches

public static int batchNumberOfBatches(java.util.Collection<?> collection,
                                       int batchSize)
If batching this is the number of batches

Parameters:
collection -
batchSize -
Returns:
the number of batches

batchList

public static <T> java.util.List<T> batchList(java.util.Collection<T> collection,
                                              int batchSize,
                                              int batchIndex)
retrieve a batch by 0 index. Will return an array of size batchSize or the remainder. the array will be full of elements. Note, this requires an ordered input (so use linkedhashset not hashset if doing sets)

Type Parameters:
T - template type
Parameters:
collection -
batchSize -
batchIndex -
Returns:
the list This never returns null, only empty list

splitTrim

public static java.lang.String[] splitTrim(java.lang.String input,
                                           java.lang.String separator)
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)

Parameters:
input - is the delimited input to split and trim
separator - is what to split on
Returns:
the array of items after split and trimmed, or null if input is null. will be trimmed to empty

splitTrimToList

public static java.util.List<java.lang.String> splitTrimToList(java.lang.String input,
                                                               java.lang.String separator)
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)

Parameters:
input - is the delimited input to split and trim
separator - is what to split on
Returns:
the list of items after split and trimmed, or null if input is null. will be trimmed to empty

splitTrim

public static java.lang.String[] splitTrim(java.lang.String input,
                                           java.lang.String separator,
                                           boolean treatAdjacentSeparatorsAsOne)
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)

Parameters:
input - is the delimited input to split and trim
separator - is what to split on
treatAdjacentSeparatorsAsOne -
Returns:
the array of items after split and trimmed, or null if input is null. will be trimmed to empty

escapeUrlEncode

public static java.lang.String escapeUrlEncode(java.lang.String string)
escape url chars (e.g. a # is %23)

Parameters:
string - input
Returns:
the encoded string

escapeUrlDecode

public static java.lang.String escapeUrlDecode(java.lang.String string)
unescape url chars (e.g. a space is %20)

Parameters:
string - input
Returns:
the encoded string

nonNull

public static <T> java.util.List<T> nonNull(java.util.List<T> list)
make sure a list is non null. If null, then return an empty list

Type Parameters:
T -
Parameters:
list -
Returns:
the list or empty list if null

nonNull

public static <T> java.util.Set<T> nonNull(java.util.Set<T> set)
make sure a list is non null. If null, then return an empty set

Type Parameters:
T -
Parameters:
set -
Returns:
the set or empty set if null

nonNull

public static <K,V> java.util.Map<K,V> nonNull(java.util.Map<K,V> map)
make sure it is non null, if null, then give new map

Type Parameters:
K - key of map
V - value of map
Parameters:
map - is map
Returns:
set non null

toListFromCollection

public static <T> java.util.List<T> toListFromCollection(java.util.Collection<T> collection)
convert a collection to a list (if already a list, keep it)

Type Parameters:
T -
Parameters:
collection -
Returns:
the list

toList

public static <T> java.util.List<T> toList(T... objects)
return a list of objects from varargs. Though if there is one object, and it is a list, return it.

Type Parameters:
T - template type of the objects
Parameters:
objects -
Returns:
the list or null if objects is null

toListClasses

public static java.util.List<java.lang.Class<?>> toListClasses(java.lang.Class<?>... classes)
convert classes to a list

Parameters:
classes -
Returns:
list of classes

toSet

public static <T> java.util.Set<T> toSet(T... objects)
return a set of objects from varargs.

Type Parameters:
T - template type of the objects
Parameters:
objects -
Returns:
the set

assertion

public static void assertion(boolean isTrue,
                             java.lang.String reason)
If false, throw an assertException, and give a reason

Parameters:
isTrue -
reason -

assignField

public static void assignField(java.lang.Class theClass,
                               java.lang.Object invokeOn,
                               java.lang.String fieldName,
                               java.lang.Object dataToAssign,
                               boolean callOnSupers,
                               boolean overrideSecurity,
                               boolean typeCast,
                               java.lang.Class<? extends java.lang.annotation.Annotation> annotationWithValueOverride)
assign data to a field

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
fieldName - method name to call
dataToAssign - data
callOnSupers - if static and method not exists, try on supers
overrideSecurity - true to call on protected or private etc methods
typeCast - true if we should typecast
annotationWithValueOverride - annotation with value of override

assignField

public static void assignField(java.lang.Class theClass,
                               java.lang.Object invokeOn,
                               java.lang.String fieldName,
                               java.lang.Object dataToAssign,
                               java.lang.Class<? extends java.lang.annotation.Annotation> annotationWithValueOverride)
assign data to a field. Will find the field in superclasses, will typecast, and will override security (private, protected, etc)

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
fieldName - method name to call
dataToAssign - data
annotationWithValueOverride - annotation with value of override

assignField

public static void assignField(java.lang.reflect.Field field,
                               java.lang.Object invokeOn,
                               java.lang.Object dataToAssign,
                               boolean overrideSecurity,
                               boolean typeCast)
assign data to a field

Parameters:
field - is the field to assign to
invokeOn - to call on or null for static
dataToAssign - data
overrideSecurity - true to call on protected or private etc methods
typeCast - true if we should typecast

iterator

public static java.util.Iterator iterator(java.lang.Object collection)
null safe iterator getter if the type if collection

Parameters:
collection -
Returns:
the iterator

length

public static int length(java.lang.Object arrayOrCollection)
Null safe array length or map

Parameters:
arrayOrCollection -
Returns:
the length of the array (0 for null)

next

public static java.lang.Object next(java.lang.Object arrayOrCollection,
                                    java.util.Iterator iterator,
                                    int index)
If array, get the element based on index, if Collection, get it based on iterator.

Parameters:
arrayOrCollection -
iterator -
index -
Returns:
the object

remove

public static java.lang.Object remove(java.lang.Object arrayOrCollection,
                                      int index)
Remove the iterator or index

Parameters:
arrayOrCollection -
index -
Returns:
the object list or new array

remove

public static java.lang.Object remove(java.lang.Object arrayOrCollection,
                                      java.util.Iterator iterator,
                                      int index)
Remove the iterator or index

Parameters:
arrayOrCollection -
iterator -
index -
Returns:
the object list or new array

classesString

public static java.lang.String classesString(java.lang.Object object)
print the simple names of a list of classes

Parameters:
object -
Returns:
the simple names

classNameCollection

public static java.lang.String classNameCollection(java.lang.Object object)
null safe classname method, max out at 20

Parameters:
object -
Returns:
the classname

className

public static java.lang.String className(java.lang.Object object)
null safe classname method, gets the unenhanced name

Parameters:
object -
Returns:
the classname

assignField

public static void assignField(java.lang.reflect.Field field,
                               java.lang.Object invokeOn,
                               java.lang.Object dataToAssign,
                               boolean overrideSecurity,
                               boolean typeCast,
                               java.lang.Class<? extends java.lang.annotation.Annotation> annotationWithValueOverride)
assign data to a field

Parameters:
field - is the field to assign to
invokeOn - to call on or null for static
dataToAssign - data
overrideSecurity - true to call on protected or private etc methods
typeCast - true if we should typecast
annotationWithValueOverride - annotation with value of override, or null if none

assignField

public static void assignField(java.lang.Object invokeOn,
                               java.lang.String fieldName,
                               java.lang.Object dataToAssign)
assign data to a field. Will find the field in superclasses, will typecast, and will override security (private, protected, etc)

Parameters:
invokeOn - to call on or null for static
fieldName - method name to call
dataToAssign - data

field

public static java.lang.reflect.Field field(java.lang.Class theClass,
                                            java.lang.String fieldName,
                                            boolean callOnSupers,
                                            boolean throwExceptionIfNotFound)
get a field object for a class, potentially in superclasses

Parameters:
theClass -
fieldName -
callOnSupers - true if superclasses should be looked in for the field
throwExceptionIfNotFound - will throw runtime exception if not found
Returns:
the field object or null if not found (or exception if param is set)

fieldNames

public static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass,
                                                         java.lang.Class fieldType,
                                                         boolean includeStaticFields)
return a set of Strings for a class and type. This is not for any supertypes, only for the type at hand. includes final fields

Parameters:
theClass -
fieldType - or null for all
includeStaticFields -
Returns:
the set of strings, or the empty Set if none

fieldNames

public static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass,
                                                         java.lang.Class superclassToStopAt,
                                                         java.lang.Class<?> fieldType,
                                                         boolean includeSuperclassToStopAt,
                                                         boolean includeStaticFields,
                                                         boolean includeFinalFields)
get all field names from a class, including superclasses (if specified)

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
fieldType - is the type of the field to get
includeSuperclassToStopAt - if we should include the superclass
includeStaticFields - if include static fields
includeFinalFields - if final fields should be included
Returns:
the set of field names or empty set if none

fieldNames

public static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass,
                                                         java.lang.Class superclassToStopAt,
                                                         java.lang.Class<?> fieldType,
                                                         boolean includeSuperclassToStopAt,
                                                         boolean includeStaticFields,
                                                         boolean includeFinalFields,
                                                         java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotationToIngore)
get all field names from a class, including superclasses (if specified). ignore a certain marker annotation

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
fieldType - is the type of the field to get
includeSuperclassToStopAt - if we should include the superclass
includeStaticFields - if include static fields
includeFinalFields - if final fields should be included
markerAnnotationToIngore - if this is not null, then if the field has this annotation, then do not include in list
Returns:
the set of field names

fieldNames

public static java.util.Set<java.lang.String> fieldNames(java.lang.Class theClass,
                                                         java.lang.Class superclassToStopAt,
                                                         java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotationToIngore)
get all field names from a class, including superclasses (if specified) (up to and including the specified superclass). ignore a certain marker annotation. Dont get static or final field, and get fields of all types

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
markerAnnotationToIngore - if this is not null, then if the field has this annotation, then do not include in list
Returns:
the set of field names or empty set if none

fields

public static java.util.Set<java.lang.reflect.Field> fields(java.lang.Class theClass,
                                                            java.lang.Class superclassToStopAt,
                                                            java.lang.Class fieldType,
                                                            boolean includeSuperclassToStopAt,
                                                            boolean includeStaticFields,
                                                            boolean includeFinalFields,
                                                            java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation,
                                                            boolean includeAnnotation)
get all fields from a class, including superclasses (if specified)

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
fieldType - is the type of the field to get
includeSuperclassToStopAt - if we should include the superclass
includeStaticFields - if include static fields
includeFinalFields - if final fields should be included
markerAnnotation - if this is not null, then if the field has this annotation, then do not include in list (if includeAnnotation is false)
includeAnnotation - true if the attribute should be included if annotation is present, false if exclude
Returns:
the set of fields (wont return null)

fields

public static java.util.Set<java.lang.reflect.Field> fields(java.lang.Class theClass,
                                                            java.lang.Class superclassToStopAt,
                                                            java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation,
                                                            boolean includeAnnotation)
get all fields from a class, including superclasses (if specified) (up to and including the specified superclass). ignore a certain marker annotation, or only include it. Dont get static or final field, and get fields of all types

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
markerAnnotation - if this is not null, then if the field has this annotation, then do not include in list (if includeAnnotation is false)
includeAnnotation - true if the attribute should be included if annotation is present, false if exclude
Returns:
the set of field names or empty set if none

compareObjectFields

public static java.util.Set<java.lang.String> compareObjectFields(java.lang.Object first,
                                                                  java.lang.Object second,
                                                                  java.util.Set<java.lang.String> fieldsToCompare,
                                                                  java.lang.String mapPrefix)
compare two objects, compare primitives, Strings, maps of string attributes. if both objects equal each others references, then return empty set. then, if not, then if either is null, return all fields

Parameters:
first -
second -
fieldsToCompare -
mapPrefix - is the prefix for maps which are compared (e.g. attribute__)
Returns:
the set of fields which are different. never returns null

clone

public static <T> T clone(T object,
                          java.util.Set<java.lang.String> fieldsToClone)
clone an object, assign primitives, Strings, maps of string attributes. Clone GrouperCloneable fields.

Type Parameters:
T - template
Parameters:
object -
fieldsToClone -
Returns:
the cloned object or null if input is null

cloneFields

public static <T> void cloneFields(T object,
                                   T result,
                                   java.util.Set<java.lang.String> fieldsToClone)
clone an object, assign primitives, Strings, maps of string attributes. Clone GrouperCloneable fields.

Type Parameters:
T - template
Parameters:
object -
result -
fieldsToClone -

cloneValue

public static <T> T cloneValue(T value)
helper method to clone the value of a field. just returns the same reference for primitives and immutables. Will subclone GrouperCloneables, and will throw exception if not expecting the type. Will clone sets, lists, maps.

Type Parameters:
T - template
Parameters:
value -
Returns:
the cloned value

methodNames

public static java.util.Set<java.lang.String> methodNames(java.lang.Class<?> theClass,
                                                          java.lang.Class<?> superclassToStopAt,
                                                          boolean includeSuperclassToStopAt,
                                                          boolean includeStaticMethods)
simple method to get method names

Parameters:
theClass -
superclassToStopAt -
includeSuperclassToStopAt -
includeStaticMethods -
Returns:
the set of method names

methodsHelper

public static void methodsHelper(java.lang.Class<?> theClass,
                                 java.lang.Class<?> superclassToStopAt,
                                 boolean includeSuperclassToStopAt,
                                 boolean includeStaticMethods,
                                 java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation,
                                 boolean includeAnnotation,
                                 java.util.Set<java.lang.reflect.Method> methodSet)
get the set of methods

Parameters:
theClass -
superclassToStopAt -
includeSuperclassToStopAt -
includeStaticMethods -
markerAnnotation -
includeAnnotation -
methodSet -

method

public static java.lang.reflect.Method method(java.lang.Class<?> theClass,
                                              java.lang.String methodName,
                                              java.lang.Object paramTypesOrArrayOrList,
                                              java.lang.Class<?> superclassToStopAt,
                                              boolean includeSuperclassToStopAt,
                                              boolean isStaticOrInstance,
                                              java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation,
                                              boolean includeAnnotation)
get the set of methods

Parameters:
theClass -
methodName -
paramTypesOrArrayOrList - types of the params
superclassToStopAt -
includeSuperclassToStopAt -
isStaticOrInstance - true if static
markerAnnotation -
includeAnnotation -
Returns:
the method or null if not found

fieldValue

public static java.lang.Object fieldValue(java.lang.Class theClass,
                                          java.lang.Object invokeOn,
                                          java.lang.String fieldName,
                                          boolean callOnSupers,
                                          boolean overrideSecurity)
find out a field value

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
fieldName - method name to call
callOnSupers - if static and method not exists, try on supers
overrideSecurity - true to call on protected or private etc methods
Returns:
the current value

fieldValue

public static java.lang.Object fieldValue(java.lang.reflect.Field field,
                                          java.lang.Object invokeOn)
get the value of a field, override security if needbe

Parameters:
field -
invokeOn -
Returns:
the value of the field

fieldValue

public static java.lang.Object fieldValue(java.lang.reflect.Field field,
                                          java.lang.Object invokeOn,
                                          boolean overrideSecurity)
get the value of a field

Parameters:
field -
invokeOn -
overrideSecurity -
Returns:
the value of the field

fieldValue

public static java.lang.Object fieldValue(java.lang.Object invokeOn,
                                          java.lang.String fieldName)
find out a field value (invoke on supers, override security)

Parameters:
invokeOn - to call on or null for static
fieldName - method name to call
Returns:
the current value

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.Object invokeOn,
                                          java.lang.String methodName)
helper method for calling a method with no params (could be in superclass)

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
methodName - method name to call
Returns:
the data

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.Object invokeOn,
                                          java.lang.String methodName,
                                          java.lang.Object paramTypesOrArrayOrList,
                                          java.lang.Object paramsOrListOrArray)
helper method for calling a method (could be in superclass)

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
methodName - method name to call
paramTypesOrArrayOrList - types of the params
paramsOrListOrArray - data
Returns:
the data

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.Object invokeOn,
                                          java.lang.String methodName,
                                          java.lang.Object paramTypesOrArrayOrList,
                                          java.lang.Object paramsOrListOrArray,
                                          boolean callOnSupers)
helper method for calling a method

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
methodName - method name to call
paramTypesOrArrayOrList - types of the params
paramsOrListOrArray - data
callOnSupers - if static and method not exists, try on supers
Returns:
the data

construct

public static <T> T construct(java.lang.Class<T> theClass,
                              java.lang.Class[] types,
                              java.lang.Object[] args)
construct an instance by reflection

Type Parameters:
T -
Parameters:
theClass -
args -
types -
Returns:
the instance

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.Object invokeOn,
                                          java.lang.String methodName,
                                          java.lang.Object paramTypesOrArrayOrList,
                                          java.lang.Object paramsOrListOrArray,
                                          boolean callOnSupers,
                                          boolean overrideSecurity)
helper method for calling a method

Parameters:
theClass - the class which has the method
invokeOn - to call on or null for static
methodName - method name to call
paramTypesOrArrayOrList - types of the params
paramsOrListOrArray - data
callOnSupers - if static and method not exists, try on supers
overrideSecurity - true to call on protected or private etc methods
Returns:
the data

invokeMethod

public static java.lang.Object invokeMethod(java.lang.reflect.Method method,
                                            java.lang.Object invokeOn)
Safely invoke a reflection method that takes no args

Parameters:
method - to invoke
invokeOn - if NO_PARAMS then will not pass in params.
Returns:
the result

invokeMethod

public static java.lang.Object invokeMethod(java.lang.reflect.Method method,
                                            java.lang.Object invokeOn,
                                            java.lang.Object paramsOrListOrArray)
Safely invoke a reflection method

Parameters:
method - to invoke
invokeOn -
paramsOrListOrArray - must be an arg. If null, will pass null. if NO_PARAMS then will not pass in params.
Returns:
the result

toArray

public static java.lang.Object toArray(java.lang.Object objectOrArrayOrCollection)
Convert a list to an array with the type of the first element e.g. if it is a list of Person objects, then the array is Person[]

Parameters:
objectOrArrayOrCollection - is a list
Returns:
the array of objects with type of the first element in the list

toArray

public static <T> T[] toArray(java.util.Collection collection,
                              java.lang.Class<T> theClass)
convert a list into an array of type of theClass

Type Parameters:
T - is the type of the array
Parameters:
collection - list to convert
theClass - type of array to return
Returns:
array of type theClass[] filled with the objects from list

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.String methodName)
helper method for calling a static method up the stack. method takes no args (could be in superclass)

Parameters:
theClass - the class which has the method
methodName - method name to call
Returns:
the data

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.String methodName,
                                          boolean callOnSupers)
helper method for calling a static method with no params

Parameters:
theClass - the class which has the method
methodName - method name to call
callOnSupers - if we should try the super classes if not exists in this class
Returns:
the data

callMethod

public static java.lang.Object callMethod(java.lang.Class theClass,
                                          java.lang.String methodName,
                                          java.lang.Object paramTypesOrArrayOrList,
                                          java.lang.Object paramsOrListOrArray)
helper method for calling a static method up the stack

Parameters:
theClass - the class which has the method
methodName - method name to call
paramTypesOrArrayOrList - types of the params
paramsOrListOrArray - data
Returns:
the data

callMethod

public static java.lang.Object callMethod(java.lang.Object invokeOn,
                                          java.lang.String methodName)
helper method for calling a method with no params (could be in superclass), will override security

Parameters:
invokeOn - instance to invoke on
methodName - method name to call not exists in this class
Returns:
the data

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.Object searchFor,
                                       java.lang.Object replaceWith)
replace a string or strings from a string, and put the output in a string buffer. This does not recurse

Parameters:
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with
Returns:
the string

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.Object searchFor,
                                       java.lang.Object replaceWith,
                                       boolean recurse)
replace a string or strings from a string, and put the output in a string buffer

Parameters:
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with
recurse - if true then do multiple replaces (on the replacements)
Returns:
the string

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.Object searchFor,
                                       java.lang.Object replaceWith,
                                       boolean recurse,
                                       boolean removeIfFound)
replace a string or strings from a string, and put the output in a string buffer

Parameters:
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with
recurse - if true then do multiple replaces (on the replacements)
removeIfFound - true if removing from searchFor and replaceWith if found
Returns:
the string

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String repl,
                                       java.lang.String with)

Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

 replace(null, *, *)        = null
 replace("", *, *)          = ""
 replace("any", null, *)    = "any"
 replace("any", *, null)    = "any"
 replace("any", "", *)      = "any"
 replace("aba", "a", null)  = "aba"
 replace("aba", "a", "")    = "b"
 replace("aba", "a", "z")   = "zbz"
 

Parameters:
text - text to search and replace in, may be null
repl - the String to search for, may be null
with - the String to replace with, may be null
Returns:
the text with any replacements processed, null if null String input
See Also:
replace(String text, String repl, String with, int max)

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String repl,
                                       java.lang.String with,
                                       int max)

Replaces a String with another String inside a larger String, for the first max values of the search String.

A null reference passed to this method is a no-op.

 replace(null, *, *, *)         = null
 replace("", *, *, *)           = ""
 replace("any", null, *, *)     = "any"
 replace("any", *, null, *)     = "any"
 replace("any", "", *, *)       = "any"
 replace("any", *, *, 0)        = "any"
 replace("abaa", "a", null, -1) = "abaa"
 replace("abaa", "a", "", -1)   = "b"
 replace("abaa", "a", "z", 0)   = "abaa"
 replace("abaa", "a", "z", 1)   = "zbaa"
 replace("abaa", "a", "z", 2)   = "zbza"
 replace("abaa", "a", "z", -1)  = "zbzz"
 

Parameters:
text - text to search and replace in, may be null
repl - the String to search for, may be null
with - the String to replace with, may be null
max - maximum number of values to replace, or -1 if no maximum
Returns:
the text with any replacements processed, null if null String input

isEmpty

public static boolean isEmpty(java.lang.String str)

Checks if a String is empty ("") or null.

 isEmpty(null)      = true
 isEmpty("")        = true
 isEmpty(" ")       = false
 isEmpty("bob")     = false
 isEmpty("  bob  ") = false
 

NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().

Parameters:
str - the String to check, may be null
Returns:
true if the String is empty or null

replace

public static void replace(java.lang.StringBuffer outBuffer,
                           java.lang.String text,
                           java.lang.Object searchFor,
                           java.lang.Object replaceWith)
replace a string or strings from a string, and put the output in a string buffer. This does not recurse

Parameters:
outBuffer - stringbuffer to write to
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with

replace

public static void replace(java.lang.StringBuffer outBuffer,
                           java.lang.String text,
                           java.lang.Object searchFor,
                           java.lang.Object replaceWith,
                           boolean recurse)
replace a string or strings from a string, and put the output in a string buffer

Parameters:
outBuffer - stringbuffer to write to
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with
recurse - if true then do multiple replaces (on the replacements)

replace

public static void replace(java.io.Writer outWriter,
                           java.lang.String text,
                           java.lang.Object searchFor,
                           java.lang.Object replaceWith)
replace a string or strings from a string, and put the output in a string buffer. This does not recurse

Parameters:
outWriter - writer to write to
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with

replace

public static void replace(java.io.Writer outWriter,
                           java.lang.String text,
                           java.lang.Object searchFor,
                           java.lang.Object replaceWith,
                           boolean recurse)
replace a string or strings from a string, and put the output in a string buffer

Parameters:
outWriter - writer to write to
text - string to look in
searchFor - string array to search for
replaceWith - string array to replace with
recurse - if true then do multiple replaces (on the replacements)

packInts

public static long packInts(int first,
                            int second)
pack two ints into a long. Note: the first is held in the left bits, the second is held in the right bits

Parameters:
first - is first int
second - is second int
Returns:
the long which has two ints in there

unpackInt

public static int unpackInt(long theLong,
                            boolean isFirst)
take a long

Parameters:
theLong - to unpack
isFirst - true for first, false for second
Returns:
one of the packed ints, first or second

get

public static java.lang.Object get(java.lang.Object arrayOrCollection,
                                   int index)
Get a specific index of an array or collection (note for collections and iterating, it is more efficient to get an iterator and iterate

Parameters:
arrayOrCollection -
index -
Returns:
the object at that index

toStringSafe

public static java.lang.String toStringSafe(java.lang.Object object)
fail safe toString for Exception blocks, and include the stack if there is a problem with toString()

Parameters:
object -
Returns:
the toStringSafe string

booleanValue

public static boolean booleanValue(java.lang.Object object)
get the boolean value for an object, cant be null or blank

Parameters:
object -
Returns:
the boolean

booleanValue

public static boolean booleanValue(java.lang.Object object,
                                   boolean defaultBoolean)
get the boolean value for an object

Parameters:
object -
defaultBoolean - if object is null or empty
Returns:
the boolean

booleanObjectValue

public static java.lang.Boolean booleanObjectValue(java.lang.Object object)
get the Boolean value for an object

Parameters:
object -
Returns:
the Boolean or null if null or empty

nullOrBlank

public static boolean nullOrBlank(java.lang.Object object)
is an object null or blank

Parameters:
object -
Returns:
true if null or blank

getter

public static java.lang.reflect.Method getter(java.lang.Class theClass,
                                              java.lang.String fieldName,
                                              boolean callOnSupers,
                                              boolean throwExceptionIfNotFound)
get a getter method object for a class, potentially in superclasses

Parameters:
theClass -
fieldName -
callOnSupers - true if superclasses should be looked in for the getter
throwExceptionIfNotFound - will throw runtime exception if not found
Returns:
the getter object or null if not found (or exception if param is set)

getterHelper

public static java.lang.reflect.Method getterHelper(java.lang.Class theClass,
                                                    java.lang.String fieldName,
                                                    java.lang.String getterName,
                                                    boolean callOnSupers,
                                                    boolean throwExceptionIfNotFound)
get a setter method object for a class, potentially in superclasses

Parameters:
theClass -
fieldName -
getterName - name of setter
callOnSupers - true if superclasses should be looked in for the setter
throwExceptionIfNotFound - will throw runtime exception if not found
Returns:
the setter object or null if not found (or exception if param is set)

getterNameFromPropertyName

public static java.lang.String getterNameFromPropertyName(java.lang.String propertyName)
generate getBb from bb

Parameters:
propertyName -
Returns:
the getter

getters

public static java.util.Set<java.lang.reflect.Method> getters(java.lang.Class theClass,
                                                              java.lang.Class superclassToStopAt,
                                                              java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation,
                                                              java.lang.Boolean includeAnnotation)
get all getters from a class, including superclasses (if specified) (up to and including the specified superclass). ignore a certain marker annotation, or only include it. Dont get static or final getters, and get getters of all types

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
markerAnnotation - if this is not null, then if the field has this annotation, then do not include in list (if includeAnnotation is false)
includeAnnotation - true if the attribute should be included if annotation is present, false if exclude
Returns:
the set of field names or empty set if none

isGetter

public static boolean isGetter(java.lang.reflect.Method method)
if the method name starts with get, and takes no args, and returns something, then getter

Parameters:
method -
Returns:
true if getter

assignSetter

public static void assignSetter(java.lang.Object invokeOn,
                                java.lang.String fieldName,
                                java.lang.Object dataToAssign,
                                boolean typeCast)
assign data to a setter. Will find the field in superclasses, will typecast, and will override security (private, protected, etc)

Parameters:
invokeOn - to call on or null for static
fieldName - method name to call
dataToAssign - data
typeCast - will typecast if true
Throws:
java.lang.RuntimeException - if not there

isSetter

public static boolean isSetter(java.lang.reflect.Method method)
if the method name starts with get, and takes no args, and returns something, then getter

Parameters:
method -
Returns:
true if getter

setter

public static java.lang.reflect.Method setter(java.lang.Class theClass,
                                              java.lang.String fieldName,
                                              boolean callOnSupers,
                                              boolean throwExceptionIfNotFound)
get a setter method object for a class, potentially in superclasses

Parameters:
theClass -
fieldName -
callOnSupers - true if superclasses should be looked in for the setter
throwExceptionIfNotFound - will throw runtime exception if not found
Returns:
the setter object or null if not found (or exception if param is set)

setterHelper

public static java.lang.reflect.Method setterHelper(java.lang.Class theClass,
                                                    java.lang.String fieldName,
                                                    java.lang.String setterName,
                                                    boolean callOnSupers,
                                                    boolean throwExceptionIfNotFound)
get a setter method object for a class, potentially in superclasses

Parameters:
theClass -
fieldName -
setterName - name of setter
callOnSupers - true if superclasses should be looked in for the setter
throwExceptionIfNotFound - will throw runtime exception if not found
Returns:
the setter object or null if not found (or exception if param is set)

setterNameFromPropertyName

public static java.lang.String setterNameFromPropertyName(java.lang.String propertyName)
generate setBb from bb

Parameters:
propertyName -
Returns:
the setter

setters

public static java.util.Set<java.lang.reflect.Method> setters(java.lang.Class theClass,
                                                              java.lang.Class superclassToStopAt,
                                                              java.lang.Class<?> fieldType,
                                                              boolean includeSuperclassToStopAt,
                                                              java.lang.Class<? extends java.lang.annotation.Annotation> markerAnnotation,
                                                              boolean includeAnnotation)
get all setters from a class, including superclasses (if specified)

Parameters:
theClass - to look for fields in
superclassToStopAt - to go up to or null to go up to Object
fieldType - is the type of the field to get
includeSuperclassToStopAt - if we should include the superclass
markerAnnotation - if this is not null, then if the field has this annotation, then do not include in list (if includeAnnotation is false)
includeAnnotation - true if the attribute should be included if annotation is present, false if exclude
Returns:
the set of fields (wont return null)

propertyName

public static java.lang.String propertyName(java.lang.reflect.Method method)
If this is a getter or setter, then get the property name

Parameters:
method -
Returns:
the property name

propertyType

public static java.lang.Class propertyType(java.lang.Class theClass,
                                           java.lang.String propertyName)
use reflection to get a property type based on getter or setter or field

Parameters:
theClass -
propertyName -
Returns:
the property type

typeCast

public static <T> T typeCast(java.lang.Object value,
                             java.lang.Class<T> theClass)
If necessary, convert an object to another type. if type is Object.class, just return the input. Do not convert null to an empty primitive

Type Parameters:
T - is template type
Parameters:
value -
theClass -
Returns:
the object of that instance converted into something else

removeEnd

public static void removeEnd(java.lang.StringBuilder str,
                             java.lang.String remove)
remove end if there

Parameters:
str -
remove -

endsWith

public static boolean endsWith(java.lang.StringBuilder str,
                               java.lang.String end)
Parameters:
str -
end -
Returns:
true if ends with

newFileUniqueName

public static java.io.File newFileUniqueName(java.lang.String parentDirName,
                                             java.lang.String namePrefix,
                                             java.lang.String nameSuffix,
                                             boolean createFile)
 make a new file in the name prefix dir.  If parent dir name is c:\temp
 and namePrefix is grouperDdl and nameSuffix is sql, then the file will be:
 
 c:\temp\grouperDdl_20080721_13_45_43_123.sql
  
 If the file exists, it will make a new filename, and create the empty file, and return it
 

Parameters:
parentDirName - can be blank for current dir
namePrefix - the part before the date part
nameSuffix - the last part of file name (can contain dot or will be the extension
createFile - true to create the file
Returns:
the created file

dateValue

public static java.util.Date dateValue(java.lang.Object inputObject)
 Convert an object to a java.util.Date.  allows, dates, null, blank, 
 yyyymmdd or yyyymmdd hh24:mm:ss
 or yyyy/MM/dd HH:mm:ss.SSS
 

Parameters:
inputObject - is the String or Date to convert
Returns:
the Date

isBlank

public static boolean isBlank(java.lang.Object input)
See if the input is null or if string, if it is empty or blank (whitespace)

Parameters:
input -
Returns:
true if blank

typeCast

public static <T> T typeCast(java.lang.Object value,
                             java.lang.Class<T> theClass,
                             boolean convertNullToDefaultPrimitive,
                             boolean useNewInstanceHooks)
If necessary, convert an object to another type. if type is Object.class, just return the input

Type Parameters:
T - is the type to return
Parameters:
value -
theClass -
convertNullToDefaultPrimitive - if the value is null, and theClass is primitive, should we convert the null to a primitive default value
useNewInstanceHooks - if theClass is not recognized, then honor the string "null", "newInstance", or get a constructor with one param, and call it
Returns:
the object of that instance converted into something else

isScalar

public static boolean isScalar(java.lang.Class<?> type)
see if a class is a scalar (not bean, not array or list, etc)

Parameters:
type -
Returns:
true if scalar

toTimestamp

public static java.sql.Timestamp toTimestamp(java.lang.Object input)
 Convert a string or object to a timestamp (could be string, date, timestamp, etc)
 yyyymmdd
 or
 yyyy/MM/dd HH:mm:ss
 or
 yyyy/MM/dd HH:mm:ss.SSS
 or
 yyyy/MM/dd HH:mm:ss.SSSSSS
 
 

Parameters:
input -
Returns:
the timestamp
Throws:
java.lang.RuntimeException - if invalid format

removeEnd

public static java.lang.String removeEnd(java.lang.String str,
                                         java.lang.String remove)

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null. An empty ("") source string will return the empty string. A null search string will return the source string.

 StringUtils.removeEnd(null, *)      = null
 StringUtils.removeEnd("", *)        = ""
 StringUtils.removeEnd(*, null)      = *
 StringUtils.removeEnd("www.domain.com", ".com.")  = "www,domain"
 StringUtils.removeEnd("www.domain.com", ".com")   = "www.domain"
 StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
 StringUtils.removeEnd("abc", "")    = "abc"
 

Parameters:
str - the source String to search, may be null
remove - the String to search for and remove, may be null
Returns:
the substring with the string removed if found, null if null String input
Since:
2.1

stringValue

public static java.lang.String stringValue(java.lang.Object input)
convert an object to a string

Parameters:
input - is the object to convert
Returns:
the String conversion of the object

timestampToString

public static java.lang.String timestampToString(java.util.Date timestamp)
Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS

Parameters:
timestamp -
Returns:
the string representation

stringValue

public static java.lang.String stringValue(java.util.Date date)
convert a date to the standard string yyyymmdd

Parameters:
date -
Returns:
the string value

stringToTimestamp

public static java.sql.Timestamp stringToTimestamp(java.lang.String input)
convert a string to timestamp based on the following formats:
 yyyyMMdd
 yyyy/MM/dd HH:mm:ss
 yyyy/MM/dd HH:mm:ss.SSS
 yyyy/MM/dd HH:mm:ss.SSSSSS
 

Parameters:
input -
Returns:
the timestamp object

bigDecimalObjectValue

public static java.math.BigDecimal bigDecimalObjectValue(java.lang.Object input)
Convert an object to a byte, allow nulls

Parameters:
input -
Returns:
the boolean object value

byteObjectValue

public static java.lang.Byte byteObjectValue(java.lang.Object input)
Convert an object to a byte, allow nulls

Parameters:
input -
Returns:
the boolean object value

byteValue

public static byte byteValue(java.lang.Object input)
convert an object to a byte

Parameters:
input -
Returns:
the byte

doubleObjectValue

public static java.lang.Double doubleObjectValue(java.lang.Object input,
                                                 boolean allowNullBlank)
get the Double value of an object

Parameters:
input - is a number or String
allowNullBlank - used to default to false, if true, return null if nul inputted
Returns:
the Double equivalent

doubleValue

public static double doubleValue(java.lang.Object input)
get the double value of an object

Parameters:
input - is a number or String
Returns:
the double equivalent

doubleValueNoError

public static double doubleValueNoError(java.lang.Object input)
get the double value of an object, do not throw an exception if there is an error

Parameters:
input - is a number or String
Returns:
the double equivalent

floatObjectValue

public static java.lang.Float floatObjectValue(java.lang.Object input,
                                               boolean allowNullBlank)
get the Float value of an object

Parameters:
input - is a number or String
allowNullBlank - true if allow null or blank
Returns:
the Float equivalent

floatValue

public static float floatValue(java.lang.Object input)
get the float value of an object

Parameters:
input - is a number or String
Returns:
the float equivalent

floatValueNoError

public static float floatValueNoError(java.lang.Object input)
get the float value of an object, do not throw an exception if there is an error

Parameters:
input - is a number or String
Returns:
the float equivalent

intObjectValue

public static java.lang.Integer intObjectValue(java.lang.Object input,
                                               boolean allowNullBlank)
get the Integer value of an object

Parameters:
input - is a number or String
allowNullBlank - true if convert null or blank to null
Returns:
the Integer equivalent

intValue

public static int intValue(java.lang.Object input)
convert an object to a int

Parameters:
input -
Returns:
the number

intValue

public static int intValue(java.lang.Object input,
                           int valueIfNull)
convert an object to a int

Parameters:
input -
valueIfNull - is if the input is null or empty, return this value
Returns:
the number

intValueNoError

public static int intValueNoError(java.lang.Object input)
get the int value of an object, do not throw an exception if there is an error

Parameters:
input - is a number or String
Returns:
the int equivalent

longObjectValue

public static java.lang.Long longObjectValue(java.lang.Object input,
                                             boolean allowNullBlank)
get the Long value of an object

Parameters:
input - is a number or String
allowNullBlank - true if null or blank converts to null
Returns:
the Long equivalent

longValue

public static long longValue(java.lang.Object input)
convert an object to a long

Parameters:
input -
Returns:
the number

longValue

public static long longValue(java.lang.Object input,
                             long valueIfNull)
convert an object to a long

Parameters:
input -
valueIfNull - is if the input is null or empty, return this value
Returns:
the number

longValueNoError

public static long longValueNoError(java.lang.Object input)
get the long value of an object, do not throw an exception if there is an error

Parameters:
input - is a number or String
Returns:
the long equivalent

shortObjectValue

public static java.lang.Short shortObjectValue(java.lang.Object input)
get the Short value of an object. converts null or blank to null

Parameters:
input - is a number or String
Returns:
the Long equivalent

shortValue

public static short shortValue(java.lang.Object input)
convert an object to a short

Parameters:
input -
Returns:
the number

charObjectValue

public static java.lang.Character charObjectValue(java.lang.Object input)
get the Character wrapper value for the input

Parameters:
input - allow null, return null
Returns:
the Character object wrapper

charValue

public static char charValue(java.lang.Object input)
convert an object to a char

Parameters:
input -
Returns:
the number

createParentDirectories

public static void createParentDirectories(java.io.File file)
Create the parent directories for a file if they do not already exist

Parameters:
file -

saveStringIntoFile

public static void saveStringIntoFile(java.io.File file,
                                      java.lang.String contents)
save a string into a file, file does not have to exist

Parameters:
file - is the file to save to
contents - is the contents of the file

saveStringIntoFile

public static boolean saveStringIntoFile(java.io.File file,
                                         java.lang.String contents,
                                         boolean onlyIfDifferentContents,
                                         boolean ignoreWhitespace)
save a string into a file, file does not have to exist

Parameters:
file - is the file to save to
contents - is the contents of the file
onlyIfDifferentContents - true if only saving due to different contents
ignoreWhitespace - true to ignore whitespace
Returns:
true if contents were saved (thus different if param set)

writeStringToFile

public static void writeStringToFile(java.io.File file,
                                     java.lang.String data,
                                     java.lang.String encoding)
                              throws java.io.IOException

Writes data to a file. The file will be created if it does not exist.

There is no readFileToString method without encoding parameter because the default encoding can differ between platforms and therefore results in inconsistent results.

Parameters:
file - the file to write.
data - The content to write to the file.
encoding - encoding to use
Throws:
java.io.IOException - in case of an I/O error
java.io.UnsupportedEncodingException - if the encoding is not supported by the VM

readFileIntoString

public static java.lang.String readFileIntoString(java.io.File file)
Parameters:
file - is the file to read into a string
Returns:
String

readResourceIntoString

public static java.lang.String readResourceIntoString(java.lang.String resourceName,
                                                      boolean allowNull)
Parameters:
resourceName - is the string resource from classpath to read (e.g. grouper.properties)
allowNull - is true if its ok if the resource is null or if it is not found or blank or whatever.
Returns:
String or null if allowed or RuntimeException if not allowed

readResourceIntoString

public static java.lang.String readResourceIntoString(java.lang.String resourceName,
                                                      java.lang.Class<?> classInJar)
read resource into string

Parameters:
resourceName -
classInJar - if not null, then look for the jar where this file is, and look in the same dir
Returns:
the properties or null if not exist

readFileToString

public static java.lang.String readFileToString(java.io.File file,
                                                java.lang.String encoding)
                                         throws java.io.IOException

Reads the contents of a file into a String.

There is no readFileToString method without encoding parameter because the default encoding can differ between platforms and therefore results in inconsistent results.

Parameters:
file - the file to read.
encoding - the encoding to use
Returns:
The file contents or null if read failed.
Throws:
java.io.IOException - in case of an I/O error

replaceWhitespaceWithSpace

public static java.lang.String replaceWhitespaceWithSpace(java.lang.String input)
replace all whitespace with space

Parameters:
input -
Returns:
the string

closeQuietly

public static void closeQuietly(java.io.InputStream input)
Unconditionally close an InputStream. Equivalent to InputStream.close(), except any exceptions will be ignored.

Parameters:
input - A (possibly null) InputStream

closeQuietly

public static void closeQuietly(java.io.OutputStream output)
Unconditionally close an OutputStream. Equivalent to OutputStream.close(), except any exceptions will be ignored.

Parameters:
output - A (possibly null) OutputStream

closeQuietly

public static void closeQuietly(java.io.Reader input)
Unconditionally close an Reader. Equivalent to Reader.close(), except any exceptions will be ignored.

Parameters:
input - A (possibly null) Reader

closeQuietly

public static void closeQuietly(java.io.Writer writer)
close a writer quietly

Parameters:
writer -

toString

public static java.lang.String toString(java.io.InputStream input,
                                        java.lang.String encoding)
                                 throws java.io.IOException
Get the contents of an InputStream as a String.

Parameters:
input - the InputStream to read from
encoding - The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.
Returns:
the requested String
Throws:
java.io.IOException - In case of an I/O problem

copy

public static void copy(java.io.InputStream input,
                        java.io.Writer output,
                        java.lang.String encoding)
                 throws java.io.IOException
Copy and convert bytes from an InputStream to chars on a Writer, using the specified encoding.

Parameters:
input - the InputStream to read from
output - the Writer to write to
encoding - The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.
Throws:
java.io.IOException - In case of an I/O problem

copy

public static int copy(java.io.Reader input,
                       java.io.Writer output)
                throws java.io.IOException
Copy chars from a Reader to a Writer.

Parameters:
input - the Reader to read from
output - the Writer to write to
Returns:
the number of characters copied
Throws:
java.io.IOException - In case of an I/O problem

convertLongToChar

public static java.lang.String convertLongToChar(long theLong)
this method takes a long (less than 62) and converts it to a 1 character string (a-z, A-Z, 0-9)

Parameters:
theLong - is the long (less than 62) to convert to a 1 character string
Returns:
a one character string

convertLongToCharSmall

public static java.lang.String convertLongToCharSmall(long theLong)
this method takes a long (less than 36) and converts it to a 1 character string (A-Z, 0-9)

Parameters:
theLong - is the long (less than 36) to convert to a 1 character string
Returns:
a one character string

convertLongToString

public static java.lang.String convertLongToString(long theLong)
convert a long to a string by converting it to base 62 (26 lower, 26 upper, 10 digits)

Parameters:
theLong - is the long to convert
Returns:
the String conversion of this

convertLongToStringSmall

public static java.lang.String convertLongToStringSmall(long theLong)
convert a long to a string by converting it to base 36 (26 upper, 10 digits)

Parameters:
theLong - is the long to convert
Returns:
the String conversion of this

incrementChar

public static char incrementChar(char theChar)
increment a character (A-Z then 0-9)

Parameters:
theChar -
Returns:
the value

incrementStringInt

public static char[] incrementStringInt(char[] string)
Increment a string with A-Z and 0-9 (no lower case so case insensitive apps like windows IE will still work)

Parameters:
string -
Returns:
the value

propertiesFromResourceName

public static java.util.Properties propertiesFromResourceName(java.lang.String resourceName)
read properties from a resource, dont modify the properties returned since they are cached

Parameters:
resourceName -
Returns:
the properties

propertiesCacheClear

public static void propertiesCacheClear()
clear properties cache (e.g. for testing)


propertiesFromFile

public static java.util.Properties propertiesFromFile(java.io.File file)
read properties from file

Parameters:
file -
Returns:
properties

propertiesFromResourceName

public static java.util.Properties propertiesFromResourceName(java.lang.String resourceName,
                                                              boolean useCache,
                                                              boolean exceptionIfNotExist,
                                                              java.lang.Class<?> classInJar,
                                                              java.lang.StringBuilder callingLog)
read properties from a resource, dont modify the properties returned since they are cached

Parameters:
resourceName -
useCache -
exceptionIfNotExist -
classInJar - if not null, then look for the jar where this file is, and look in the same dir
callingLog -
Returns:
the properties or null if not exist

enumValueOfIgnoreCase

public static <E extends java.lang.Enum<?>> E enumValueOfIgnoreCase(java.lang.Class<E> theEnumClass,
                                                                    java.lang.String string,
                                                                    boolean exceptionOnNotFound)
                                                         throws java.lang.RuntimeException
do a case-insensitive matching

Type Parameters:
E - generic type
Parameters:
theEnumClass - class of the enum
string -
exceptionOnNotFound - true if exception should be thrown on not found
Returns:
the enum or null or exception if not found
Throws:
java.lang.RuntimeException - if there is a problem

propertyValue

public static java.lang.Object propertyValue(java.lang.Object object,
                                             java.lang.String property)
this assumes the property exists, and is a simple property

Parameters:
object -
property -
Returns:
the value

propertiesValue

public static java.lang.String propertiesValue(java.util.Properties properties,
                                               java.lang.String key)
get a value (trimmed to e) from a property file

Parameters:
properties -
key -
Returns:
the property value

propertiesValue

public static java.lang.String propertiesValue(java.util.Properties properties,
                                               java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                               java.lang.String key)
get a value (trimmed to e) from a property file

Parameters:
properties -
overrideMap - for testing, to override some properties values
key -
Returns:
the property value

propertiesValue

public static java.lang.String propertiesValue(java.util.Properties properties,
                                               java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                               java.util.Map<java.lang.String,java.lang.String> overrideMap2,
                                               java.lang.String key)
get a value (trimmed to e) from a property file

Parameters:
properties -
overrideMap - for testing or threadlocal, to override some properties values
overrideMap2 - for testing, to provide some properties values
key -
Returns:
the property value

substituteCommonVars

public static java.lang.String substituteCommonVars(java.lang.String string)
substitute common vars like $space$ and $newline$

Parameters:
string -
Returns:
the string

propertiesValueBoolean

public static boolean propertiesValueBoolean(java.util.Properties properties,
                                             java.lang.String propertyName,
                                             boolean defaultValue)
get a boolean property, or the default if cant find

Parameters:
properties -
propertyName -
defaultValue -
Returns:
the boolean

propertiesValueBoolean

public static boolean propertiesValueBoolean(java.lang.String resourceName,
                                             java.util.Properties properties,
                                             java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                             java.lang.String propertyName,
                                             boolean defaultValue,
                                             boolean required)
get a boolean property, or the default if cant find. Validate also with a descriptive exception if problem

Parameters:
resourceName -
properties -
overrideMap - for testing to override properties
propertyName -
defaultValue -
required -
Returns:
the boolean

propertiesValueInt

public static int propertiesValueInt(java.lang.String resourceName,
                                     java.util.Properties properties,
                                     java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                     java.lang.String propertyName,
                                     int defaultValue,
                                     boolean required)
get an int property, or the default if cant find. Validate also with a descriptive exception if problem

Parameters:
resourceName -
properties -
overrideMap - for testing to override properties
propertyName -
defaultValue -
required -
Returns:
the int

propertiesValue

public static java.lang.String propertiesValue(java.lang.String resourceName,
                                               java.util.Properties properties,
                                               java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                               java.lang.String propertyName,
                                               boolean required)
get a boolean property, or the default if cant find. Validate also with a descriptive exception if problem

Parameters:
resourceName -
properties -
overrideMap - for threadlocal or testing to override properties
propertyName -
required -
Returns:
the string

propertiesValueInt

public static int propertiesValueInt(java.util.Properties properties,
                                     java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                     java.lang.String propertyName,
                                     int defaultValue)
get a int property, or the default if cant find

Parameters:
properties -
overrideMap - for testing to override properties
propertyName -
defaultValue -
Returns:
the int

propertiesValueInt

public static int propertiesValueInt(java.util.Properties properties,
                                     java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                     java.util.Map<java.lang.String,java.lang.String> overrideMap2,
                                     java.lang.String propertyName,
                                     int defaultValue)
get a int property, or the default if cant find

Parameters:
properties -
overrideMap - for testing to override properties
overrideMap2 -
propertyName -
defaultValue -
Returns:
the int

propertiesValueBoolean

public static boolean propertiesValueBoolean(java.util.Properties properties,
                                             java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                             java.lang.String propertyName,
                                             boolean defaultValue)
get a boolean property, or the default if cant find

Parameters:
properties -
overrideMap - for testing to override properties
propertyName -
defaultValue -
Returns:
the boolean

propertiesValueBoolean

public static boolean propertiesValueBoolean(java.util.Properties properties,
                                             java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                             java.util.Map<java.lang.String,java.lang.String> overrideMap2,
                                             java.lang.String propertyName,
                                             boolean defaultValue)
get a boolean property, or the default if cant find

Parameters:
properties -
overrideMap - for testing or threadlocal to override properties
overrideMap2 - for testing or threadlocal to override properties
propertyName -
defaultValue -
Returns:
the boolean

toMap

public static java.util.Map<?,?> toMap(java.lang.Object... keysAndValues)
keys and values go into map

Parameters:
keysAndValues -
Returns:
the map

closeQuietly

public static void closeQuietly(java.sql.Connection connection)
close a connection null safe and dont throw exception

Parameters:
connection -

closeQuietly

public static void closeQuietly(java.sql.Statement statement)
close a statement null safe and dont throw exception

Parameters:
statement -

closeQuietly

public static void closeQuietly(java.sql.ResultSet resultSet)
close a resultSet null safe and dont throw exception

Parameters:
resultSet -

hostname

public static java.lang.String hostname()
get the hostname of this machine

Returns:
the hostname

isAscii

public static boolean isAscii(char input)
is ascii char

Parameters:
input -
Returns:
true if ascii

lengthAscii

public static int lengthAscii(java.lang.String input)
find the length of ascii chars (non ascii are counted as two)

Parameters:
input -
Returns:
the length of ascii chars

rollbackQuietly

public static void rollbackQuietly(java.sql.Connection connection)
rollback a connection quietly

Parameters:
connection -

truncateAscii

public static java.lang.String truncateAscii(java.lang.String input,
                                             int requiredLength)
find the length of ascii chars (non ascii are counted as two)

Parameters:
input - is the string to operate on
requiredLength - length we need the string to be
Returns:
the length of ascii chars

readFromFileIfFile

public static java.lang.String readFromFileIfFile(java.lang.String in,
                                                  boolean disableExternalFileLookup)
if the input is a file, read string from file. if not, or if disabled from grouper.properties, return the input

Parameters:
in -
disableExternalFileLookup -
Returns:
the result

readFromFileIfFileExists

public static java.lang.String readFromFileIfFileExists(java.lang.String in,
                                                        boolean disableExternalFileLookup)
if the input is a file, read string from file. if not, or if disabled from grouper.properties, return the input note, pass could have slashes in it... so only do this if file exists...

Parameters:
in -
disableExternalFileLookup -
Returns:
the result

mkdirs

public static void mkdirs(java.io.File dir)
Create directories, throw exception if not possible. This is will be ok if the directory already exists (will not delete it)

Parameters:
dir -

equals

public static boolean equals(java.lang.String first,
                             java.lang.String second)
null safe string compare

Parameters:
first -
second -
Returns:
true if equal

isBlank

public static boolean isBlank(java.lang.String str)

Checks if a String is whitespace, empty ("") or null.

 isBlank(null)      = true
 isBlank("")        = true
 isBlank(" ")       = true
 isBlank("bob")     = false
 isBlank("  bob  ") = false
 

Parameters:
str - the String to check, may be null
Returns:
true if the String is null, empty or whitespace
Since:
2.0

isNotBlank

public static boolean isNotBlank(java.lang.String str)
Parameters:
str -
Returns:
true if not blank

trim

public static java.lang.String trim(java.lang.String str)
trim whitespace from string

Parameters:
str -
Returns:
trimmed string

equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String str1,
                                       java.lang.String str2)
equalsignorecase

Parameters:
str1 -
str2 -
Returns:
true if the strings are equal ignore case

trimToEmpty

public static java.lang.String trimToEmpty(java.lang.String str)
trim to empty, convert null to empty

Parameters:
str -
Returns:
trimmed

abbreviate

public static java.lang.String abbreviate(java.lang.String str,
                                          int maxWidth)

Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."

Specifically:

 StringUtils.abbreviate(null, *)      = null
 StringUtils.abbreviate("", 4)        = ""
 StringUtils.abbreviate("abcdefg", 6) = "abc..."
 StringUtils.abbreviate("abcdefg", 7) = "abcdefg"
 StringUtils.abbreviate("abcdefg", 8) = "abcdefg"
 StringUtils.abbreviate("abcdefg", 4) = "a..."
 StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException
 

Parameters:
str - the String to check, may be null
maxWidth - maximum length of result String, must be at least 4
Returns:
abbreviated String, null if null String input
Throws:
java.lang.IllegalArgumentException - if the width is too small
Since:
2.0

abbreviate

public static java.lang.String abbreviate(java.lang.String str,
                                          int offset,
                                          int maxWidth)

Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "...is the time for..."

Works like abbreviate(String, int), but allows you to specify a "left edge" offset. Note that this left edge is not necessarily going to be the leftmost character in the result, or the first character following the ellipses, but it will appear somewhere in the result.

In no case will it return a String of length greater than maxWidth.

 StringUtils.abbreviate(null, *, *)                = null
 StringUtils.abbreviate("", 0, 4)                  = ""
 StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..."
 StringUtils.abbreviate("abcdefghijklmno", 0, 10)  = "abcdefg..."
 StringUtils.abbreviate("abcdefghijklmno", 1, 10)  = "abcdefg..."
 StringUtils.abbreviate("abcdefghijklmno", 4, 10)  = "abcdefg..."
 StringUtils.abbreviate("abcdefghijklmno", 5, 10)  = "...fghi..."
 StringUtils.abbreviate("abcdefghijklmno", 6, 10)  = "...ghij..."
 StringUtils.abbreviate("abcdefghijklmno", 8, 10)  = "...ijklmno"
 StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno"
 StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno"
 StringUtils.abbreviate("abcdefghij", 0, 3)        = IllegalArgumentException
 StringUtils.abbreviate("abcdefghij", 5, 6)        = IllegalArgumentException
 

Parameters:
str - the String to check, may be null
offset - left edge of source String
maxWidth - maximum length of result String, must be at least 4
Returns:
abbreviated String, null if null String input
Throws:
java.lang.IllegalArgumentException - if the width is too small
Since:
2.0

split

public static java.lang.String[] split(java.lang.String str)

Splits the provided text into an array, using whitespace as the separator. Whitespace is defined by Character.isWhitespace(char).

The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.

A null input String returns null.

 StringUtils.split(null)       = null
 StringUtils.split("")         = []
 StringUtils.split("abc def")  = ["abc", "def"]
 StringUtils.split("abc  def") = ["abc", "def"]
 StringUtils.split(" abc ")    = ["abc"]
 

Parameters:
str - the String to parse, may be null
Returns:
an array of parsed Strings, null if null String input

split

public static java.lang.String[] split(java.lang.String str,
                                       char separatorChar)

Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.

The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.

A null input String returns null.

 StringUtils.split(null, *)         = null
 StringUtils.split("", *)           = []
 StringUtils.split("a.b.c", '.')    = ["a", "b", "c"]
 StringUtils.split("a..b.c", '.')   = ["a", "b", "c"]
 StringUtils.split("a:b:c", '.')    = ["a:b:c"]
 StringUtils.split("a\tb\nc", null) = ["a", "b", "c"]
 StringUtils.split("a b c", ' ')    = ["a", "b", "c"]
 

Parameters:
str - the String to parse, may be null
separatorChar - the character used as the delimiter, null splits on whitespace
Returns:
an array of parsed Strings, null if null String input
Since:
2.0

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String separatorChars)

Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.

The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.

A null input String returns null. A null separatorChars splits on whitespace.

 StringUtils.split(null, *)         = null
 StringUtils.split("", *)           = []
 StringUtils.split("abc def", null) = ["abc", "def"]
 StringUtils.split("abc def", " ")  = ["abc", "def"]
 StringUtils.split("abc  def", " ") = ["abc", "def"]
 StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
 

Parameters:
str - the String to parse, may be null
separatorChars - the characters used as the delimiters, null splits on whitespace
Returns:
an array of parsed Strings, null if null String input

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String separatorChars,
                                       int max)

Splits the provided text into an array with a maximum length, separators specified.

The separator is not included in the returned String array. Adjacent separators are treated as one separator.

A null input String returns null. A null separatorChars splits on whitespace.

If more than max delimited substrings are found, the last returned string includes all characters after the first max - 1 returned strings (including separator characters).

 StringUtils.split(null, *, *)            = null
 StringUtils.split("", *, *)              = []
 StringUtils.split("ab de fg", null, 0)   = ["ab", "cd", "ef"]
 StringUtils.split("ab   de fg", null, 0) = ["ab", "cd", "ef"]
 StringUtils.split("ab:cd:ef", ":", 0)    = ["ab", "cd", "ef"]
 StringUtils.split("ab:cd:ef", ":", 2)    = ["ab", "cd:ef"]
 

Parameters:
str - the String to parse, may be null
separatorChars - the characters used as the delimiters, null splits on whitespace
max - the maximum number of elements to include in the array. A zero or negative value implies no limit
Returns:
an array of parsed Strings, null if null String input

splitByWholeSeparator

public static java.lang.String[] splitByWholeSeparator(java.lang.String str,
                                                       java.lang.String separator)

Splits the provided text into an array, separator string specified.

The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.

A null input String returns null. A null separator splits on whitespace.

 StringUtils.split(null, *)            = null
 StringUtils.split("", *)              = []
 StringUtils.split("ab de fg", null)   = ["ab", "de", "fg"]
 StringUtils.split("ab   de fg", null) = ["ab", "de", "fg"]
 StringUtils.split("ab:cd:ef", ":")    = ["ab", "cd", "ef"]
 StringUtils.split("abstemiouslyaeiouyabstemiously", "aeiouy")  = ["bst", "m", "sl", "bst", "m", "sl"]
 StringUtils.split("abstemiouslyaeiouyabstemiously", "aeiouy")  = ["abstemiously", "abstemiously"]
 

Parameters:
str - the String to parse, may be null
separator - String containing the String to be used as a delimiter, null splits on whitespace
Returns:
an array of parsed Strings, null if null String was input

splitByWholeSeparator

public static java.lang.String[] splitByWholeSeparator(java.lang.String str,
                                                       java.lang.String separator,
                                                       int max)

Splits the provided text into an array, separator string specified. Returns a maximum of max substrings.

The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.

A null input String returns null. A null separator splits on whitespace.

 StringUtils.splitByWholeSeparator(null, *, *)               = null
 StringUtils.splitByWholeSeparator("", *, *)                 = []
 StringUtils.splitByWholeSeparator("ab de fg", null, 0)      = ["ab", "de", "fg"]
 StringUtils.splitByWholeSeparator("ab   de fg", null, 0)    = ["ab", "de", "fg"]
 StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2)       = ["ab", "cd"]
 StringUtils.splitByWholeSeparator("abstemiouslyaeiouyabstemiously", "aeiouy", 2) = ["bst", "m"]
 StringUtils.splitByWholeSeparator("abstemiouslyaeiouyabstemiously", "aeiouy", 2)  = ["abstemiously", "abstemiously"]
 

Parameters:
str - the String to parse, may be null
separator - String containing the String to be used as a delimiter, null splits on whitespace
max - the maximum number of elements to include in the returned array. A zero or negative value implies no limit.
Returns:
an array of parsed Strings, null if null String was input

splitPreserveAllTokens

public static java.lang.String[] splitPreserveAllTokens(java.lang.String str)

Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer. Whitespace is defined by Character.isWhitespace(char).

The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.

A null input String returns null.

 StringUtils.splitPreserveAllTokens(null)       = null
 StringUtils.splitPreserveAllTokens("")         = []
 StringUtils.splitPreserveAllTokens("abc def")  = ["abc", "def"]
 StringUtils.splitPreserveAllTokens("abc  def") = ["abc", "", "def"]
 StringUtils.splitPreserveAllTokens(" abc ")    = ["", "abc", ""]
 

Parameters:
str - the String to parse, may be null
Returns:
an array of parsed Strings, null if null String input
Since:
2.1

splitPreserveAllTokens

public static java.lang.String[] splitPreserveAllTokens(java.lang.String str,
                                                        char separatorChar)

Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.

The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.

A null input String returns null.

 StringUtils.splitPreserveAllTokens(null, *)         = null
 StringUtils.splitPreserveAllTokens("", *)           = []
 StringUtils.splitPreserveAllTokens("a.b.c", '.')    = ["a", "b", "c"]
 StringUtils.splitPreserveAllTokens("a..b.c", '.')   = ["a", "b", "c"]
 StringUtils.splitPreserveAllTokens("a:b:c", '.')    = ["a:b:c"]
 StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"]
 StringUtils.splitPreserveAllTokens("a b c", ' ')    = ["a", "b", "c"]
 StringUtils.splitPreserveAllTokens("a b c ", ' ')   = ["a", "b", "c", ""]
 StringUtils.splitPreserveAllTokens("a b c ", ' ')   = ["a", "b", "c", "", ""]
 StringUtils.splitPreserveAllTokens(" a b c", ' ')   = ["", a", "b", "c"]
 StringUtils.splitPreserveAllTokens("  a b c", ' ')  = ["", "", a", "b", "c"]
 StringUtils.splitPreserveAllTokens(" a b c ", ' ')  = ["", a", "b", "c", ""]
 

Parameters:
str - the String to parse, may be null
separatorChar - the character used as the delimiter, null splits on whitespace
Returns:
an array of parsed Strings, null if null String input
Since:
2.1

splitPreserveAllTokens

public static java.lang.String[] splitPreserveAllTokens(java.lang.String str,
                                                        java.lang.String separatorChars)

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.

The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.

A null input String returns null. A null separatorChars splits on whitespace.

 StringUtils.splitPreserveAllTokens(null, *)           = null
 StringUtils.splitPreserveAllTokens("", *)             = []
 StringUtils.splitPreserveAllTokens("abc def", null)   = ["abc", "def"]
 StringUtils.splitPreserveAllTokens("abc def", " ")    = ["abc", "def"]
 StringUtils.splitPreserveAllTokens("abc  def", " ")   = ["abc", "", def"]
 StringUtils.splitPreserveAllTokens("ab:cd:ef", ":")   = ["ab", "cd", "ef"]
 StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":")  = ["ab", "cd", "ef", ""]
 StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""]
 StringUtils.splitPreserveAllTokens("ab::cd:ef", ":")  = ["ab", "", cd", "ef"]
 StringUtils.splitPreserveAllTokens(":cd:ef", ":")     = ["", cd", "ef"]
 StringUtils.splitPreserveAllTokens("::cd:ef", ":")    = ["", "", cd", "ef"]
 StringUtils.splitPreserveAllTokens(":cd:ef:", ":")    = ["", cd", "ef", ""]
 

Parameters:
str - the String to parse, may be null
separatorChars - the characters used as the delimiters, null splits on whitespace
Returns:
an array of parsed Strings, null if null String input
Since:
2.1

splitPreserveAllTokens

public static java.lang.String[] splitPreserveAllTokens(java.lang.String str,
                                                        java.lang.String separatorChars,
                                                        int max)

Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. Adjacent separators are treated as one separator.

A null input String returns null. A null separatorChars splits on whitespace.

If more than max delimited substrings are found, the last returned string includes all characters after the first max - 1 returned strings (including separator characters).

 StringUtils.splitPreserveAllTokens(null, *, *)            = null
 StringUtils.splitPreserveAllTokens("", *, *)              = []
 StringUtils.splitPreserveAllTokens("ab de fg", null, 0)   = ["ab", "cd", "ef"]
 StringUtils.splitPreserveAllTokens("ab   de fg", null, 0) = ["ab", "cd", "ef"]
 StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 0)    = ["ab", "cd", "ef"]
 StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2)    = ["ab", "cd:ef"]
 StringUtils.splitPreserveAllTokens("ab   de fg", null, 2) = ["ab", "  de fg"]
 StringUtils.splitPreserveAllTokens("ab   de fg", null, 3) = ["ab", "", " de fg"]
 StringUtils.splitPreserveAllTokens("ab   de fg", null, 4) = ["ab", "", "", "de fg"]
 

Parameters:
str - the String to parse, may be null
separatorChars - the characters used as the delimiters, null splits on whitespace
max - the maximum number of elements to include in the array. A zero or negative value implies no limit
Returns:
an array of parsed Strings, null if null String input
Since:
2.1

join

public static java.lang.String join(java.lang.Object[] array)

Joins the elements of the provided array into a single String containing the provided list of elements.

No separator is added to the joined String. Null objects or empty strings within the array are represented by empty strings.

 StringUtils.join(null)            = null
 StringUtils.join([])              = ""
 StringUtils.join([null])          = ""
 StringUtils.join(["a", "b", "c"]) = "abc"
 StringUtils.join([null, "", "a"]) = "a"
 

Parameters:
array - the array of values to join together, may be null
Returns:
the joined String, null if null array input
Since:
2.0

join

public static java.lang.String join(java.lang.Object[] array,
                                    char separator)

Joins the elements of the provided array into a single String containing the provided list of elements.

No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

 StringUtils.join(null, *)               = null
 StringUtils.join([], *)                 = ""
 StringUtils.join([null], *)             = ""
 StringUtils.join(["a", "b", "c"], ';')  = "a;b;c"
 StringUtils.join(["a", "b", "c"], null) = "abc"
 StringUtils.join([null, "", "a"], ';')  = ";;a"
 

Parameters:
array - the array of values to join together, may be null
separator - the separator character to use
Returns:
the joined String, null if null array input
Since:
2.0

join

public static java.lang.String join(java.lang.Object[] array,
                                    java.lang.String separator)

Joins the elements of the provided array into a single String containing the provided list of elements.

No delimiter is added before or after the list. A null separator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.

 StringUtils.join(null, *)                = null
 StringUtils.join([], *)                  = ""
 StringUtils.join([null], *)              = ""
 StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
 StringUtils.join(["a", "b", "c"], null)  = "abc"
 StringUtils.join(["a", "b", "c"], "")    = "abc"
 StringUtils.join([null, "", "a"], ',')   = ",,a"
 

Parameters:
array - the array of values to join together, may be null
separator - the separator character to use, null treated as ""
Returns:
the joined String, null if null array input

join

public static java.lang.String join(java.util.Iterator iterator,
                                    char separator)

Joins the elements of the provided Iterator into a single String containing the provided elements.

No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.

See the examples here: join(Object[],char).

Parameters:
iterator - the Iterator of values to join together, may be null
separator - the separator character to use
Returns:
the joined String, null if null iterator input
Since:
2.0

join

public static java.lang.String join(java.util.Iterator iterator,
                                    java.lang.String separator)

Joins the elements of the provided Iterator into a single String containing the provided elements.

No delimiter is added before or after the list. A null separator is the same as an empty String ("").

See the examples here: join(Object[],String).

Parameters:
iterator - the Iterator of values to join together, may be null
separator - the separator character to use, null treated as ""
Returns:
the joined String, null if null iterator input

defaultString

public static java.lang.String defaultString(java.lang.String str)

Returns either the passed in String, or if the String is null, an empty String ("").

 StringUtils.defaultString(null)  = ""
 StringUtils.defaultString("")    = ""
 StringUtils.defaultString("bat") = "bat"
 

Parameters:
str - the String to check, may be null
Returns:
the passed in String, or the empty String if it was null
See Also:
String.valueOf(Object)

defaultString

public static java.lang.String defaultString(java.lang.String str,
                                             java.lang.String defaultStr)

Returns either the passed in String, or if the String is null, the value of defaultStr.

 StringUtils.defaultString(null, "NULL")  = "NULL"
 StringUtils.defaultString("", "NULL")    = ""
 StringUtils.defaultString("bat", "NULL") = "bat"
 

Parameters:
str - the String to check, may be null
defaultStr - the default String to return if the input is null, may be null
Returns:
the passed in String, or the default if it was null
See Also:
String.valueOf(Object)

defaultIfEmpty

public static java.lang.String defaultIfEmpty(java.lang.String str,
                                              java.lang.String defaultStr)

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

 StringUtils.defaultIfEmpty(null, "NULL")  = "NULL"
 StringUtils.defaultIfEmpty("", "NULL")    = "NULL"
 StringUtils.defaultIfEmpty("bat", "NULL") = "bat"
 

Parameters:
str - the String to check, may be null
defaultStr - the default String to return if the input is empty ("") or null, may be null
Returns:
the passed in String, or the default

capitalize

public static java.lang.String capitalize(java.lang.String str)

Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char). No other letters are changed.

A null input String returns null.

 StringUtils.capitalize(null)  = null
 StringUtils.capitalize("")    = ""
 StringUtils.capitalize("cat") = "Cat"
 StringUtils.capitalize("cAt") = "CAt"
 

Parameters:
str - the String to capitalize, may be null
Returns:
the capitalized String, null if null String input
Since:
2.0

contains

public static boolean contains(java.lang.String str,
                               char searchChar)

Checks if String contains a search character, handling null. This method uses String.indexOf(int).

A null or empty ("") String will return false.

 StringUtils.contains(null, *)    = false
 StringUtils.contains("", *)      = false
 StringUtils.contains("abc", 'a') = true
 StringUtils.contains("abc", 'z') = false
 

Parameters:
str - the String to check, may be null
searchChar - the character to find
Returns:
true if the String contains the search character, false if not or null string input
Since:
2.0

contains

public static boolean contains(java.lang.String str,
                               java.lang.String searchStr)

Checks if String contains a search String, handling null. This method uses String.indexOf(int).

A null String will return false.

 StringUtils.contains(null, *)     = false
 StringUtils.contains(*, null)     = false
 StringUtils.contains("", "")      = true
 StringUtils.contains("abc", "")   = true
 StringUtils.contains("abc", "a")  = true
 StringUtils.contains("abc", "z")  = false
 

Parameters:
str - the String to check, may be null
searchStr - the String to find, may be null
Returns:
true if the String contains the search String, false if not or null string input
Since:
2.0

equals

public static boolean equals(java.lang.Object object1,
                             java.lang.Object object2)

Compares two objects for equality, where either one or both objects may be null.

 ObjectUtils.equals(null, null)                  = true
 ObjectUtils.equals(null, "")                    = false
 ObjectUtils.equals("", null)                    = false
 ObjectUtils.equals("", "")                      = true
 ObjectUtils.equals(Boolean.TRUE, null)          = false
 ObjectUtils.equals(Boolean.TRUE, "true")        = false
 ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE)  = true
 ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false
 

Parameters:
object1 - the first object, may be null
object2 - the second object, may be null
Returns:
true if the values of both objects are the same

getFullStackTrace

public static java.lang.String getFullStackTrace(java.lang.Throwable throwable)

A way to get the entire nested stack-trace of an throwable.

Parameters:
throwable - the Throwable to be examined
Returns:
the nested stack trace, with the root cause first
Since:
2.0

getThrowables

public static java.lang.Throwable[] getThrowables(java.lang.Throwable throwable)

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return an array containing one element - the input throwable. A throwable with one cause will return an array containing two elements. - the input throwable and the cause throwable. A null throwable will return an array size zero.

Parameters:
throwable - the throwable to inspect, may be null
Returns:
the array of throwables, never null

isNestedThrowable

public static boolean isNestedThrowable(java.lang.Throwable throwable)

Checks whether this Throwable class can store a cause.

This method does not check whether it actually does store a cause.

Parameters:
throwable - the Throwable to examine, may be null
Returns:
boolean true if nested otherwise false
Since:
2.0

isThrowableNested

public static boolean isThrowableNested()

Checks if the Throwable class has a getCause method.

This is true for JDK 1.4 and above.

Returns:
true if Throwable is nestable
Since:
2.0

getCause

public static java.lang.Throwable getCause(java.lang.Throwable throwable)

Introspects the Throwable to obtain the cause.

The method searches for methods with specific names that return a Throwable object. This will pick up most wrapping exceptions, including those from JDK 1.4, and

The default list searched for are:

In the absence of any such method, the object is inspected for a detail field assignable to a Throwable.

If none of the above is found, returns null.

Parameters:
throwable - the throwable to introspect for a cause, may be null
Returns:
the cause of the Throwable, null if none found or null throwable input
Since:
1.0

getCause

public static java.lang.Throwable getCause(java.lang.Throwable throwable,
                                           java.lang.String[] methodNames)

Introspects the Throwable to obtain the cause.

  1. Try known exception types.
  2. Try the supplied array of method names.
  3. Try the field 'detail'.

A null set of method names means use the default set. A null in the set of method names will be ignored.

Parameters:
throwable - the throwable to introspect for a cause, may be null
methodNames - the method names, null treated as default set
Returns:
the cause of the Throwable, null if none found or null throwable input
Since:
1.0

argKey

public static java.lang.String argKey(java.lang.String option)
from a command line arg, get the key. e.g. if input is --whatever=something then key is whatever, value is something

Parameters:
option -
Returns:
the key

argValue

public static java.lang.String argValue(java.lang.String option)
from a command line arg, get the key. e.g. if input is --whatever=something then key is whatever, value is something

Parameters:
option -
Returns:
the value

argMap

public static java.util.Map<java.lang.String,java.lang.String> argMap(java.lang.String[] args)
add an option: --whatever=val to a map of options where --whatever is key, and val is value

Parameters:
args -
Returns:
the map

argMapString

public static java.lang.String argMapString(java.util.Map<java.lang.String,java.lang.String> argMap,
                                            java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                            java.lang.String key,
                                            boolean required)
get the value from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
required -
Returns:
the value or null or exception

argMapBoolean

public static boolean argMapBoolean(java.util.Map<java.lang.String,java.lang.String> argMap,
                                    java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                    java.lang.String key,
                                    boolean required,
                                    boolean defaultValue)
get the value from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
required -
defaultValue -
Returns:
the value or null or exception

argMapTimestamp

public static java.sql.Timestamp argMapTimestamp(java.util.Map<java.lang.String,java.lang.String> argMap,
                                                 java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                                 java.lang.String key)
get the value from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
Returns:
the value or null or exception

argMapBoolean

public static java.lang.Boolean argMapBoolean(java.util.Map<java.lang.String,java.lang.String> argMap,
                                              java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                              java.lang.String key)
get the value from the argMap

Parameters:
argMap -
argMapNotUsed -
key -
Returns:
the value or null or exception

argMapSet

public static java.util.Set<java.lang.String> argMapSet(java.util.Map<java.lang.String,java.lang.String> argMap,
                                                        java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                                        java.lang.String key,
                                                        boolean required)
get the set from comma separated from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
required -
Returns:
the value or null or exception

argMapList

public static java.util.List<java.lang.String> argMapList(java.util.Map<java.lang.String,java.lang.String> argMap,
                                                          java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                                          java.lang.String key,
                                                          boolean required)
get the list from comma separated from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
required -
Returns:
the value or null or exception

argMapFileList

public static java.util.List<java.lang.String> argMapFileList(java.util.Map<java.lang.String,java.lang.String> argMap,
                                                              java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                                              java.lang.String key,
                                                              boolean required)
get the list from comma separated from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
required -
Returns:
the value or null or exception

responseBodyAsString

public static java.lang.String responseBodyAsString(HttpMethodBase method)
for testing, get the response body as a string

Parameters:
method -
Returns:
the string of response body

copy

public static void copy(java.io.InputStream input,
                        java.io.Writer output)
                 throws java.io.IOException
Copy bytes from an InputStream to chars on a Writer using the default character encoding of the platform.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

This method uses InputStreamReader.

Parameters:
input - the InputStream to read from
output - the Writer to write to
Throws:
java.lang.NullPointerException - if the input or output is null
java.io.IOException - if an I/O error occurs
Since:
Commons IO 1.1

copy

public static int copy(java.io.InputStream input,
                       java.io.OutputStream output)
                throws java.io.IOException
Copy bytes from an InputStream to an OutputStream.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

Large streams (over 2GB) will return a bytes copied value of -1 after the copy has completed since the correct number of bytes cannot be returned as an int. For large streams use the copyLarge(InputStream, OutputStream) method.

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
Returns:
the number of bytes copied
Throws:
java.lang.NullPointerException - if the input or output is null
java.io.IOException - if an I/O error occurs
java.lang.ArithmeticException - if the byte count is too large
Since:
Commons IO 1.1

copyLarge

public static long copyLarge(java.io.InputStream input,
                             java.io.OutputStream output)
                      throws java.io.IOException
Copy bytes from a large (over 2GB) InputStream to an OutputStream.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
Returns:
the number of bytes copied
Throws:
java.lang.NullPointerException - if the input or output is null
java.io.IOException - if an I/O error occurs
Since:
Commons IO 1.3

jarFile

public static java.io.File jarFile(java.lang.Class sampleClass)
get a jar file from a sample class

Parameters:
sampleClass -
Returns:
the jar file

stripLastSlashIfExists

public static java.lang.String stripLastSlashIfExists(java.lang.String input)
strip the last slash (/ or \) from a string if it exists

Parameters:
input -
Returns:
input - the last / or \

retrievePasswordFromStdin

public static java.lang.String retrievePasswordFromStdin(boolean dontMask,
                                                         java.lang.String prompt)
retrieve a password from stdin

Parameters:
dontMask -
prompt - to print to user
Returns:
the password

retrievePasswordFromStdin

public static final char[] retrievePasswordFromStdin(java.io.InputStream in,
                                                     java.lang.String prompt)
                                              throws java.io.IOException
Parameters:
in - stream to be used (e.g. System.in)
prompt - The prompt to display to the user.
Returns:
The password as entered by the user.
Throws:
java.io.IOException

propertyValidateValueRequired

public static boolean propertyValidateValueRequired(java.lang.String resourceName,
                                                    java.util.Properties properties,
                                                    java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                                    java.lang.String key,
                                                    boolean exceptionOnError)
make sure a value exists in properties

Parameters:
resourceName -
properties -
overrideMap -
key -
exceptionOnError -
Returns:
true if ok, false if not

propertyValidateValueBoolean

public static boolean propertyValidateValueBoolean(java.lang.String resourceName,
                                                   java.util.Properties properties,
                                                   java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                                   java.lang.String key,
                                                   boolean required,
                                                   boolean exceptionOnError)
make sure a value is boolean in properties

Parameters:
resourceName -
properties -
overrideMap -
key -
required -
exceptionOnError -
Returns:
true if ok, false if not

propertyValidateValueInt

public static boolean propertyValidateValueInt(java.lang.String resourceName,
                                               java.util.Properties properties,
                                               java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                               java.lang.String key,
                                               boolean required,
                                               boolean exceptionOnError)
make sure a value is int in properties

Parameters:
resourceName -
properties -
overrideMap -
key -
required -
exceptionOnError -
Returns:
true if ok, false if not

propertyValidateValueClass

public static boolean propertyValidateValueClass(java.lang.String resourceName,
                                                 java.util.Properties properties,
                                                 java.util.Map<java.lang.String,java.lang.String> overrideMap,
                                                 java.lang.String key,
                                                 java.lang.Class<?> classType,
                                                 boolean required,
                                                 boolean exceptionOnError)
make sure a property is a class of a certain type

Parameters:
resourceName -
properties -
overrideMap -
key -
classType -
required -
exceptionOnError -
Returns:
true if ok

stripStart

public static java.lang.String stripStart(java.lang.String str,
                                          java.lang.String stripChars)

Strips any of a set of characters from the start of a String.

A null input String returns null. An empty string ("") input returns the empty string.

If the stripChars String is null, whitespace is stripped as defined by Character.isWhitespace(char).

 StringUtils.stripStart(null, *)          = null
 StringUtils.stripStart("", *)            = ""
 StringUtils.stripStart("abc", "")        = "abc"
 StringUtils.stripStart("abc", null)      = "abc"
 StringUtils.stripStart("  abc", null)    = "abc"
 StringUtils.stripStart("abc  ", null)    = "abc  "
 StringUtils.stripStart(" abc ", null)    = "abc "
 StringUtils.stripStart("yxabc  ", "xyz") = "abc  "
 

Parameters:
str - the String to remove characters from, may be null
stripChars - the characters to remove, null treated as whitespace
Returns:
the stripped String, null if null String input

stripEnd

public static java.lang.String stripEnd(java.lang.String str,
                                        java.lang.String stripChars)

Strips any of a set of characters from the end of a String.

A null input String returns null. An empty string ("") input returns the empty string.

If the stripChars String is null, whitespace is stripped as defined by Character.isWhitespace(char).

 StringUtils.stripEnd(null, *)          = null
 StringUtils.stripEnd("", *)            = ""
 StringUtils.stripEnd("abc", "")        = "abc"
 StringUtils.stripEnd("abc", null)      = "abc"
 StringUtils.stripEnd("  abc", null)    = "  abc"
 StringUtils.stripEnd("abc  ", null)    = "abc"
 StringUtils.stripEnd(" abc ", null)    = " abc"
 StringUtils.stripEnd("  abcyx", "xyz") = "  abc"
 

Parameters:
str - the String to remove characters from, may be null
stripChars - the characters to remove, null treated as whitespace
Returns:
the stripped String, null if null String input

repeat

public static java.lang.String repeat(java.lang.String str,
                                      int repeat)

Repeat a String repeat times to form a new String.

 StringUtils.repeat(null, 2) = null
 StringUtils.repeat("", 0)   = ""
 StringUtils.repeat("", 2)   = ""
 StringUtils.repeat("a", 3)  = "aaa"
 StringUtils.repeat("ab", 2) = "abab"
 StringUtils.repeat("a", -2) = ""
 

Parameters:
str - the String to repeat, may be null
repeat - number of times to repeat str, negative treated as zero
Returns:
a new String consisting of the original String repeated, null if null String input

rightPad

public static java.lang.String rightPad(java.lang.String str,
                                        int size)

Right pad a String with spaces (' ').

The String is padded to the size of size.

 StringUtils.rightPad(null, *)   = null
 StringUtils.rightPad("", 3)     = "   "
 StringUtils.rightPad("bat", 3)  = "bat"
 StringUtils.rightPad("bat", 5)  = "bat  "
 StringUtils.rightPad("bat", 1)  = "bat"
 StringUtils.rightPad("bat", -1) = "bat"
 

Parameters:
str - the String to pad out, may be null
size - the size to pad to
Returns:
right padded String or original String if no padding is necessary, null if null String input

rightPad

public static java.lang.String rightPad(java.lang.String str,
                                        int size,
                                        char padChar)

Right pad a String with a specified character.

The String is padded to the size of size.

 StringUtils.rightPad(null, *, *)     = null
 StringUtils.rightPad("", 3, 'z')     = "zzz"
 StringUtils.rightPad("bat", 3, 'z')  = "bat"
 StringUtils.rightPad("bat", 5, 'z')  = "batzz"
 StringUtils.rightPad("bat", 1, 'z')  = "bat"
 StringUtils.rightPad("bat", -1, 'z') = "bat"
 

Parameters:
str - the String to pad out, may be null
size - the size to pad to
padChar - the character to pad with
Returns:
right padded String or original String if no padding is necessary, null if null String input
Since:
2.0

rightPad

public static java.lang.String rightPad(java.lang.String str,
                                        int size,
                                        java.lang.String padStr)

Right pad a String with a specified String.

The String is padded to the size of size.

 StringUtils.rightPad(null, *, *)      = null
 StringUtils.rightPad("", 3, "z")      = "zzz"
 StringUtils.rightPad("bat", 3, "yz")  = "bat"
 StringUtils.rightPad("bat", 5, "yz")  = "batyz"
 StringUtils.rightPad("bat", 8, "yz")  = "batyzyzy"
 StringUtils.rightPad("bat", 1, "yz")  = "bat"
 StringUtils.rightPad("bat", -1, "yz") = "bat"
 StringUtils.rightPad("bat", 5, null)  = "bat  "
 StringUtils.rightPad("bat", 5, "")    = "bat  "
 

Parameters:
str - the String to pad out, may be null
size - the size to pad to
padStr - the String to pad with, null or empty treated as single space
Returns:
right padded String or original String if no padding is necessary, null if null String input

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size)

Left pad a String with spaces (' ').

The String is padded to the size of size.

 StringUtils.leftPad(null, *)   = null
 StringUtils.leftPad("", 3)     = "   "
 StringUtils.leftPad("bat", 3)  = "bat"
 StringUtils.leftPad("bat", 5)  = "  bat"
 StringUtils.leftPad("bat", 1)  = "bat"
 StringUtils.leftPad("bat", -1) = "bat"
 

Parameters:
str - the String to pad out, may be null
size - the size to pad to
Returns:
left padded String or original String if no padding is necessary, null if null String input

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size,
                                       char padChar)

Left pad a String with a specified character.

Pad to a size of size.

 StringUtils.leftPad(null, *, *)     = null
 StringUtils.leftPad("", 3, 'z')     = "zzz"
 StringUtils.leftPad("bat", 3, 'z')  = "bat"
 StringUtils.leftPad("bat", 5, 'z')  = "zzbat"
 StringUtils.leftPad("bat", 1, 'z')  = "bat"
 StringUtils.leftPad("bat", -1, 'z') = "bat"
 

Parameters:
str - the String to pad out, may be null
size - the size to pad to
padChar - the character to pad with
Returns:
left padded String or original String if no padding is necessary, null if null String input
Since:
2.0

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size,
                                       java.lang.String padStr)

Left pad a String with a specified String.

Pad to a size of size.

 StringUtils.leftPad(null, *, *)      = null
 StringUtils.leftPad("", 3, "z")      = "zzz"
 StringUtils.leftPad("bat", 3, "yz")  = "bat"
 StringUtils.leftPad("bat", 5, "yz")  = "yzbat"
 StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat"
 StringUtils.leftPad("bat", 1, "yz")  = "bat"
 StringUtils.leftPad("bat", -1, "yz") = "bat"
 StringUtils.leftPad("bat", 5, null)  = "  bat"
 StringUtils.leftPad("bat", 5, "")    = "  bat"
 

Parameters:
str - the String to pad out, may be null
size - the size to pad to
padStr - the String to pad with, null or empty treated as single space
Returns:
left padded String or original String if no padding is necessary, null if null String input

convertToRuntimeException

public static void convertToRuntimeException(java.lang.Exception e)
convert an exception to a runtime exception

Parameters:
e -

substringBefore

public static java.lang.String substringBefore(java.lang.String str,
                                               java.lang.String separator)

Gets the substring before the first occurrence of a separator. The separator is not returned.

A null string input will return null. An empty ("") string input will return the empty string. A null separator will return the input string.

 StringUtils.substringBefore(null, *)      = null
 StringUtils.substringBefore("", *)        = ""
 StringUtils.substringBefore("abc", "a")   = ""
 StringUtils.substringBefore("abcba", "b") = "a"
 StringUtils.substringBefore("abc", "c")   = "ab"
 StringUtils.substringBefore("abc", "d")   = "abc"
 StringUtils.substringBefore("abc", "")    = ""
 StringUtils.substringBefore("abc", null)  = "abc"
 

Parameters:
str - the String to get a substring from, may be null
separator - the String to search for, may be null
Returns:
the substring before the first occurrence of the separator, null if null String input
Since:
2.0

substringAfter

public static java.lang.String substringAfter(java.lang.String str,
                                              java.lang.String separator)

Gets the substring after the first occurrence of a separator. The separator is not returned.

A null string input will return null. An empty ("") string input will return the empty string. A null separator will return the empty string if the input string is not null.

 StringUtils.substringAfter(null, *)      = null
 StringUtils.substringAfter("", *)        = ""
 StringUtils.substringAfter(*, null)      = ""
 StringUtils.substringAfter("abc", "a")   = "bc"
 StringUtils.substringAfter("abcba", "b") = "cba"
 StringUtils.substringAfter("abc", "c")   = ""
 StringUtils.substringAfter("abc", "d")   = ""
 StringUtils.substringAfter("abc", "")    = "abc"
 

Parameters:
str - the String to get a substring from, may be null
separator - the String to search for, may be null
Returns:
the substring after the first occurrence of the separator, null if null String input
Since:
2.0

substringBeforeLast

public static java.lang.String substringBeforeLast(java.lang.String str,
                                                   java.lang.String separator)

Gets the substring before the last occurrence of a separator. The separator is not returned.

A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the input string.

 StringUtils.substringBeforeLast(null, *)      = null
 StringUtils.substringBeforeLast("", *)        = ""
 StringUtils.substringBeforeLast("abcba", "b") = "abc"
 StringUtils.substringBeforeLast("abc", "c")   = "ab"
 StringUtils.substringBeforeLast("a", "a")     = ""
 StringUtils.substringBeforeLast("a", "z")     = "a"
 StringUtils.substringBeforeLast("a", null)    = "a"
 StringUtils.substringBeforeLast("a", "")      = "a"
 

Parameters:
str - the String to get a substring from, may be null
separator - the String to search for, may be null
Returns:
the substring before the last occurrence of the separator, null if null String input
Since:
2.0

substringAfterLast

public static java.lang.String substringAfterLast(java.lang.String str,
                                                  java.lang.String separator)

Gets the substring after the last occurrence of a separator. The separator is not returned.

A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the empty string if the input string is not null.

 StringUtils.substringAfterLast(null, *)      = null
 StringUtils.substringAfterLast("", *)        = ""
 StringUtils.substringAfterLast(*, "")        = ""
 StringUtils.substringAfterLast(*, null)      = ""
 StringUtils.substringAfterLast("abc", "a")   = "bc"
 StringUtils.substringAfterLast("abcba", "b") = "a"
 StringUtils.substringAfterLast("abc", "c")   = ""
 StringUtils.substringAfterLast("a", "a")     = ""
 StringUtils.substringAfterLast("a", "z")     = ""
 

Parameters:
str - the String to get a substring from, may be null
separator - the String to search for, may be null
Returns:
the substring after the last occurrence of the separator, null if null String input
Since:
2.0

argMapInteger

public static java.lang.Integer argMapInteger(java.util.Map<java.lang.String,java.lang.String> argMap,
                                              java.util.Map<java.lang.String,java.lang.String> argMapNotUsed,
                                              java.lang.String key,
                                              boolean required,
                                              java.lang.Integer defaultValue)
get the value from the argMap, throw exception if not there and required

Parameters:
argMap -
argMapNotUsed -
key -
required -
defaultValue -
Returns:
the value or null or exception

toSqlDate

public static java.sql.Date toSqlDate(java.util.Date date)
null safe convert from util date to sql date

Parameters:
date -
Returns:
the sql date

indexOf

public static int indexOf(java.lang.Object[] array,
                          java.lang.Object objectToFind)

Find the index of the given object in the array.

This method returns -1 if null array input.

Parameters:
array - the array to search through for the object, may be null
objectToFind - the object to find, may be null
Returns:
the index of the object within the array, -1 if not found or null array input

contains

public static boolean contains(java.lang.Object[] array,
                               java.lang.Object objectToFind)

Checks if the object is in the given array.

The method returns false if a null array is passed in.

Parameters:
array - the array to search through
objectToFind - the object to find
Returns:
true if the array contains the object

indexOf

public static int indexOf(java.lang.Object[] array,
                          java.lang.Object objectToFind,
                          int startIndex)

Find the index of the given object in the array starting at the given index.

This method returns -1 if null array input.

A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.

Parameters:
array - the array to search through for the object, may be null
objectToFind - the object to find, may be null
startIndex - the index to start searching at
Returns:
the index of the object within the array starting at the index, -1 if not found or null array input

dateToString

public static java.lang.String dateToString(java.util.Date date)
convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23

Parameters:
date -
Returns:
the string, or null if the date is null

stringToDate

public static java.util.Date stringToDate(java.lang.String dateString)
convert a string to a date using the standard web service pattern Note that HH is 0-23

Parameters:
dateString -
Returns:
the string, or null if the date was null

stringToDate2

public static java.util.Date stringToDate2(java.lang.String input)
take as input: yyyy/mm/dd yyyy-mm-dd dd-mon-yyyy yyyy/mm/dd hh:mm:ss dd-mon-yyyy hh:mm:ss yyyy/mm/dd hh:mm:ss.SSS dd-mon-yyyy hh:mm:ss.SSS

Parameters:
input -
Returns:
the date

monthInt

public static int monthInt(java.lang.String mon)
convert a month string to an int (1 indexed). e.g. if input is feb or Feb or february or February return 2

Parameters:
mon -
Returns:
the month

propertiesThreadLocalOverrideMap

public static java.util.Map<java.lang.String,java.lang.String> propertiesThreadLocalOverrideMap(java.lang.String propertiesFileName)
override map for properties in thread local to be used in a web server or the like, based on property file name

Parameters:
propertiesFileName -
Returns:
the override map

execCommand

public static void execCommand(java.lang.String command)
This will execute a command, and split spaces for args (might not be what you want if you are using quotes)

Parameters:
command -

execCommand

public static GrouperClientCommonUtils.CommandResult execCommand(java.lang.String[] arguments)
This will execute a command (with args). In this method, 
 if the exit code of the command is not zero, an exception will be thrown.
 Example call: execCommand(new String[]{"/bin/bash", "-c", "cd /someFolder; runSomeScript.sh"}, true);
 

Parameters:
arguments - are the commands
Returns:
the output text of the command.

retrieveExecutorService

public static java.util.concurrent.ExecutorService retrieveExecutorService()
Returns:
executor service

execCommand

public static GrouperClientCommonUtils.CommandResult execCommand(java.lang.String[] arguments,
                                                                 boolean exceptionOnExitValueNeZero)
This will execute a command (with args). Under normal operation, 
 if the exit code of the command is not zero, an exception will be thrown.
 If the parameter exceptionOnExitValueNeZero is set to true, the 
 results of the call will be returned regardless of the exit status.
 Example call: execCommand(new String[]{"/bin/bash", "-c", "cd /someFolder; runSomeScript.sh"}, true);
 

Parameters:
arguments - are the commands
exceptionOnExitValueNeZero - if this is set to false, the results of the call will be returned regardless of the exit status
Returns:
the output text of the command, and the error and return code if exceptionOnExitValueNeZero is false.

serializeObjectToFile

public static void serializeObjectToFile(java.io.Serializable object,
                                         java.io.File file)
serialize an object to a file (create parent dir if necessary)

Parameters:
object -
file -

unserializeObjectFromFile

public static java.io.Serializable unserializeObjectFromFile(java.io.File file,
                                                             boolean nullIfException,
                                                             boolean deleteFileOnException)
unserialize an object from a file if it exists

Parameters:
file -
nullIfException - true if null should be returned instead of exception
deleteFileOnException - true if file should be deleted on exception
Returns:
the object or null

deleteCreateFile

public static void deleteCreateFile(java.io.File file)
delete and create a new file. If its a directory, delete, and create a new dir.

Parameters:
file - is the file to delete and create

deleteFile

public static void deleteFile(java.io.File file)
Delete a file, throw exception if cannot

Parameters:
file -

copy

public static void copy(java.io.File fromFile,
                        java.io.File toFile)
copy a file to a new file

Parameters:
fromFile -
toFile -

renameTo

public static void renameTo(java.io.File fromFile,
                            java.io.File toFile)
rename a file to another file and throw runtime exception if not ok

Parameters:
fromFile -
toFile -

deleteRecursiveDirectory

public static void deleteRecursiveDirectory(java.lang.String dirName)
clear out all files recursively in a directory, including the directory itself

Parameters:
dirName -
Throws:
java.lang.RuntimeException - when something goes wrong

absolutePath

public static java.lang.String absolutePath(java.io.File file)
absolute path null safe

Parameters:
file -
Returns:
absolute path null safe

fileOrClasspathInputstream

public static java.io.InputStream fileOrClasspathInputstream(java.lang.String typeAndLocation,
                                                             java.lang.String logHint)
file or classpath location

Parameters:
typeAndLocation -
Returns:
the inputstream