Package edu.uky.ai.io

Class Node

java.lang.Object
edu.uky.ai.io.Node
Direct Known Subclasses:
List, Symbol

public abstract class Node extends Object
The abstract parent class of List and Symbol.
Author:
Stephen G. Ware
  • Field Details

    • next

      public final Node 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

      public Node 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 a Symbol.
      Returns:
      true if the node is a symbol, false otherwise
    • isSymbol

      public boolean isSymbol(String value)
      Tests if this node is a specific Symbol.
      Parameters:
      value - the value of the symbol
      Returns:
      true if the node is that symbol, false otherwise
    • asSymbol

      public Symbol asSymbol()
      Casts this node to a symbol.
      Returns:
      the node as a symbol
      Throws:
      FormatException - if the node is not a symbol
    • asSymbol

      public Symbol asSymbol(String value)
      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 a List.
      Returns:
      true if the node is a list, false otherwise
    • isList

      public boolean isList(int min, int max)
      Tests if this node is a List of a certain length.
      Parameters:
      min - the minimum number of elements the list can have
      max - 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

      public List asList()
      Casts the node to a list.
      Returns:
      the node as a list
      Throws:
      FormatException - if the node is not a list
    • asList

      public List asList(int min, int max)
      Casts the node to a list of a certain length.
      Parameters:
      min - the minimum number of elements the list can have
      max - 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

      public static final Node parse(File file) throws IOException
      Parse a given file as a node.
      Parameters:
      file - the file to parse
      Returns:
      a node
      Throws:
      IOException - if an IO exception occurred while reading the file
    • parse

      public static final Node parse(String string)
      Parse a given string as a node.
      Parameters:
      string - the string to parse
      Returns:
      a node