Top Description Fields Constructors Methods
org.jabref.model

public abstract Class ChainNode<T extends ChainNode<T>>

extends Object
Class Inheritance
Known Direct Subclasses
org.jabref.model.entry.Keyword
Annotations
@SuppressWarnings:unchecked
Type Parameters
<T>
the type of the class
Imports
java.util.Objects, .Optional

Represents a node in a chain. We view a chain as a vertical hierarchy and thus refer to the previous node as parent and the next node is a child.

In usual implementations, nodes function as wrappers around a data object. Thus normally they have a value property which allows access to the value stored in the node. In contrast to this approach, the ChainNode<T> class is designed to be used as a base class which provides the tree traversing functionality via inheritance.

Example usage: private class BasicChainNode extends ChainNode<BasicChainNode> { public BasicChainNode() { super(BasicChainNode.class); } }

Field Summary

Modifier and TypeField and Description
private T
child

This node's child, or null if this node has no child

private T
parent

This node's parent, or null if this node has no parent

Constructor Summary

AccessConstructor and Description
public
ChainNode(Class<T>
class deriving from TreeNode<T>. It should always be "T.class". We need this parameter since it is hard to get this information by other means.
derivingClass
)

Constructs a chain node without parent and no child.

Method Summary

Modifier and TypeMethod and Description
public void
addAtEnd(T node)

Adds the given node at the end of the chain.

public Optional<T>

Returns:

this node's child T, or an empty Optional if this node has no child
getChild
()

Returns this node's child or an empty Optional if this node has no child.

public Optional<T>

Returns:

this node's parent T, or an empty Optional if this node has no parent
getParent
()

Returns this node's parent or an empty Optional if this node has no parent.

public boolean

Returns:

true if anotherNode is a descendant of this node
isAncestorOf
(T
node to test
anotherNode
)

Returns true if this node is an ancestor of the given node.

public void
moveTo(T
the new parent
target
)

Removes this node from its parent and makes it a child of the specified node.

public void
removeChild()

Removes the child from this node's child list, giving it an empty parent.

public T

Returns:

the child node
setChild
(T
the node to add as child
child
)

Adds the node as the child.

protected void
setParent(T
the new parent
parent
)

Sets the parent node of this node.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

childback to summary
private T child

This node's child, or null if this node has no child

parentback to summary
private T parent

This node's parent, or null if this node has no parent

Constructor Detail

ChainNodeback to summary
public ChainNode(Class<T> derivingClass)

Constructs a chain node without parent and no child.

Parameters
derivingClass:Class<T>

class deriving from TreeNode<T>. It should always be "T.class". We need this parameter since it is hard to get this information by other means.

Method Detail

addAtEndback to summary
public void addAtEnd(T node)

Adds the given node at the end of the chain. E.g., "A > B > C" + "D" -> "A > B > C > D".

getChildback to summary
public Optional<T> getChild()

Returns this node's child or an empty Optional if this node has no child.

Returns:Optional<T>

this node's child T, or an empty Optional if this node has no child

getParentback to summary
public Optional<T> getParent()

Returns this node's parent or an empty Optional if this node has no parent.

Returns:Optional<T>

this node's parent T, or an empty Optional if this node has no parent

isAncestorOfback to summary
public boolean isAncestorOf(T anotherNode)

Returns true if this node is an ancestor of the given node.

A node is considered an ancestor of itself.

Parameters
anotherNode:T

node to test

Returns:boolean

true if anotherNode is a descendant of this node

Exceptions
NullPointerException:
if anotherNode is null
moveToback to summary
public void moveTo(T target)

Removes this node from its parent and makes it a child of the specified node. In this way the whole subchain based at this node is moved to the given node.

Parameters
target:T

the new parent

Exceptions
NullPointerException:
if target is null
UnsupportedOperationException:
if target is an descendant of this node
removeChildback to summary
public void removeChild()

Removes the child from this node's child list, giving it an empty parent.

setChildback to summary
public T setChild(T child)

Adds the node as the child. Also sets the parent of the given node to this node. The given node is not allowed to already be in a tree (i.e. it has to have no parent).

Parameters
child:T

the node to add as child

Returns:T

the child node

Exceptions
UnsupportedOperationException:
if the given node has already a parent
setParentback to summary
protected void setParent(T parent)

Sets the parent node of this node.

This method does not set this node as the child of the new parent nor does it remove this node from the old parent. You should probably call moveTo(ChainNode) to change the chain.

Parameters
parent:T

the new parent