Class ContextUtils


  • public class ContextUtils
    extends Object
    Utility functions for working with contexts.
    • Constructor Detail

      • ContextUtils

        public ContextUtils()
    • Method Detail

      • findContext

        public static <T> Context<? extends T> findContext​(Context<T> start,
                                                           Object id)
        This searches the specified context and its descendants for the context with the specified id. This searches through the contexts in a breadth-first manner, and will return the first context whose getId() method returns the specified id. This includes the start context.
        Parameters:
        start - the root context of the search tree (non-null)
        id - the id of the context to search for
        Returns:
        the first context found with the given id, or null if no context is found
      • getContext

        public static Context getContext​(Object o)
        Retrieves the context a given object is in. This will traverse the RunState's current master context. It then will traverse down the context's sub contexts until it finds the lowest level context the object is in.

        This is the same as ContextUtils.getContext(RunState.getInstance().getMasterContext(), o)

        Parameters:
        o - an object to find in the contexts
        Returns:
        the context that contains the object
      • getContext

        public static Context getContext​(Context<?> startingContext,
                                         Object o)
        Retrieves the context of the specified object starting with the specified Context. This will traverse into the specified context's sub contexts until it finds the lowest level context the object is in.
        Parameters:
        startingContext - the context to begin the search at
        o - an object to find in the contexts
        Returns:
        the context that contains the object
      • getParentContext

        public static Context getParentContext​(Context context)
        Starting with the master context, search for and return the parent context of the specified context.
        Parameters:
        context -
        Returns:
        the parent context of the specified context, or null if not found.
      • getParentContext

        public static Context getParentContext​(Context startingContext,
                                               Context context)
        Starting with the specified starting context, search for and return the parent context of the specified context.
        Parameters:
        startingContext -
        context -
        Returns:
        the parent context of the specified context, or null if not found.