Interface Sexpr<T extends Sexpr<T>>
- Type Parameters:
T
- is the type of the implementing class.
- All Superinterfaces:
Comparable<Sexpr<?>>
The textual representations of symbolic expressions are case-sensitive.
Symbolic expressions are naturally comparable based on their textual representations.
Two symbolic expressions (X) and (Y) are equal,
iff X.toString()
equals Y.toString()
.
All instances of this interface are immutable.
-
Method Summary
Modifier and TypeMethodDescriptiondefault SAtom
asAtom()
Cast this object to SAtom.default SList
asList()
Cast this object to SList.boolean
This method performs a breadth-first-search of the tree rooted at this node.default int
boolean
This method performs a depth-first-search of the tree rooted at this node.boolean
isAtom()
This method determines whether this object is a SAtom.boolean
isList()
This method determines whether this object is a SList.location()
This method retrieves an object describing the source from which this object we obtained.boolean
This method performs a post-order-search of the tree rooted at this node.boolean
This method performs a pre-order-search of the tree rooted at this node.toString()
This method retrieves the textual representation of this symbolic expression.void
This method performs a traversal of the tree rooted at this node.int
This method determines the height of the tree rooted at this node.int
This method counts the leaf nodes in the tree rooted at this node.int
treeSize()
This method counts the nodes in the tree rooted at this node.
-
Method Details
-
treeLeafCount
int treeLeafCount()This method counts the leaf nodes in the tree rooted at this node.This is a constant-time operation.
- Returns:
- the number of leaf nodes.
-
treeHeight
int treeHeight()This method determines the height of the tree rooted at this node.This is a constant-time operation.
- Returns:
- the height of this tree.
-
treeSize
int treeSize()This method counts the nodes in the tree rooted at this node.This is a constant-time operation.
- Returns:
- the number of nodes, including this node.
-
bfs
This method performs a breadth-first-search of the tree rooted at this node.- Parameters:
condition
- will return true, when the sought after node is found.- Returns:
- true, if the node was found.
-
dfs
This method performs a depth-first-search of the tree rooted at this node.- Parameters:
condition
- will return true, when the sought after node is found.- Returns:
- true, if the node was found.
-
preorder
This method performs a pre-order-search of the tree rooted at this node.- Parameters:
condition
- will return true, when the sought after node is found.- Returns:
- true, if the node was found.
-
postorder
This method performs a post-order-search of the tree rooted at this node.- Parameters:
condition
- will return true, when the sought after node is found.- Returns:
- true, if the node was found.
-
traverse
This method performs a traversal of the tree rooted at this node.- Parameters:
before
- will be invoked upon entering each sub-tree.after
- will be invoked upon exiting each sub-tree.
-
isAtom
boolean isAtom()This method determines whether this object is a SAtom.- Returns:
- true, iff this object is a SAtom.
-
isList
boolean isList()This method determines whether this object is a SList.- Returns:
- true, iff this object is a SAtom.
-
location
SourceLocation location()This method retrieves an object describing the source from which this object we obtained.- Returns:
- the source-code location of this node.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T extends Sexpr<T>>
-
asAtom
Cast this object to SAtom.This method could be considered a bad API design choice. However, the inclusion of this method makes the use of fluent chained-methods calls clearer and easier to write; therefore, the benefits outweigh the down-sides here.
- Returns:
- this.
- Throws:
ClassCastException
- if isAtom() is false.
-
asList
Cast this object to SList.This method could be considered a bad API design choice. However, the inclusion of this method makes the use of fluent chained-methods calls clearer and easier to write; therefore, the benefits outweigh the down-sides here.
- Returns:
- this.
- Throws:
ClassCastException
- if isList() is false.
-
toString
String toString()This method retrieves the textual representation of this symbolic expression.
-