Interface IContext

All Known Implementing Classes:
Context, GuiceContext

public interface IContext
A context supplies values associated with keys; keys are instances of Property or Class.

Context implementations may use an identity-based lookup, name-based lookup, or anything in-between. For portability, keys need to be unique instances with unique names.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    containsKey(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(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.
    default <T> T
    getOrDefault(Property<T> property)
    Returns the context value associated with the given property; if no value is associated with the given property, returns the default value of the property.
  • Method Details

    • get

      <T> T get(Property<T> property)
      Returns the context value associated with the given property.
      Parameters:
      property - the property being queried (not null)
      Returns:
      an object corresponding to the given property, or null
    • getOrDefault

      default <T> T getOrDefault(Property<T> property)
      Returns the context value associated with the given property; if no value is associated with the given property, returns the default value of the property.

      This implementation makes no guarantees about synchronization or atomicity.

      Parameters:
      property - the property being queried (not null)
      Returns:
      an object corresponding to the given property, or the property's default value (may be null)
      See Also:
    • get

      <T> T get(Class<T> clazz)
      Returns the context value associated with the given class.
      Parameters:
      clazz - the class being queried (not null)
      Returns:
      an object corresponding to the given class, or null
    • containsKey

      boolean containsKey(Property<?> property)
      Returns whether this context has a value associated with the given property.
      Parameters:
      property - the property being queried (not null)
      Returns:
      true if this context has a value for the given property, and false otherwise
    • containsKey

      boolean containsKey(Class<?> clazz)
      Returns whether this context has a value associated with the given class.
      Parameters:
      clazz - the class being queried (not null)
      Returns:
      true if this context has a value for the given class, and false otherwise