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 java.lang.Object
The abstract parent class of List and Symbol.
Author:
Stephen G. Ware
  • Field Summary

    Fields 
    Modifier and Type Field Description
    Node next
    The node that follows this node (i.e.
  • 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 a List.
    boolean isList​(int min, int max)
    Tests if this node is a List of a certain length.
    boolean isSymbol()
    Tests if this node is a Symbol.
    boolean isSymbol​(java.lang.String value)
    Tests if this node is a specific Symbol.
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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​(java.lang.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​(java.lang.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​(java.io.File file) throws java.io.IOException
      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

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