Class DefaultContextSearchNode

  • All Implemented Interfaces:
    ContextSearchNode
    Direct Known Subclasses:
    ContextSearchTree

    public class DefaultContextSearchNode
    extends java.lang.Object
    implements ContextSearchNode
    Represents a single search needle with all its results in the tree of context searches.

    Searching of contexts is performed by traversing through context tree in regards to merge-by attributes, obligatory merge attributes and/or appropriate CockpitConfigurationContextStrategy. Each step down the tree means that any contexts found are a little bit less relevant to actual request. It is represented by search level and results in lower priority during merge process - a context with lower priority (found on lower level) is merged into a context with higher priority (found on higher level).

    • Constructor Detail

      • DefaultContextSearchNode

        public DefaultContextSearchNode​(ContextSearchNeedle searchNeedle,
                                        NodeRelevance relevance)
        Parameters:
        searchNeedle - search request bound to this node
        relevance - relevance of this request
    • Method Detail

      • setEgalitarian

        public void setEgalitarian​(boolean egalitarian)
        Description copied from interface: ContextSearchNode
        Informs a node how it should interpret its children's results. If a node is egalitarian, then result of all children are considered as a result of this node. Otherwise only a child with highest relevance is taken under consideration.
        Specified by:
        setEgalitarian in interface ContextSearchNode
        Parameters:
        egalitarian - true if node should be egalitarian
      • addNodeResult

        public boolean addNodeResult​(Context result)
        Description copied from interface: ContextSearchNode
        Adds new search result to current node.
        Specified by:
        addNodeResult in interface ContextSearchNode
        Parameters:
        result - context that matches node's request
        Returns:
        true if result has not yet been known and changed nodes result set.
      • getNodeResult

        public java.util.List<Context> getNodeResult()
        Description copied from interface: ContextSearchNode
        Gets search results bound to this node.
        Specified by:
        getNodeResult in interface ContextSearchNode
        Returns:
        list of contexts that matches this node's needle
      • getResultChildren

        protected java.util.Collection<ContextSearchNode> getResultChildren()
      • getNotEmptyRelevance

        public NodeRelevance getNotEmptyRelevance()
        Description copied from interface: ContextSearchNode
        Gets highest relevance of all children with any result in regards to original request
        Specified by:
        getNotEmptyRelevance in interface ContextSearchNode
        Returns:
        node's relevance if any result is bound to it, highest relevance of children with result or null if no result is bound to this branch
      • countNotEmptyRelevance

        protected NodeRelevance countNotEmptyRelevance()
      • getLevel

        public int getLevel()
        Description copied from interface: ContextSearchNode
        Return a level on which the node is situated - minimum number of steps needed to come from original request to this.
        Specified by:
        getLevel in interface ContextSearchNode
        Returns:
        0 for root level and 1 more for each level of relevance
      • getParent

        public ContextSearchNode getParent()
        Description copied from interface: ContextSearchNode
        Gets parent search node.

        Parent node is a search needle that caused search represented by this node.

        Specified by:
        getParent in interface ContextSearchNode
        Returns:
        parent search node or null if it is root search
      • setParent

        public void setParent​(ContextSearchNode parent)
        Description copied from interface: ContextSearchNode
        Updates parent search node.

        Parent node is a search needle that caused search represented by this node.

        Specified by:
        setParent in interface ContextSearchNode
        Parameters:
        parent - parent search node or null if it is root search
      • setParentImmediately

        protected void setParentImmediately​(ContextSearchNode parent)
      • addChild

        public void addChild​(ContextSearchNode child)
        Description copied from interface: ContextSearchNode
        Adds new child search node.

        A child search node is a search that is related to this node and comes from its dependencies.

        Specified by:
        addChild in interface ContextSearchNode
        Parameters:
        child - child node
      • addChildImmediately

        protected boolean addChildImmediately​(ContextSearchNode child)
      • removeChild

        public void removeChild​(ContextSearchNode child)
        Description copied from interface: ContextSearchNode
        Removes a child search node.

        A child search node is a search that is related to this node and comes from its dependencies.

        Specified by:
        removeChild in interface ContextSearchNode
        Parameters:
        child - child node
      • removeChildImmediately

        protected boolean removeChildImmediately​(ContextSearchNode child)
      • isCommitted

        public boolean isCommitted()
        Description copied from interface: ContextSearchNode
        Checks if node is committed.

        Search node should be committed after all searches bound to this node has been performed, all results has been assigned and nothing should be changed regarding this node and all its children.

        Committed node becomes immutable and any action that may change it's result will result in IllegalStateException.

        Specified by:
        isCommitted in interface ContextSearchNode
        Returns:
        true if search bound to this node has been performed and finished
      • commit

        public void commit()
        Description copied from interface: ContextSearchNode
        Marks node as committed.

        Search node should be committed after all searches bound to this node has been performed, all results has been assigned and nothing should be changed regarding this node and all its children.

        Committed node becomes immutable and any action that may change it's result will result in IllegalStateException.

        Specified by:
        commit in interface ContextSearchNode
      • getChildren

        public java.util.Collection<ContextSearchNode> getChildren()
        Description copied from interface: ContextSearchNode
        Gets all child search nodes.

        A child search node is a search that is related to this node and comes from its dependencies.

        Specified by:
        getChildren in interface ContextSearchNode
        Returns:
        collection of child nodes
      • toTreeElementAttribute

        public static void toTreeElementAttribute​(java.io.OutputStream os,
                                                  java.lang.String name,
                                                  java.lang.String value)
                                           throws java.io.IOException
        Writes single search node attribute to provided output stream.
        Parameters:
        os - destination stream
        name - name of attribute to be written
        value - value of attribute to be written
        Throws:
        java.io.IOException - thrown if some problems occurred while writing to stream
      • toTreeElementAttributes

        public static void toTreeElementAttributes​(java.io.OutputStream os,
                                                   ContextSearchNode node)
                                            throws java.io.IOException
        Writes all attributes of single search node to provided output stream.
        Parameters:
        os - destination stream
        node - search node which attributes are to be written
        Throws:
        java.io.IOException - thrown if some problems occurred while writing to stream
      • toTreeElement

        public static void toTreeElement​(java.io.OutputStream os,
                                         ContextSearchNode node,
                                         java.lang.String elementName)
                                  throws java.io.IOException
        Writes XML representation of single search node to provided output stream. XML element written is not closed and toTreeElementEnd(OutputStream, String) should be also called.
        Parameters:
        os - destination stream
        node - search node which is to be written
        elementName - name of element that should represent provided node
        Throws:
        java.io.IOException - thrown if some problems occurred while writing to stream
      • toTreeElementEnd

        public static void toTreeElementEnd​(java.io.OutputStream os,
                                            java.lang.String elementName)
                                     throws java.io.IOException
        Writes a closure of XML element to provided output stream.
        Parameters:
        os - destination stream
        elementName - name of element that should be closed
        Throws:
        java.io.IOException - thrown if writing to stream fails
      • toXML

        public void toXML​(java.io.OutputStream os)
                   throws java.io.IOException
        Description copied from interface: ContextSearchNode
        Writes XML representation of search node to provided stream
        Specified by:
        toXML in interface ContextSearchNode
        Parameters:
        os - destination stream
        Throws:
        java.io.IOException - thrown, if there were problems during writing to stream
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object