Package repast.simphony.util
Class ContextUtils
java.lang.Object
repast.simphony.util.ContextUtils
Utility functions for working with contexts.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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.static Context
getContext
(Object o) Retrieves the context a given object is in.static Context
getContext
(Context<?> startingContext, Object o) Retrieves the context of the specified object starting with the specified Context.static Context
getParentContext
(Context context) Starting with the master context, search for and return the parent context of the specified context.static Context
getParentContext
(Context startingContext, Context context) Starting with the specified starting context, search for and return the parent context of the specified context.
-
Constructor Details
-
ContextUtils
public ContextUtils()
-
-
Method Details
-
findContext
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
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 asContextUtils.getContext(RunState.getInstance().getMasterContext(), o)
- Parameters:
o
- an object to find in the contexts- Returns:
- the context that contains the object
-
getContext
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 ato
- an object to find in the contexts- Returns:
- the context that contains the object
-
getParentContext
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
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.
-