Class DefaultContextSearchNode
- java.lang.Object
-
- com.hybris.cockpitng.core.config.impl.model.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-byattributes, obligatory merge attributes and/or appropriateCockpitConfigurationContextStrategy. 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).
-
-
Field Summary
-
Fields inherited from interface com.hybris.cockpitng.core.config.impl.model.ContextSearchNode
DEC_RELEVANCE_COMPARATOR, INC_RELEVANCE_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description DefaultContextSearchNode(ContextSearchNeedle searchNeedle, NodeRelevance relevance)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(ContextSearchNode child)Adds new child search node.protected booleanaddChildImmediately(ContextSearchNode child)booleanaddNodeResult(Context result)Adds new search result to current node.voidcommit()Marks node as committed.protected NodeRelevancecountNotEmptyRelevance()java.util.Collection<ContextSearchNode>getChildren()Gets all child search nodes.intgetLevel()Return a level on which the node is situated - minimum number of steps needed to come from original request to this.java.util.List<Context>getNodeResult()Gets search results bound to this node.NodeRelevancegetNotEmptyRelevance()Gets highest relevance of all children with any result in regards to original requestContextSearchNodegetParent()Gets parent search node.NodeRelevancegetRelevance()Gets relevance of this node in regards to original requestjava.util.List<Context>getResult()Gets search results bound to this node and its children.protected java.util.Collection<ContextSearchNode>getResultChildren()static java.util.Collection<ContextSearchNode>getResultChildren(ContextSearchNode node)ContextSearchNeedlegetSearchNeedle()Search request represented by this nodebooleanisCommitted()Checks if node is committed.booleanisEgalitarian()Checks how node is interpreting children results.voidremoveChild(ContextSearchNode child)Removes a child search node.protected booleanremoveChildImmediately(ContextSearchNode child)voidsetEgalitarian(boolean egalitarian)Informs a node how it should interpret its children's results.voidsetParent(ContextSearchNode parent)Updates parent search node.protected voidsetParentImmediately(ContextSearchNode parent)java.lang.StringtoString()static voidtoTreeElement(java.io.OutputStream os, ContextSearchNode node, java.lang.String elementName)Writes XML representation of single search node to provided output stream.static voidtoTreeElementAttribute(java.io.OutputStream os, java.lang.String name, java.lang.String value)Writes single search node attribute to provided output stream.static voidtoTreeElementAttributes(java.io.OutputStream os, ContextSearchNode node)Writes all attributes of single search node to provided output stream.static voidtoTreeElementEnd(java.io.OutputStream os, java.lang.String elementName)Writes a closure of XML element to provided output stream.voidtoXML(java.io.OutputStream os)Writes XML representation of search node to provided stream
-
-
-
Constructor Detail
-
DefaultContextSearchNode
public DefaultContextSearchNode(ContextSearchNeedle searchNeedle, NodeRelevance relevance)
- Parameters:
searchNeedle- search request bound to this noderelevance- relevance of this request
-
-
Method Detail
-
getRelevance
public NodeRelevance getRelevance()
Description copied from interface:ContextSearchNodeGets relevance of this node in regards to original request- Specified by:
getRelevancein interfaceContextSearchNode- Returns:
- node relevance
-
getSearchNeedle
public ContextSearchNeedle getSearchNeedle()
Description copied from interface:ContextSearchNodeSearch request represented by this node- Specified by:
getSearchNeedlein interfaceContextSearchNode- Returns:
- search request or
nullif node is only container for other requests
-
isEgalitarian
public boolean isEgalitarian()
Description copied from interface:ContextSearchNodeChecks how node is interpreting children 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:
isEgalitarianin interfaceContextSearchNode- Returns:
trueif node is egalitarian- See Also:
ContextSearchNode.getNotEmptyRelevance(),ContextSearchNode.getResult()
-
setEgalitarian
public void setEgalitarian(boolean egalitarian)
Description copied from interface:ContextSearchNodeInforms 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:
setEgalitarianin interfaceContextSearchNode- Parameters:
egalitarian-trueif node should be egalitarian
-
addNodeResult
public boolean addNodeResult(Context result)
Description copied from interface:ContextSearchNodeAdds new search result to current node.- Specified by:
addNodeResultin interfaceContextSearchNode- Parameters:
result- context that matches node's request- Returns:
trueif result has not yet been known and changed nodes result set.
-
getNodeResult
public java.util.List<Context> getNodeResult()
Description copied from interface:ContextSearchNodeGets search results bound to this node.- Specified by:
getNodeResultin interfaceContextSearchNode- Returns:
- list of contexts that matches this node's needle
-
getResultChildren
protected java.util.Collection<ContextSearchNode> getResultChildren()
-
getResultChildren
public static java.util.Collection<ContextSearchNode> getResultChildren(ContextSearchNode node)
-
getResult
public java.util.List<Context> getResult()
Description copied from interface:ContextSearchNodeGets search results bound to this node and its children. Result should be ordered by their relevance (from most relevant to least).- Specified by:
getResultin interfaceContextSearchNode- Returns:
- list of contexts that matches all requests in this branch
- See Also:
ContextSearchNode.isEgalitarian()
-
getNotEmptyRelevance
public NodeRelevance getNotEmptyRelevance()
Description copied from interface:ContextSearchNodeGets highest relevance of all children with any result in regards to original request- Specified by:
getNotEmptyRelevancein interfaceContextSearchNode- Returns:
- node's relevance if any result is bound to it, highest relevance of children with result or
nullif no result is bound to this branch
-
countNotEmptyRelevance
protected NodeRelevance countNotEmptyRelevance()
-
getLevel
public int getLevel()
Description copied from interface:ContextSearchNodeReturn a level on which the node is situated - minimum number of steps needed to come from original request to this.- Specified by:
getLevelin interfaceContextSearchNode- Returns:
0for root level and 1 more for each level of relevance
-
getParent
public ContextSearchNode getParent()
Description copied from interface:ContextSearchNodeGets parent search node.Parent node is a search needle that caused search represented by this node.
- Specified by:
getParentin interfaceContextSearchNode- Returns:
- parent search node or
nullif it is root search
-
setParent
public void setParent(ContextSearchNode parent)
Description copied from interface:ContextSearchNodeUpdates parent search node.Parent node is a search needle that caused search represented by this node.
- Specified by:
setParentin interfaceContextSearchNode- Parameters:
parent- parent search node ornullif it is root search
-
setParentImmediately
protected void setParentImmediately(ContextSearchNode parent)
-
addChild
public void addChild(ContextSearchNode child)
Description copied from interface:ContextSearchNodeAdds new child search node.A child search node is a search that is related to this node and comes from its dependencies.
- Specified by:
addChildin interfaceContextSearchNode- Parameters:
child- child node
-
addChildImmediately
protected boolean addChildImmediately(ContextSearchNode child)
-
removeChild
public void removeChild(ContextSearchNode child)
Description copied from interface:ContextSearchNodeRemoves a child search node.A child search node is a search that is related to this node and comes from its dependencies.
- Specified by:
removeChildin interfaceContextSearchNode- Parameters:
child- child node
-
removeChildImmediately
protected boolean removeChildImmediately(ContextSearchNode child)
-
isCommitted
public boolean isCommitted()
Description copied from interface:ContextSearchNodeChecks 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:
isCommittedin interfaceContextSearchNode- Returns:
trueif search bound to this node has been performed and finished
-
commit
public void commit()
Description copied from interface:ContextSearchNodeMarks 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:
commitin interfaceContextSearchNode
-
getChildren
public java.util.Collection<ContextSearchNode> getChildren()
Description copied from interface:ContextSearchNodeGets all child search nodes.A child search node is a search that is related to this node and comes from its dependencies.
- Specified by:
getChildrenin interfaceContextSearchNode- 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.IOExceptionWrites single search node attribute to provided output stream.- Parameters:
os- destination streamname- name of attribute to be writtenvalue- 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.IOExceptionWrites all attributes of single search node to provided output stream.- Parameters:
os- destination streamnode- 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.IOExceptionWrites XML representation of single search node to provided output stream. XML element written is not closed andtoTreeElementEnd(OutputStream, String)should be also called.- Parameters:
os- destination streamnode- search node which is to be writtenelementName- 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.IOExceptionWrites a closure of XML element to provided output stream.- Parameters:
os- destination streamelementName- 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.IOExceptionDescription copied from interface:ContextSearchNodeWrites XML representation of search node to provided stream- Specified by:
toXMLin interfaceContextSearchNode- Parameters:
os- destination stream- Throws:
java.io.IOException- thrown, if there were problems during writing to stream
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-