Class SubjectUtils

java.lang.Object
edu.internet2.middleware.subject.SubjectUtils

public class SubjectUtils extends Object
  • Field Details

    • DATE_FORMAT

      public static final String DATE_FORMAT
      string format of dates
      See Also:
    • DATE_MINUTES_SECONDS_FORMAT

      public static final String DATE_MINUTES_SECONDS_FORMAT
      format including minutes and seconds: yyyy/MM/dd HH:mm:ss
      See Also:
    • DATE_MINUTES_SECONDS_NO_SLASH_FORMAT

      public static final String DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
      format including minutes and seconds: yyyyMMdd HH:mm:ss
      See Also:
    • TIMESTAMP_FORMAT

      public static final String TIMESTAMP_FORMAT
      format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSS
      See Also:
    • TIMESTAMP_NO_SLASH_FORMAT

      public static final String TIMESTAMP_NO_SLASH_FORMAT
      format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS
      See Also:
    • NOT_FOUND

      public static final int NOT_FOUND
      special number when a number is not found
      See Also:
    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      The name says it all.
      See Also:
    • EMPTY_STRING_ARRAY

      public static final String[] EMPTY_STRING_ARRAY
      An empty immutable String array.
  • Constructor Details

    • SubjectUtils

      public SubjectUtils()
  • Method Details

    • enumValueOfIgnoreCase

      public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound) throws 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:
      RuntimeException - if there is a problem
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(String str1, String str2)
      equalsignorecase
      Parameters:
      str1 -
      str2 -
      Returns:
      true if the strings are equal ignore case
    • splitTrim

      public static String[] splitTrim(String input, 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
    • splitTrimToSet

      public static Set<String> splitTrimToSet(String input, 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 set of items after split and trimmed, or null if input is null. will be trimmed to empty
    • splitTrim

      public static String[] splitTrim(String input, 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
    • splitByWholeSeparator

      public static String[] splitByWholeSeparator(String str, 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 String[] splitByWholeSeparator(String str, 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
    • enumValueOfIgnoreCase

      public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound, boolean exceptionIfInvalid) throws 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
      exceptionIfInvalid - if there is a string, but it is invalid, if should throw exception
      Returns:
      the enum or null or exception if not found
      Throws:
      RuntimeException - if there is a problem
    • injectInException

      public static boolean injectInException(Throwable t, String message)
      If we can, inject this into the exception, else return false
      Parameters:
      t -
      message -
      Returns:
      true if success, false if not
    • assignField

      public static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, boolean callOnSupers, boolean overrideSecurity, boolean typeCast, Class<? extends 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(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, Class<? extends 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(Field field, Object invokeOn, 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
    • assignField

      public static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast, Class<? extends 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(Object invokeOn, String fieldName, 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 Field field(Class theClass, 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)
    • typeCast

      public static <T> T typeCast(Object value, 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
    • typeCast

      public static <T> T typeCast(Object value, 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
    • dateValue

      public static Date dateValue(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(Object input)
      See if the input is null or if string, if it is empty or blank (whitespace)
      Parameters:
      input -
      Returns:
      true if blank
    • intObjectValue

      public static Integer intObjectValue(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(Object input)
      convert an object to a int
      Parameters:
      input -
      Returns:
      the number
    • intValue

      public static int intValue(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(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
    • stringValue

      public static String stringValue(Date date)
      convert a date to the standard string yyyymmdd
      Parameters:
      date -
      Returns:
      the string value
    • stringValue

      public static String stringValue(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 String timestampToString(Date timestamp)
      Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS
      Parameters:
      timestamp -
      Returns:
      the string representation
    • toString

      public static String toString(InputStream input, String encoding) throws 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:
      IOException - In case of an I/O problem
    • toTimestamp

      public static Timestamp toTimestamp(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:
      RuntimeException - if invalid format
    • className

      public static String className(Object object)
      null safe classname method, gets the unenhanced name
      Parameters:
      object -
      Returns:
      the classname
    • classNameCollection

      public static String classNameCollection(Object object)
      null safe classname method, max out at 20
      Parameters:
      object -
      Returns:
      the classname
    • bigDecimalObjectValue

      public static BigDecimal bigDecimalObjectValue(Object input)
      Convert an object to a byte, allow nulls
      Parameters:
      input -
      Returns:
      the boolean object value
    • booleanObjectValue

      public static Boolean booleanObjectValue(Object object)
      get the Boolean value for an object
      Parameters:
      object -
      Returns:
      the Boolean or null if null or empty
    • booleanValue

      public static boolean booleanValue(Object object)
      get the boolean value for an object, cant be null or blank
      Parameters:
      object -
      Returns:
      the boolean
    • booleanValue

      public static boolean booleanValue(Object object, boolean defaultBoolean)
      get the boolean value for an object
      Parameters:
      object -
      defaultBoolean - if object is null or empty
      Returns:
      the boolean
    • byteObjectValue

      public static Byte byteObjectValue(Object input)
      Convert an object to a byte, allow nulls
      Parameters:
      input -
      Returns:
      the boolean object value
    • byteValue

      public static byte byteValue(Object input)
      convert an object to a byte
      Parameters:
      input -
      Returns:
      the byte
    • charObjectValue

      public static Character charObjectValue(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(Object input)
      convert an object to a char
      Parameters:
      input -
      Returns:
      the number
    • doubleObjectValue

      public static Double doubleObjectValue(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(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(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 Float floatObjectValue(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(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(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
    • longObjectValue

      public static Long longObjectValue(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(Object input)
      convert an object to a long
      Parameters:
      input -
      Returns:
      the number
    • longValue

      public static long longValue(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(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 Short shortObjectValue(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(Object input)
      convert an object to a short
      Parameters:
      input -
      Returns:
      the number
    • forName

      public static Class forName(String origClassName)
      Returns the class object.
      Parameters:
      origClassName - is fully qualified
      Returns:
      the class
    • newInstance

      public static <T> T newInstance(Class<T> theClass)
      Construct a class
      Type Parameters:
      T - template type
      Parameters:
      theClass -
      Returns:
      the instance
    • toStringForLog

      public static String toStringForLog(Object object)
      print out various types of objects
      Parameters:
      object -
      Returns:
      the string value
    • toStringForLog

      public static String toStringForLog(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
    • copy

      public static int copy(Reader input, Writer output) throws 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:
      IOException - In case of an I/O problem
    • copy

      public static void copy(InputStream input, Writer output, String encoding) throws 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:
      IOException - In case of an I/O problem
    • stringToTimestamp

      public static Timestamp stringToTimestamp(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
    • iterator

      public static Iterator iterator(Object collection)
      null safe iterator getter if the type if collection
      Parameters:
      collection -
      Returns:
      the iterator
    • length

      public static int length(Object arrayOrCollection)
      Null safe array length or map
      Parameters:
      arrayOrCollection -
      Returns:
      the length of the array (0 for null)
    • next

      public static Object next(Object arrayOrCollection, 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
    • nullOrBlank

      public static boolean nullOrBlank(Object object)
      is an object null or blank
      Parameters:
      object -
      Returns:
      true if null or blank
    • 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
    • defaultIfBlank

      public static String defaultIfBlank(String string, String defaultStringIfBlank)
      return the string or the other if the first is blank
      Parameters:
      string -
      defaultStringIfBlank -
      Returns:
      the string or the default one
    • propertiesFromResourceName

      public static Properties propertiesFromResourceName(String resourceName)
      read properties from a resource, dont modify the properties returned since they are cached
      Parameters:
      resourceName -
      Returns:
      the properties
    • computeUrl

      public static URL computeUrl(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 ClassLoader classLoader()
      fast class loader
      Returns:
      the class loader
    • closeQuietly

      public static void closeQuietly(Connection connection)
      close a connection null safe and dont throw exception
      Parameters:
      connection -
    • closeQuietly

      public static void closeQuietly(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(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(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(ResultSet resultSet)
      close a resultSet null safe and dont throw exception
      Parameters:
      resultSet -
    • closeQuietly

      public static void closeQuietly(Statement statement)
      close a statement null safe and dont throw exception
      Parameters:
      statement -
    • closeQuietly

      public static void closeQuietly(Writer writer)
      close a writer quietly
      Parameters:
      writer -
    • fileFromResourceName

      @Deprecated public static File fileFromResourceName(String resourceName)
      Deprecated.
      get a file name from a resource name
      Parameters:
      resourceName - is the classpath location
      Returns:
      the file path on the system
    • getLocationFromResourceName

      public static String getLocationFromResourceName(String resourceName)
      get a file name from a resource name
      Parameters:
      resourceName - is the classpath location
      Returns:
      Full path to the resource. For files, the file path on the system; otherwise, the resource URL
    • fileCanonicalPath

      public static String fileCanonicalPath(File file)
      get canonical path of file
      Parameters:
      file -
      Returns:
      the path
    • substituteExpressionLanguage

      public static String substituteExpressionLanguage(String stringToParse, Map<String,Object> variableMap)
      substitute an EL for objects
      Parameters:
      stringToParse -
      variableMap -
      Returns:
      the string
    • substituteExpressionLanguage

      public static String substituteExpressionLanguage(String stringToParse, Map<String,Object> variableMap, boolean lenient)
      substitute an EL for objects
      Parameters:
      stringToParse -
      variableMap -
      lenient -
      Returns:
      the string
    • assertion

      public static void assertion(boolean isTrue, String reason)
      If false, throw an assertException, and give a reason
      Parameters:
      isTrue -
      reason -
    • split

      public static String[] split(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 String[] split(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 String[] split(String str, 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 String[] split(String str, 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
    • trim

      public static String trim(String str)
      trim whitespace from string
      Parameters:
      str -
      Returns:
      trimmed string
    • toSet

      public static <M> Set<M> toSet(M... inputs)
      convert an element to a set
      Type Parameters:
      M -
      Parameters:
      m -
      Returns:
    • batchNumberOfBatches

      public static int batchNumberOfBatches(int count, int batchSize, boolean haveAtLeastOne)
      If batching this is the number of batches
      Parameters:
      count - is size of set
      batchSize -
      haveAtLeastOne - is true if there should be at least one run even if the collection is empty (e.g. for queries based on other things)
      Returns:
      the number of batches
    • batchNumberOfBatches

      @Deprecated public static int batchNumberOfBatches(int count, int batchSize)
      Deprecated.
      use batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)
      If batching this is the number of batches. Will return at least 1
      Parameters:
      count - is size of set
      batchSize -
      Returns:
      the number of batches
    • batchNumberOfBatches

      @Deprecated public static int batchNumberOfBatches(Collection<?> collection, int batchSize)
      Deprecated.
      use batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)
      If batching this is the number of batches, will return at least 1
      Parameters:
      collection -
      batchSize -
      Returns:
      the number of batches
    • batchNumberOfBatches

      public static int batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)
      If batching this is the number of batches, will return at least 1
      Parameters:
      collection -
      batchSize -
      haveAtLeastOne - is true if there should be at least one run even if the collection is empty (e.g. for queries based on other things)
      Returns:
      the number of batches
    • batchList

      public static <T> List<T> batchList(List<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
    • mapToString

      public static String mapToString(Map map)
      convert a set to a string (comma separate)
      Parameters:
      map -
      Returns:
      the String
    • propertiesToString

      public static String propertiesToString(Properties properties)
      convert properties to a string (comma separate)
      Parameters:
      properties -
      Returns:
      the String
    • toList

      public static <T> 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
    • subjectToString

      public static String subjectToString(Subject subject)
      convert a subject to string safely
      Parameters:
      subject -
      Returns:
      the string value of subject (might be null)
    • listFromCollection

      public static <T> List<T> listFromCollection(Collection<T> collection)
      null safe convert collection to list
      Type Parameters:
      T -
      Parameters:
      collection -
      Returns:
      the list
    • nonNull

      public static <T> Collection<T> nonNull(Collection<T> list)
      make sure a collection 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> List<T> nonNull(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 <K, V> Map<K,V> nonNull(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
    • nonNull

      public static <T> Set<T> nonNull(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 <T> T[] nonNull(T[] array, Class<?> theClass)
      make sure a array is non null. If null, then return an empty array.
      Type Parameters:
      T -
      Parameters:
      array -
      theClass - to make array from
      Returns:
      the list or empty list if null
    • compare

      public static int compare(Comparable first, Comparable second)
      compare null safe
      Parameters:
      first -
      second -
      Returns:
      0 for equal, 1 for greater, -1 for less