Class CheckedProviders

java.lang.Object
com.google.inject.throwingproviders.CheckedProviders

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

    • CheckedProviders

      private CheckedProviders()
  • Method Details

    • generateProvider

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

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

      private static com.google.common.base.Optional<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(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:
      • invalid reference
        #of(TypeLiteral, T)
    • throwing

      public static <T, P extends CheckedProvider<? super T>> P throwing(TypeLiteral<P> providerType, Class<? extends 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

      invalid reference
      #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:
      • invalid reference
        #of(TypeLiteral, T)
    • throwing

      public static <T, P extends CheckedProvider<? super T>> P throwing(Class<P> providerType, Class<? extends 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:
    • isCheckedException

      private static boolean isCheckedException(Class<? extends Throwable> thrownType)
    • checkThrowable

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