Class SubjectApiUtils

java.lang.Object
edu.internet2.middleware.subject.util.SubjectApiUtils

public class SubjectApiUtils extends Object
utility methods for subject api
  • Constructor Details

    • SubjectApiUtils

      public SubjectApiUtils()
  • Method Details

    • subjectToString

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

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

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

      public static String convertUrlToDriverClassIfNeeded(String connectionUrl, String driverClassName)
      if there is no driver class specified, then try to derive it from the URL
      Parameters:
      connectionUrl -
      driverClassName -
      Returns:
      the driver class
    • isHsql

      public static boolean isHsql(String connectionUrl)
      see if the config file seems to be hsql
      Parameters:
      connectionUrl - url to check against
      Returns:
      see if hsql
    • isMysql

      public static boolean isMysql(String connectionUrl)
      see if the config file seems to be mysql
      Parameters:
      connectionUrl -
      Returns:
      see if mysql
    • isOracle

      public static boolean isOracle(String connectionUrl)
      see if the config file seems to be oracle
      Parameters:
      connectionUrl -
      Returns:
      see if oracle
    • isPostgres

      public static boolean isPostgres(String connectionUrl)
      see if the config file seems to be postgres
      Parameters:
      connectionUrl -
      Returns:
      see if postgres
    • isSQLServer

      public static boolean isSQLServer(String connectionUrl)
      see if the config file seems to be sql server
      Parameters:
      connectionUrl -
      Returns:
      see if sql server
    • 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
    • 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
    • convertToInClauseForSqlStatic

      public static String convertToInClauseForSqlStatic(Collection<String> collection)
      convert a collection of strings (no parens) to an in clause
      Parameters:
      collection -
      Returns:
      the string of in clause (without parens)
    • 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