Class CheckedProviders


  • public final class CheckedProviders
    extends java.lang.Object
    Static utility methods for creating and working with instances of CheckedProvider.
    Since:
    4.2
    • Constructor Detail

      • CheckedProviders

        private CheckedProviders()
    • Method Detail

      • generateProvider

        private static <T,​P extends CheckedProvider<? super T>> P generateProvider​(java.lang.Class<P> providerType,
                                                                                         com.google.common.base.Optional<T> value,
                                                                                         java.lang.reflect.InvocationHandler handler)
      • generateProvider

        private static <T,​P extends CheckedProvider<? super T>> P generateProvider​(TypeLiteral<P> providerType,
                                                                                         com.google.common.base.Optional<T> value,
                                                                                         java.lang.reflect.InvocationHandler handler)
      • getClassOptional

        private static com.google.common.base.Optional<java.lang.Class<?>> getClassOptional​(com.google.common.base.Optional<?> value)
      • of

        public static <T,​P extends CheckedProvider<? super T>> P of​(TypeLiteral<P> providerType,
                                                                          @Nullable
                                                                          T instance)
        Returns a CheckedProvider which always provides instance.

        The provider type passed as providerType must be an interface. Calls to methods other than CheckedProvider.get() will throw UnsupportedOperationException.

        Parameters:
        providerType - the type of the CheckedProvider to return
        instance - the instance that should always be provided
      • of

        public static <T,​P extends CheckedProvider<? super T>> P of​(java.lang.Class<P> providerType,
                                                                          @Nullable
                                                                          T instance)
        Returns a CheckedProvider which always provides instance.
        Parameters:
        providerType - the type of the CheckedProvider to return
        instance - the instance that should always be provided
        See Also:
        #of(TypeLiteral, T)
      • throwing

        public static <T,​P extends CheckedProvider<? super T>> P throwing​(TypeLiteral<P> providerType,
                                                                                java.lang.Class<? extends java.lang.Throwable> throwable)
        Returns a CheckedProvider which always throws exceptions.

        This method uses the nullary (no argument) constructor of throwable to create a new instance of the given Throwable on each method invocation which is then thrown immediately.

        See #of(TypeLiteral, T) for more information.

        Parameters:
        providerType - the type of the CheckedProvider to return
        throwable - the type of the Throwable to throw
        See Also:
        #of(TypeLiteral, T)
      • throwing

        public static <T,​P extends CheckedProvider<? super T>> P throwing​(java.lang.Class<P> providerType,
                                                                                java.lang.Class<? extends java.lang.Throwable> throwable)
        Returns a CheckedProvider which always throws exceptions.
        Parameters:
        providerType - the type of the CheckedProvider to return
        throwable - the type of the Throwable to throw
        See Also:
        throwing(TypeLiteral, Class)
      • isCheckedException

        private static boolean isCheckedException​(java.lang.Class<? extends java.lang.Throwable> thrownType)
      • checkThrowable

        private static void checkThrowable​(java.lang.Class<? extends CheckedProvider<?>> providerType,
                                           java.lang.Class<? extends java.lang.Throwable> thrownType)