public class Node extends Object implements Comparable<Node>
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.
Modifier and Type | Class and Description |
---|---|
static class |
Node.Type
The type of node.
|
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
private |
Node(Node copyFrom,
Node parent)
Make a copy of a node
|
|
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 node
|
|
Node(String name,
String title,
Node parent,
BasicItem item,
ChildNodeDirection direction)
Create an item-type child node
|
private |
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.
|
Modifier and Type | Method and 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 to
getNewChildren() . |
<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() |
private final String name
private final String title
private BasicItem item
private final Node parent
private final Node.Type type
private final String nodeId
private final ChildNodeDirection direction
private int numWarnings
private int numErrors
private int childWarnings
private int childErrors
private boolean childrenLoaded
private Map<NodeAttribute,Object> attributes
public Node(String name, String title, BasicItem item)
name
- The name of the nodetitle
- The display title of the nodeitem
- The item the node referencesGenericOverview.getRootNode()
public Node(String name, String title, Node parent)
name
- The name of the child nodetitle
- The display title of the nodeparent
- The parent nodepublic Node(String name, String title, Node parent, ChildNodeDirection direction)
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 nodespublic Node(String name, String title, Node parent, BasicItem item)
name
- The name of the child nodetitle
- The display title of the nodeparent
- The parent nodeitem
- The item this node referencespublic Node(String name, String title, Node parent, BasicItem item, ChildNodeDirection direction)
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 nodesprivate Node(String name, String title, Node parent, BasicItem item, Node.Type type, ChildNodeDirection direction)
public String getId()
public Node.Type getNodeType()
getItem()
always return null. It it returns null for
an item-type node it usually means that access was denied to that
particular item.public String getName()
getParent().getChild(this.getName())
should return this node.public String getTitle()
public BasicItem getItem()
public BasicItem getItem(DbControl dc)
public Item getItemType()
getItem().getType()
.public Node getParent()
public Node getFirstParent(Filter<? super Node> filter)
Filter.evaluate(Object)
returns true is the node that is returned.filter
- The filter to use for matching parentpublic Node getFirstNode(Filter<? super Node> filter)
Filter.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 calling
getFirstParent(Filter)
if it didn't match.filter
- The filter to use for matching nodespublic List<Node> findAll(Filter<? super Node> filter)
filter
- The filter to use for matching nodespublic List<Node> getChildren()
public int numChildren()
public Node getChild(String name)
name
- The name of the child node.public int numNewChildren()
getNewChildren()
.public List<Node> getNewChildren()
protected void addChild(Node child)
public void sortChildren(Comparator<? super Node> comparator)
comparator
- A comparator that determines the sort order,
if not specifed, they children are sorted according to their
titlepublic void setChildrenLoaded()
public boolean isChildrenLoaded()
public ChildNodeDirection getChildNodeDirection()
public void setWarnings(int numWarnings)
numWarnings
- The number of warningsaddWarnings(int)
public void addWarnings(int numWarnings)
numWarnings
- The numer of warnings to addsetWarnings(int)
protected void addChildWarnings(int numWarnings)
public void setErrors(int numErrors)
numErrors
- The number of errorsaddErrors(int)
public void addErrors(int numErrors)
numErrors
- The numer of errors to addsetErrors(int)
protected void addChildErrors(int numErrors)
public int getNumWarnings()
getChildWarnings()
public int getNumErrors()
getChildErrors()
public int getChildWarnings()
getNumWarnings()
public int getChildErrors()
getNumErrors()
public void clearFailures()
public <T> void setAttribute(NodeAttribute<T> attribute, T value)
attribute
- The attribute to setvalue
- The value to set for the attribute or null to remove the
current valuepublic <T> T getAttribute(NodeAttribute<T> attribute)
attribute
- The attribute to getpublic boolean hasAttribute(NodeAttribute<?> attribute)
attribute
- The attribute to checkpublic Node deepCopy(Node parentOfCopy)
parentOfCopy
- The node that should be the parent of the
copy or null to make the copy a root nodePermissionDeniedException
- If the given parent node is a
descendant of this node (it would lead to an infinite loop)public int compareTo(Node o)
compareTo
in interface Comparable<Node>