Package htsjdk.utils

Class ValidationUtils


  • public class ValidationUtils
    extends Object
    Simple functions that streamline the checking of values.
    • Constructor Detail

      • ValidationUtils

        public ValidationUtils()
    • Method Detail

      • nonNull

        public static <T> T nonNull​(T object)
        Checks that an Object object is not null and returns the same object or throws an IllegalArgumentException
        Parameters:
        object - any Object
        Returns:
        the same object
        Throws:
        IllegalArgumentException - if a o == null
      • nonNull

        public static <T> T nonNull​(T object,
                                    String nameOfObject)
        Checks that an Object is not null and returns the same object or throws an IllegalArgumentException
        Parameters:
        object - any Object
        nameOfObject - the name of the object that is being checked for null. ( is used in the exception thrown when o == null.)
        Returns:
        the same object
        Throws:
        IllegalArgumentException - if a o == null
      • nonNull

        public static <T> T nonNull​(T object,
                                    Supplier<String> message)
        Checks that an Object is not null and returns the same object or throws an IllegalArgumentException
        Parameters:
        object - any Object
        message - the text message that would be passed to the exception thrown when o == null.
        Returns:
        the same object
        Throws:
        IllegalArgumentException - if a o == null
      • nonEmpty

        public static <T extends Collection<?>> T nonEmpty​(T collection,
                                                           String nameOfObject)
        Checks that a Collection is not null and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws an IllegalArgumentException
        Parameters:
        collection - any Collection
        nameOfObject - the name of the object that is being checked for non-emptiness. ( is used in the exception thrown when o.isEmpty().)
        Returns:
        the original collection
        Throws:
        IllegalArgumentException - if collection is null or empty
      • isNonEmpty

        public static boolean isNonEmpty​(Collection<?> collection)
        Checks that a Collection is not null and that it is not empty. If it's non-null and non-empty it returns the true
        Parameters:
        collection - any Collection
        Returns:
        true if the collection exists and has elements
      • nonEmpty

        public static String nonEmpty​(String string,
                                      String nameOfObject)
        Checks that a String is not null and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws an IllegalArgumentException
        Parameters:
        string - any String
        nameOfObject - a message to include in the output
        Returns:
        the original string
        Throws:
        IllegalArgumentException - if string is null or empty
      • nonEmpty

        public static String nonEmpty​(String string)
        Checks that a String is not null and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws an IllegalArgumentException
        Parameters:
        string - any String
        Returns:
        the original string
        Throws:
        IllegalArgumentException - if string is null or empty
      • nonEmpty

        public static <I,​T extends Collection<I>> T nonEmpty​(T collection)
        Checks that a Collection is not null and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws an IllegalArgumentException
        Parameters:
        collection - any Collection
        Returns:
        the original collection
        Throws:
        IllegalArgumentException - if collection is null or empty
      • validateArg

        public static void validateArg​(boolean condition,
                                       String msg)
      • validateArg

        public static void validateArg​(boolean condition,
                                       Supplier<String> msg)