Class RealOptionalBinder<T>

  • All Implemented Interfaces:
    Module

    public final class RealOptionalBinder<T>
    extends java.lang.Object
    implements Module
    The actual OptionalBinder plays several roles. It implements Module to hide that fact from the public API, and installs the various bindings that are exposed to the user.
    • Field Detail

      • JAVA_OPTIONAL_CLASS

        private static final java.lang.Class<?> JAVA_OPTIONAL_CLASS
      • JAVA_OPTIONAL_EMPTY

        private static final java.lang.Object JAVA_OPTIONAL_EMPTY
      • JAVA_OPTIONAL_OF_METHOD

        private static final java.lang.reflect.Method JAVA_OPTIONAL_OF_METHOD
      • binder

        private final Binder binder
    • Constructor Detail

      • RealOptionalBinder

        private RealOptionalBinder​(Binder binder,
                                   Key<T> typeKey)
    • Method Detail

      • invokeJavaOptionalOfNullable

        private static java.lang.Object invokeJavaOptionalOfNullable​(java.lang.Object o)
        Returns java.util.Optional.empty() if the parameter is null, calls invokeJavaOptionalOf(java.lang.Object) otherwise.
      • invokeJavaOptionalOf

        private static java.lang.Object invokeJavaOptionalOf​(java.lang.Object o)
        Invokes java.util.Optional.of.
      • optionalOf

        static <T> TypeLiteral<com.google.common.base.Optional<T>> optionalOf​(TypeLiteral<T> type)
      • optionalOfJavaxProvider

        static <T> TypeLiteral<com.google.common.base.Optional<javax.inject.Provider<T>>> optionalOfJavaxProvider​(TypeLiteral<T> type)
      • javaOptionalOfJavaxProvider

        static <T> TypeLiteral<?> javaOptionalOfJavaxProvider​(TypeLiteral<T> type)
      • providerOf

        static <T> Key<Provider<T>> providerOf​(Key<T> key)
      • addDirectTypeBinding

        private void addDirectTypeBinding​(Binder binder)
        Adds a binding for T. Multiple calls to this are safe, and will be collapsed as duplicate bindings.
      • getKeyForDefaultBinding

        Key<T> getKeyForDefaultBinding()
        Returns the key to use for the default binding.

        As a side effect this installs support for the 'direct type', so a binding for T will be made available.

      • getKeyForActualBinding

        Key<T> getKeyForActualBinding()
        Returns the key to use for the actual binding, overrides the default if set.

        As a side effect this installs support for the 'direct type', so a binding for T will be made available.

      • configure

        public void configure​(Binder binder)
        Description copied from interface: Module
        Contributes bindings and other configurations for this module to binder.

        Do not invoke this method directly to install submodules. Instead use Binder.install(Module), which ensures that provider methods are discovered.

        Specified by:
        configure in interface Module
      • bindJava8Optional

        private void bindJava8Optional​(Binder binder)
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object