Package edu.uky.ai.io
Class Node
java.lang.Object
edu.uky.ai.io.Node
public abstract class Node
extends java.lang.Object
- Author:
- Stephen G. Ware
-
Field Summary
-
Method Summary
Modifier and Type Method Description List
asList()
Casts the node to a list.List
asList(int min, int max)
Casts the node to a list of a certain length.Symbol
asSymbol()
Casts this node to a symbol.Symbol
asSymbol(java.lang.String value)
Casts this node to a specific symbol.boolean
isList()
Tests if this node is aList
.boolean
isList(int min, int max)
Tests if this node is aList
of a certain length.boolean
isSymbol()
Tests if this node is aSymbol
.boolean
isSymbol(java.lang.String value)
Tests if this node is a specificSymbol
.static Node
parse(java.io.File file)
Parse a given file as a node.static Node
parse(java.lang.String string)
Parse a given string as a node.Node
requireNext()
Returns the node's next sibling or throws an exception if no such node exists.
-
Field Details
-
next
The node that follows this node (i.e. its next sibling) or null if this is the last node in a list
-
-
Method Details
-
requireNext
Returns the node's next sibling or throws an exception if no such node exists.- Returns:
- the next sibling
- Throws:
FormatException
- if no next sibling exists
-
isSymbol
public boolean isSymbol()Tests if this node is aSymbol
.- Returns:
- true if the node is a symbol, false otherwise
-
isSymbol
public boolean isSymbol(java.lang.String value)Tests if this node is a specificSymbol
.- Parameters:
value
- the value of the symbol- Returns:
- true if the node is that symbol, false otherwise
-
asSymbol
Casts this node to a symbol.- Returns:
- the node as a symbol
- Throws:
FormatException
- if the node is not a symbol
-
asSymbol
Casts this node to a specific symbol.- Parameters:
value
- the value of the symbol- Returns:
- the node as the symbol
- Throws:
FormatException
- if the node is not a symbol
-
isList
public boolean isList()Tests if this node is aList
.- Returns:
- true if the node is a list, false otherwise
-
isList
public boolean isList(int min, int max)Tests if this node is aList
of a certain length.- Parameters:
min
- the minimum number of elements the list can havemax
- the maximum number of elements the list can have (-1 indicates any number of elements)- Returns:
- true if the node is such a list, false otherwise
-
asList
Casts the node to a list.- Returns:
- the node as a list
- Throws:
FormatException
- if the node is not a list
-
asList
Casts the node to a list of a certain length.- Parameters:
min
- the minimum number of elements the list can havemax
- the maximum number of elements the list can have (-1 indicates any number of elements)- Returns:
- the node as a list of that length
- Throws:
FormatException
- if the node is not a list
-
parse
Parse a given file as a node.- Parameters:
file
- the file to parse- Returns:
- a node
- Throws:
java.io.IOException
- if an IO exception occurred while reading the file
-
parse
Parse a given string as a node.- Parameters:
string
- the string to parse- Returns:
- a node
-