Class PreconditionsUtils


  • public class PreconditionsUtils
    extends java.lang.Object
    Utility methods related to preconditions checking.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T checkArgumentNotNull​(T reference)
      Checks whether the provided reference is null, throws IAE if it is, and returns it if not.
      static <T> T checkArgumentNotNull​(T reference, java.lang.Object errorMessage)
      Checks whether the provided reference is null, throws IAE if it is, and returns it if not.
      static <T> T checkArgumentNotNull​(T reference, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
      Checks whether the provided reference is null, throws IAE if it is, and returns it if not.
      static <T> T checkArgumentPresent​(java.util.Optional<T> reference)
      Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
      static <T> T checkArgumentPresent​(java.util.Optional<T> reference, java.lang.Object errorMessage)
      Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
      static <T> T checkArgumentPresent​(java.util.Optional<T> reference, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
      Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PreconditionsUtils

        public PreconditionsUtils()
    • Method Detail

      • checkArgumentNotNull

        public static <T> T checkArgumentNotNull​(@Nullable
                                                 T reference)
        Checks whether the provided reference is null, throws IAE if it is, and returns it if not.

        This method and its overloads are to substitute for checkNotNull() in cases where it's preferable to throw an IAE instead of an NPE, such as where we want an IAE to indicate that it's just a bad argument/parameter and reserve NPEs for bugs and unexpected null values.

      • checkArgumentNotNull

        public static <T> T checkArgumentNotNull​(@Nullable
                                                 T reference,
                                                 @Nullable
                                                 java.lang.Object errorMessage)
        Checks whether the provided reference is null, throws IAE if it is, and returns it if not.
      • checkArgumentNotNull

        public static <T> T checkArgumentNotNull​(@Nullable
                                                 T reference,
                                                 @Nullable
                                                 java.lang.String errorMessageTemplate,
                                                 @Nullable
                                                 java.lang.Object... errorMessageArgs)
        Checks whether the provided reference is null, throws IAE if it is, and returns it if not.
      • checkArgumentPresent

        public static <T> T checkArgumentPresent​(@Nullable
                                                 java.util.Optional<T> reference)
        Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
      • checkArgumentPresent

        public static <T> T checkArgumentPresent​(@Nullable
                                                 java.util.Optional<T> reference,
                                                 @Nullable
                                                 java.lang.Object errorMessage)
        Checks if the provided Optional is present, returns its value if so, and throws IAE if not.
      • checkArgumentPresent

        public static <T> T checkArgumentPresent​(@Nullable
                                                 java.util.Optional<T> reference,
                                                 @Nullable
                                                 java.lang.String errorMessageTemplate,
                                                 @Nullable
                                                 java.lang.Object... errorMessageArgs)
        Checks if the provided Optional is present, returns its value if so, and throws IAE if not.