Package net.sf.basedb.util.overview
Class Node
java.lang.Object
net.sf.basedb.util.overview.Node
- All Implemented Interfaces:
Comparable<Node>
public class Node extends Object implements Comparable<Node>
A node in an overview. There are two types of nodes: folder nodes
and item nodes. The only difference is that an item node has a link
to a
BasicItem
(see getItem()
but a folder node does not.
Both node types can have child nodes.
Each node has a unique ID (getId()
) which is based on the system
hashcode. Each node also has a name which should be unique among the
child nodes. If the name isn't unique the getChild(String)
returns the
first matching node.
- Version:
- 2.2
- Author:
- Nicklas
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Node.Type
The type of node. -
Field Summary
Fields Modifier and Type Field Description private Map<NodeAttribute<?>,Object>
attributes
private int
childErrors
private List<Node>
children
private boolean
childrenLoaded
private int
childWarnings
private ChildNodeDirection
direction
private BasicItem
item
private String
name
private List<Node>
newChildren
private String
nodeId
private int
numErrors
private int
numWarnings
private Node
parent
private String
title
private Node.Type
type
-
Constructor Summary
Constructors Modifier Constructor Description Node(String name, String title, BasicItem item)
Create an item-type root node.Node(String name, String title, Node parent)
Create a folder-type child node.Node(String name, String title, Node parent, BasicItem item)
Create an item-type child nodeNode(String name, String title, Node parent, BasicItem item, ChildNodeDirection direction)
Create an item-type child nodeprivate
Node(String name, String title, Node parent, BasicItem item, Node.Type type, ChildNodeDirection direction)
Node(String name, String title, Node parent, ChildNodeDirection direction)
Create a folder-type child node.private
Node(Node copyFrom, Node parent)
Make a copy of a node -
Method Summary
Modifier and Type Method Description protected void
addChild(Node child)
Add a child node to this one.protected void
addChildErrors(int numErrors)
Add child errors to this node.protected void
addChildWarnings(int numWarnings)
Add child warnings to this node.void
addErrors(int numErrors)
Add more errors to this node.void
addWarnings(int numWarnings)
Add more warnings to this node.void
clearFailures()
Clear all warnings, errors on this node and on all child nodes.int
compareTo(Node o)
Node
deepCopy(Node parentOfCopy)
Create a deep copy of this node and all it's children.private Node
deepCopyInternal(Node parentOfCopy)
List<Node>
findAll(Filter<? super Node> filter)
Find all nodes in the parent chain that matches the given filter.<T> T
getAttribute(NodeAttribute<T> attribute)
Get the value for a node attribute.Node
getChild(String name)
Get the child node with a specific name.int
getChildErrors()
Get the number of errors to children of this node.ChildNodeDirection
getChildNodeDirection()
Get the direction to use when loading children of this node.List<Node>
getChildren()
Get all child nodes of this node.int
getChildWarnings()
Get the number of warnings to children of this node.Node
getFirstNode(Filter<? super Node> filter)
Find the first node (including this) that matches a filter.Node
getFirstParent(Filter<? super Node> filter)
Find the first parent node that matches a filter.String
getId()
Get a unique ID for this node.BasicItem
getItem()
Get the item that is related to this node.BasicItem
getItem(DbControl dc)
Get the item that is related to this node and make sure that it is loaded with the current DbControl.Item
getItemType()
Get the item type of the item that this node related to this node.String
getName()
Get the name of this node.List<Node>
getNewChildren()
Get all new children to this node.Node.Type
getNodeType()
Get the node type of this node.int
getNumErrors()
Get the number of errors on this node.int
getNumWarnings()
Get the number of warnings on this node.Node
getParent()
Get the parent of this node.String
getTitle()
Get the display title of this node.boolean
hasAttribute(NodeAttribute<?> attribute)
Check if the node has a value for the given attribute.boolean
isChildrenLoaded()
int
numChildren()
Get the number of child nodes in this node.int
numNewChildren()
Get the number of new children added to this node since the last call togetNewChildren()
.<T> void
setAttribute(NodeAttribute<T> attribute, T value)
Set a node attribute.void
setChildrenLoaded()
Sets a flag to indicate that all children has been loaded.void
setErrors(int numErrors)
Set the number of errors that was found while validating this node.void
setWarnings(int numWarnings)
Set the number of warnings that was found while validating this node.void
sortChildren(Comparator<? super Node> comparator)
Sorts the list of child nodes.String
toString()
-
Field Details
-
name
-
title
-
item
-
parent
-
type
-
nodeId
-
direction
-
children
-
numWarnings
private int numWarnings -
numErrors
private int numErrors -
childWarnings
private int childWarnings -
childErrors
private int childErrors -
childrenLoaded
private boolean childrenLoaded -
attributes
-
newChildren
-
-
Constructor Details
-
Node
Create an item-type root node.- Parameters:
name
- The name of the nodetitle
- The display title of the nodeitem
- The item the node references- See Also:
GenericOverview.getRootNode()
-
Node
Create a folder-type child node.- Parameters:
name
- The name of the child nodetitle
- The display title of the nodeparent
- The parent node
-
Node
Create a folder-type child node.- Parameters:
name
- The name of the child nodetitle
- The display title of the nodeparent
- The parent nodedirection
- The direction to use when continuing to load child nodes- Since:
- 2.10
-
Node
Create an item-type child node- Parameters:
name
- The name of the child nodetitle
- The display title of the nodeparent
- The parent nodeitem
- The item this node references
-
Node
Create an item-type child node- Parameters:
name
- The name of the child nodetitle
- The display title of the nodeparent
- The parent nodeitem
- The item this node referencesdirection
- The direction to use when continuing to load child nodes- Since:
- 2.10
-
Node
-
Node
Make a copy of a node- Since:
- 2.10
-
-
Method Details
-
getId
Get a unique ID for this node. The ID is based on the hashcode and should be unique for a given virtual machine. -
getNodeType
Get the node type of this node. Note that for folder-type nodes thegetItem()
always return null. It it returns null for an item-type node it usually means that access was denied to that particular item. -
getName
Get the name of this node. If the name is unique among the child nodes for a parent the callgetParent().getChild(this.getName())
should return this node. -
getTitle
Get the display title of this node. -
getItem
Get the item that is related to this node. Folder-type nodes always return null. If an item-type node returns null it usually means that access was denied to the item. -
getItem
Get the item that is related to this node and make sure that it is loaded with the current DbControl. Folder-type nodes always return null. If an item-type node returns null it usually means that access was denied to the item.- Since:
- 2.10
-
getItemType
Get the item type of the item that this node related to this node. This method is a shortcut forgetItem().getType()
.- Returns:
- The item type, or null if no item is attached to this node
- Since:
- 2.10
-
getParent
Get the parent of this node. Returns null if this is the root node. -
getFirstParent
Find the first parent node that matches a filter. Eg. The first parent wereFilter.evaluate(Object)
returns true is the node that is returned.- Parameters:
filter
- The filter to use for matching parent- Returns:
- The node, or null if no node was found
- Since:
- 2.10
-
getFirstNode
Find the first node (including this) that matches a filter. Eg. the first node wereFilter.evaluate(Object)
returns true is the node that is returned. Calling this method is equivalent to first evaluating the filter on this node, and then callinggetFirstParent(Filter)
if it didn't match.- Parameters:
filter
- The filter to use for matching nodes- Returns:
- The node, or null if no node was found
- Since:
- 3.0
-
findAll
Find all nodes in the parent chain that matches the given filter.- Parameters:
filter
- The filter to use for matching nodes- Returns:
- A list with the matched nodes in the order they matched
- Since:
- 3.2
-
getChildren
Get all child nodes of this node. May return null or an empty list if this node has no children. -
numChildren
public int numChildren()Get the number of child nodes in this node.- Returns:
- The number of child nodes, or -1 if the child nodes has not been loaded yet
- Since:
- 2.10
-
getChild
Get the child node with a specific name. If more than one node has the same name only the first one found is returned.- Parameters:
name
- The name of the child node.- Returns:
- The child node with the given name, or null if no node is found
-
numNewChildren
public int numNewChildren()Get the number of new children added to this node since the last call togetNewChildren()
.- Returns:
- The number of child nodes, or -1 if the child nodes has not been loaded yet
- Since:
- 3.2
-
getNewChildren
Get all new children to this node. May return null or an empty list if this node has no children. Calling this method clears the new children information and the next call will return null unless more children is added inbetween.- Since:
- 3.2
-
addChild
Add a child node to this one. -
sortChildren
Sorts the list of child nodes.- Parameters:
comparator
- A comparator that determines the sort order, if not specifed, they children are sorted according to their title- Since:
- 2.14
-
setChildrenLoaded
public void setChildrenLoaded()Sets a flag to indicate that all children has been loaded.- Since:
- 2.10
-
isChildrenLoaded
public boolean isChildrenLoaded()- Returns:
- TRUE if the children to this node has been loaded, FALSE otherwise
- Since:
- 2.10
-
getChildNodeDirection
Get the direction to use when loading children of this node.- Returns:
- A ChildNodeDirection object
- Since:
- 2.10
-
setWarnings
public void setWarnings(int numWarnings)Set the number of warnings that was found while validating this node. This method automatically updates the number of child warnings reported by parent nodes.- Parameters:
numWarnings
- The number of warnings- See Also:
addWarnings(int)
-
addWarnings
public void addWarnings(int numWarnings)Add more warnings to this node. This method automatically updates the number of child warnings reported by parent nodes.- Parameters:
numWarnings
- The numer of warnings to add- See Also:
setWarnings(int)
-
addChildWarnings
protected void addChildWarnings(int numWarnings)Add child warnings to this node. This method is called by child nodes when the warnings are updated on them. -
setErrors
public void setErrors(int numErrors)Set the number of errors that was found while validating this node. This method automatically updates the number of child errors reported by parent nodes.- Parameters:
numErrors
- The number of errors- See Also:
addErrors(int)
-
addErrors
public void addErrors(int numErrors)Add more errors to this node. This method automatically updates the number of child errors reported by parent nodes.- Parameters:
numErrors
- The numer of errors to add- See Also:
setErrors(int)
-
addChildErrors
protected void addChildErrors(int numErrors)Add child errors to this node. This method is called by child nodes when the errors are updated on them. -
getNumWarnings
public int getNumWarnings()Get the number of warnings on this node.- See Also:
getChildWarnings()
-
getNumErrors
public int getNumErrors()Get the number of errors on this node.- See Also:
getChildErrors()
-
getChildWarnings
public int getChildWarnings()Get the number of warnings to children of this node.- See Also:
getNumWarnings()
-
getChildErrors
public int getChildErrors()Get the number of errors to children of this node.- See Also:
getNumErrors()
-
clearFailures
public void clearFailures()Clear all warnings, errors on this node and on all child nodes. -
setAttribute
Set a node attribute.- Parameters:
attribute
- The attribute to setvalue
- The value to set for the attribute or null to remove the current value- Since:
- 3.0
-
getAttribute
Get the value for a node attribute.- Parameters:
attribute
- The attribute to get- Returns:
- The value or null if there is no value
- Since:
- 3.0
-
hasAttribute
Check if the node has a value for the given attribute.- Parameters:
attribute
- The attribute to check- Returns:
- TRUE if a value exists, FALSE otherwise
- Since:
- 3.0
-
deepCopy
Create a deep copy of this node and all it's children. The copy will be attached to the given parent.- Parameters:
parentOfCopy
- The node that should be the parent of the copy or null to make the copy a root node- Returns:
- The copy
- Throws:
PermissionDeniedException
- If the given parent node is a descendant of this node (it would lead to an infinite loop)- Since:
- 2.10
-
deepCopyInternal
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Node>
-
toString
-