Class GuiceContext

  • All Implemented Interfaces:
    IContext

    public final class GuiceContext
    extends java.lang.Object
    implements IContext
    Implementation of IContext backed by a Guice injector.

    A property is translated into an injection Key in the following way:

    Key.get(property.getType(), Names.named(property.getName()))
    • Constructor Summary

      Constructors 
      Constructor Description
      GuiceContext​(com.google.inject.Injector injector)
      Constructs a context backed by the given Guice injector.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.lang.Class<?> clazz)
      Returns whether this context has a value associated with the given class.
      boolean containsKey​(Property<?> property)
      Returns whether this context has a value associated with the given property.
      <T> T get​(java.lang.Class<T> clazz)
      Returns the context value associated with the given class.
      <T> T get​(Property<T> property)
      Returns the context value associated with the given property.
      • Methods inherited from class java.lang.Object

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

      • GuiceContext

        @Inject
        public GuiceContext​(com.google.inject.Injector injector)
        Constructs a context backed by the given Guice injector.
        Parameters:
        injector - a Guice injector (not null)
    • Method Detail

      • get

        public <T> T get​(Property<T> property)
        Description copied from interface: IContext
        Returns the context value associated with the given property.
        Specified by:
        get in interface IContext
        Parameters:
        property - the property being queried (not null)
        Returns:
        an object corresponding to the given property, or null
      • get

        public <T> T get​(java.lang.Class<T> clazz)
        Description copied from interface: IContext
        Returns the context value associated with the given class.
        Specified by:
        get in interface IContext
        Parameters:
        clazz - the class being queried (not null)
        Returns:
        an object corresponding to the given class, or null
      • containsKey

        public boolean containsKey​(Property<?> property)
        Description copied from interface: IContext
        Returns whether this context has a value associated with the given property.
        Specified by:
        containsKey in interface IContext
        Parameters:
        property - the property being queried (not null)
        Returns:
        true if this context has a value for the given property, and false otherwise
      • containsKey

        public boolean containsKey​(java.lang.Class<?> clazz)
        Description copied from interface: IContext
        Returns whether this context has a value associated with the given class.
        Specified by:
        containsKey in interface IContext
        Parameters:
        clazz - the class being queried (not null)
        Returns:
        true if this context has a value for the given class, and false otherwise