Class AbstractContext<T>

    • Constructor Detail

      • AbstractContext

        public AbstractContext()
    • Method Detail

      • getTypeID

        public Object getTypeID()
        Gets an id that indentifies the user-defined type of this context. A context type typically refers to the role the context plays in a particular model. For example, the type of the context may be "School" and the agents in that context would be "Pupils".
        Specified by:
        getTypeID in interface Context<T>
        Returns:
        an id that indentifies the user-defined type of this context.
      • setTypeID

        public void setTypeID​(Object id)
        Sets an id that indentifies the user-defined type of this context. A context type typically refers to the role the context plays in a particular model. For example, the type of the context may be "School" and the agents in that context would be "Pupils".
        Specified by:
        setTypeID in interface Context<T>
        Parameters:
        id - the type id
      • query

        public Iterable<T> query​(org.apache.commons.collections15.Predicate query)
        Specified by:
        query in interface Context<T>
      • fireAddContextEvent

        protected void fireAddContextEvent​(T o)
        Parameters:
        o -
      • addInternal

        protected abstract boolean addInternal​(T o)
      • containsInternal

        protected abstract boolean containsInternal​(Object o)
      • iterator

        public Iterator<T> iterator()
        By default the iterator returns in the contents in this context in the order entered then it returns the contents of the subcontexts in the order the subcontexts were added.
        Specified by:
        iterator in interface Collection<T>
        Specified by:
        iterator in interface Iterable<T>
        Specified by:
        iterator in class AbstractCollection<T>
      • iteratorInternal

        protected abstract Iterator<T> iteratorInternal()
      • eventOccured

        public void eventOccured​(ContextEvent ev)
        Listener method for context events. This is primiarly used to receive ContextEvents from a subcontext and pass them on to this context's own listeners.
        Specified by:
        eventOccured in interface ContextListener<T>
        Parameters:
        ev -
      • hasSubContext

        public boolean hasSubContext()
        Description copied from interface: Context
        Method to check if subcontext(s) are present in the context
        Specified by:
        hasSubContext in interface Context<T>
        Returns:
        true if subcontext(s) are present and false if not
      • handleRemove

        protected boolean handleRemove​(Object o)
      • fireRemoveEvent

        protected void fireRemoveEvent​(Object o)
      • fireSubContextAdded

        protected void fireSubContextAdded​(Context<? extends T> context)
      • fireSubContextRemoved

        protected void fireSubContextRemoved​(Context<? extends T> context)
      • removeInternal

        protected abstract boolean removeInternal​(Object o)
      • sizeInternal

        protected abstract int sizeInternal()
      • findParent

        public Context findParent​(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.
        Specified by:
        findParent in interface Context<T>
        Parameters:
        o - an object to find in the contexts
        Returns:
        the context that contains the object
      • findContext

        public Context findContext​(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.
        Specified by:
        findContext in interface Context<T>
        Parameters:
        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
      • getProjection

        public <X extends Projection<?>> X getProjection​(Class<X> projection,
                                                         String name)
        Description copied from interface: Context
        Gets the named projection. This does not query subcontexts.
        Specified by:
        getProjection in interface Context<T>
        Parameters:
        projection - the type of the projection
        name - the name of the projection to get
        Returns:
        the named projection.
      • getProjections

        public <X extends Projection<?>> Iterable<X> getProjections​(Class<X> clazz)
        Description copied from interface: Context
        Gets all the projections in this Context of the specified type. This does not query subcontexts.
        Specified by:
        getProjections in interface Context<T>
        Parameters:
        clazz - the type of projections to get
        Returns:
        all the projections in this Context of the specified type.
      • getProjection

        public Projection<?> getProjection​(String name)
        Description copied from interface: Context
        Gets the named projection. This does not search subcontexts.
        Specified by:
        getProjection in interface Context<T>
        Parameters:
        name - the name of the projection to get
        Returns:
        the named projection.
      • addProjection

        public void addProjection​(Projection<? super T> projection)
        Description copied from interface: Context
        Adds the specified Projection to this Context.
        Specified by:
        addProjection in interface Context<T>
        Parameters:
        projection - the projection to add
      • removeProjection

        public Projection<? super T> removeProjection​(String projectionName)
        Removes the named projection from this Context.
        Specified by:
        removeProjection in interface Context<T>
        Parameters:
        projectionName - the name projection to remove
        Returns:
        the removed projection.
      • getProjections

        public Collection<Projection<?>> getProjections()
        Gets an iterable over all the projections contained by this Context.
        Specified by:
        getProjections in interface Context<T>
        Returns:
        an iterable over all the projections contained by this Context.
      • addValueLayer

        public void addValueLayer​(ValueLayer valueLayer)
        Adds the specified ValueLayer to this Context.
        Specified by:
        addValueLayer in interface Context<T>
        Parameters:
        valueLayer - the ValueLayer to add
      • removeValueLayer

        public ValueLayer removeValueLayer​(String name)
        Removes the named ValueLayer from this Context.
        Specified by:
        removeValueLayer in interface Context<T>
        Parameters:
        name - the name of the ValueLayer to remove.
        Returns:
        the removed ValueLayer or null if the named ValueLayer was not found.
      • getValueLayers

        public Collection<ValueLayer> getValueLayers()
        Gets an iterable over the ValueLayer-s contained by this Context.
        Specified by:
        getValueLayers in interface Context<T>
        Returns:
        an iterable over the ValueLayer-s contained by this Context.
      • getValueLayer

        public ValueLayer getValueLayer​(String name)
        Gets the named ValueLayer. This does not search subcontexts.
        Specified by:
        getValueLayer in interface Context<T>
        Parameters:
        name - the name of the ValueLayer to get
        Returns:
        the named ValueLayer.