Package io.jenetics.ext
Class AbstractTreeGene<A,G extends AbstractTreeGene<A,G>>
- java.lang.Object
-
- io.jenetics.ext.AbstractTreeGene<A,G>
-
- All Implemented Interfaces:
TreeGene<A,G>
,FlatTree<A,G>
,Tree<A,G>
,Gene<A,G>
,Factory<G>
,Verifiable
,Serializable
,Iterable<G>
public abstract class AbstractTreeGene<A,G extends AbstractTreeGene<A,G>> extends Object implements TreeGene<A,G>, Serializable
Abstract implementation of theTreeGene
interface..- Since:
- 3.9
- Version:
- 6.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTreeGene(A allele, int childOffset, int childCount)
Creates a new tree-gene from the given data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description A
allele()
protected void
bind(BaseSeq<G> genes)
This method is used by theAbstractTreeChromosome
to attach itself to this gene.protected void
checkTreeState()
G
childAt(int index)
Return the child gene with the given index.int
childCount()
Return the number of children this tree node consists of.int
childOffset()
Return the index of the first child node in the underlying node array.boolean
equals(Object obj)
ISeq<G>
flattenedNodes()
Return the whole flattened tree values in breadth-first order.int
hashCode()
boolean
isRoot()
Returnstrue
if this node is the root of the tree.boolean
isValid()
Optional<G>
parent()
Return the parent node of this tree node.G
root()
Returns the root of the tree that contains this node.int
size()
Return the number of nodes ofthis
node (sub-tree).String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.jenetics.Gene
newInstance, newInstance
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface io.jenetics.ext.util.Tree
breadthFirstIterator, breadthFirstStream, childAfter, childAtPath, childAtPath, childBefore, childIterator, childPath, childStream, depth, depthFirstIterator, depthFirstStream, firstChild, firstLeaf, identical, indexOf, isAncestor, isChild, isDescendant, isLeaf, isRelated, isSibling, iterator, lastChild, lastLeaf, leafCount, level, nextLeaf, nextNode, nextSibling, path, pathElements, pathFromAncestorIterator, postorderIterator, postorderStream, preorderIterator, preorderStream, previousLeaf, previousNode, previousSibling, sharedAncestor, siblingCount, stream, toParenthesesString, toParenthesesString
-
Methods inherited from interface io.jenetics.ext.TreeGene
newInstance, newInstance, value
-
-
-
-
Constructor Detail
-
AbstractTreeGene
protected AbstractTreeGene(A allele, int childOffset, int childCount)
Creates a new tree-gene from the given data.- Parameters:
allele
- the actual value (allele) of the tree-genechildOffset
- the offset index of the child in the containing chromosome. If this node has no child, the value should be set to zero.childCount
- the number of children of this gene- Throws:
IllegalArgumentException
- if thechildCount
is smaller than zero
-
-
Method Detail
-
flattenedNodes
public ISeq<G> flattenedNodes()
Return the whole flattened tree values in breadth-first order. This method will always return the sameISeq
instance.- Specified by:
flattenedNodes
in interfaceFlatTree<A,G extends AbstractTreeGene<A,G>>
- Returns:
- the whole flattened tree values
-
root
public G root()
Description copied from interface:Tree
Returns the root of the tree that contains this node. The root is the ancestor with no parent.
-
isRoot
public boolean isRoot()
Description copied from interface:Tree
Returnstrue
if this node is the root of the tree.
-
size
public int size()
Description copied from interface:Tree
Return the number of nodes ofthis
node (sub-tree).
-
checkTreeState
protected void checkTreeState()
-
bind
protected void bind(BaseSeq<G> genes)
This method is used by theAbstractTreeChromosome
to attach itself to this gene.- Parameters:
genes
- the genes of the attached chromosome
-
childOffset
public int childOffset()
Description copied from interface:FlatTree
Return the index of the first child node in the underlying node array.-1
is returned ifthis
node is a leaf.- Specified by:
childOffset
in interfaceFlatTree<A,G extends AbstractTreeGene<A,G>>
- Returns:
- Return the index of the first child node in the underlying node
array, or
-1
ifthis
node is a leaf
-
parent
public Optional<G> parent()
Return the parent node of this tree node.- Specified by:
parent
in interfaceTree<A,G extends AbstractTreeGene<A,G>>
- Returns:
- the parent node, or
Optional.empty()
if this node is the root of the tree - Throws:
IllegalStateException
- if this gene is not part of a chromosome
-
childAt
public G childAt(int index)
Return the child gene with the given index.- Specified by:
childAt
in interfaceTree<A,G extends AbstractTreeGene<A,G>>
- Parameters:
index
- the child index- Returns:
- the child node with the given index
- Throws:
IndexOutOfBoundsException
- if theindex
is out of bounds ([0, childCount())
)IllegalStateException
- if this gene is not part of a chromosome
-
childCount
public int childCount()
Description copied from interface:Tree
Return the number of children this tree node consists of.- Specified by:
childCount
in interfaceTree<A,G extends AbstractTreeGene<A,G>>
- Returns:
- the number of children this tree node consists of
-
isValid
public boolean isValid()
- Specified by:
isValid
in interfaceVerifiable
-
-