Class SList.Mutator

java.lang.Object
com.mackenziehigh.sexpr.SList.Mutator
Enclosing class:
SList

public final class SList.Mutator extends Object
An instance of this interface simplifies the modification of symbolic-expressions, since they are immutable.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Mutator(SList node)
    Sole Public Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(Sexpr<?> value)
    This method appends the given value onto the selected node, if the selected node is a symbolic-list.
    This method selects the first element in the currently selected list node().
    get(int index)
    This method selects an element in the currently selected list node().
    This method selects the last element in the currently selected list node().
    This method retrieves the currently selected node.
    prepend(Sexpr<?> value)
    This method prepends the given value onto the selected node, if the selected node is a symbolic-list.
    set(Sexpr<?> value)
    This method sets the selected node to the given value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Mutator

      public Mutator(SList node)
      Sole Public Constructor.
      Parameters:
      node - is the root of a symbolic-expression tree.
  • Method Details

    • append

      public SList append(Sexpr<?> value)
      This method appends the given value onto the selected node, if the selected node is a symbolic-list.
      Parameters:
      value - is the value to append onto the node().
      Returns:
      a modified copy of the symbolic-expression.
      Throws:
      IllegalStateException - if node().isList() is false.
    • prepend

      public SList prepend(Sexpr<?> value)
      This method prepends the given value onto the selected node, if the selected node is a symbolic-list.
      Parameters:
      value - is the value to prepend onto the node().
      Returns:
      a modified copy of the symbolic-expression.
      Throws:
      IllegalStateException - if node().isList() is false.
    • set

      public SList set(Sexpr<?> value)
      This method sets the selected node to the given value.
      Parameters:
      value - will replace the node() in the tree.
      Returns:
      a modified copy of the symbolic-expression.
      Throws:
      IllegalStateException - if the selected node is the root of the tree.
    • first

      public SList.Mutator first()
      This method selects the first element in the currently selected list node().
      Returns:
      a new instance of this class, which encodes this action.
      Throws:
      IllegalStateException - if node().isList() is false.
      IndexOutOfBoundsException - if node() is the list is empty.
    • last

      public SList.Mutator last()
      This method selects the last element in the currently selected list node().
      Returns:
      a new instance of this class, which encodes this action.
      Throws:
      IllegalStateException - if node().isList() is false.
      IndexOutOfBoundsException - if node() is the list is empty.
    • get

      public SList.Mutator get(int index)
      This method selects an element in the currently selected list node().
      Parameters:
      index - is the index of the element to select.
      Returns:
      a new instance that encodes this action.
      Throws:
      IllegalStateException - if node().isList() is false.
      IndexOutOfBoundsException - if node() is the list is empty.
    • node

      public Sexpr<?> node()
      This method retrieves the currently selected node.
      Returns:
      the selected node.
    • toString

      public String toString()
      Overrides:
      toString in class Object