Interface Context

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default <T extends Context>
      Optional<T>
      as​(Class<T> clazz)
      Returns an @{link Optional} which contains the first context in the chain whose type is a sub-type of the provided Context class if one exists, or an empty optional if none is present.
      <T extends Context>
      T
      asContext​(Class<T> clazz)
      Returns the first context in the chain whose type is a sub-type of the provided Context class.
      boolean containsContext​(Class<? extends Context> clazz)
      Returns true if there is a context in the chain whose type is a sub-type of the provided Context class.
      boolean containsContext​(String contextName)
      Returns true if there is a context in the chain whose name matches the provided context name.
      default Optional<Context> get​(String contextName)
      Returns an Optional containing the first context in the chain whose context name matches the provided name, or an empty Optional if none is present.
      Context getContext​(String contextName)
      Returns the first context in the chain whose context name matches the provided name.
      String getContextName()
      Get this Context's name.
      String getId()
      Returns the unique ID identifying this context, usually a UUID.
      Context getParent()
      Returns the parent of this context.
      String getRootId()
      Returns the unique ID of the root context, usually a UUID.
      boolean isRootContext()
      Returns true if this context is a root context.
      JsonValue toJsonValue()
      Return this Context as a JsonValue (for persistence).
    • Method Detail

      • getContextName

        String getContextName()
        Get this Context's name.
        Returns:
        this object's name
      • asContext

        <T extends Context> T asContext​(Class<T> clazz)
        Returns the first context in the chain whose type is a sub-type of the provided Context class. The method first checks this context to see if it has the required type, before proceeding to the parent context, and then continuing up the chain of parents until the root context is reached.
        Type Parameters:
        T - The context type.
        Parameters:
        clazz - The class of context to be returned.
        Returns:
        The first context in the chain whose type is a sub-type of the provided Context class.
        Throws:
        IllegalArgumentException - If no matching context was found in this context's parent chain.
      • as

        default <T extends ContextOptional<T> as​(Class<T> clazz)
        Returns an @{link Optional} which contains the first context in the chain whose type is a sub-type of the provided Context class if one exists, or an empty optional if none is present. The method first checks this context to see if it has the required type, before proceeding to the parent context, and then continuing up the chain of parents until the root context is reached.
        Type Parameters:
        T - The context type.
        Parameters:
        clazz - The class of context to be returned.
        Returns:
        An Optional containing the first context in the chain whose type is a sub-type of the provided Context class, or an empty optional if no such Context exists in the chain.
      • getContext

        Context getContext​(String contextName)
        Returns the first context in the chain whose context name matches the provided name.
        Parameters:
        contextName - The name of the context to be returned.
        Returns:
        The first context in the chain whose name matches the provided context name.
        Throws:
        IllegalArgumentException - If no matching context was found in this context's parent chain.
      • get

        default Optional<Context> get​(String contextName)
        Returns an Optional containing the first context in the chain whose context name matches the provided name, or an empty Optional if none is present.
        Parameters:
        contextName - The name of the context to be returned.
        Returns:
        An Optional containing the first context in the chain whose name matches the provided context name, an empty optional if none is present.
      • containsContext

        boolean containsContext​(Class<? extends Context> clazz)
        Returns true if there is a context in the chain whose type is a sub-type of the provided Context class. The method first checks this context to see if it has the required type, before proceeding to the parent context, and then continuing up the chain of parents until the root context is reached.
        Parameters:
        clazz - The class of context to be checked.
        Returns:
        true if there is a context in the chain whose type is a sub-type of the provided Context class.
      • containsContext

        boolean containsContext​(String contextName)
        Returns true if there is a context in the chain whose name matches the provided context name.
        Parameters:
        contextName - The name of the context to locate.
        Returns:
        true if there is a context in the chain whose context name matches contextName.
      • getId

        String getId()
        Returns the unique ID identifying this context, usually a UUID. If no ID has been defined then the ID of the parent context will be returned.
        Returns:
        The unique ID identifying this context. If no ID has been defined then the ID of the parent context will be returned.
      • getRootId

        String getRootId()
        Returns the unique ID of the root context, usually a UUID.
        Returns:
        The unique ID of the root context.
      • getParent

        Context getParent()
        Returns the parent of this context.
        Returns:
        The parent of this context, or null if this context is a root context.
      • isRootContext

        boolean isRootContext()
        Returns true if this context is a root context.
        Returns:
        true if this context is a root context.
      • toJsonValue

        JsonValue toJsonValue()
        Return this Context as a JsonValue (for persistence).
        Returns:
        the Context data as a JsonValue.