Class SAtom

java.lang.Object
com.mackenziehigh.sexpr.SAtom
All Implemented Interfaces:
Sexpr<SAtom>, Comparable<Sexpr<?>>

public final class SAtom extends Object implements Sexpr<SAtom>
Symbolic Atom.

All instances of this interface are immutable.

  • Method Details

    • fromBoolean

      public static SAtom fromBoolean(boolean value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromChar

      public static SAtom fromChar(char value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromByte

      public static SAtom fromByte(byte value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromShort

      public static SAtom fromShort(short value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromInt

      public static SAtom fromInt(int value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromLong

      public static SAtom fromLong(long value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromFloat

      public static SAtom fromFloat(float value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromDouble

      public static SAtom fromDouble(double value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromString

      public static SAtom fromString(String value)
      Factory Method.
      Parameters:
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromBoolean

      public static SAtom fromBoolean(SourceLocation location, boolean value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromChar

      public static SAtom fromChar(SourceLocation location, char value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromByte

      public static SAtom fromByte(SourceLocation location, byte value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromShort

      public static SAtom fromShort(SourceLocation location, short value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromInt

      public static SAtom fromInt(SourceLocation location, int value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromLong

      public static SAtom fromLong(SourceLocation location, long value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromFloat

      public static SAtom fromFloat(SourceLocation location, float value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromDouble

      public static SAtom fromDouble(SourceLocation location, double value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • fromString

      public static SAtom fromString(SourceLocation location, String value)
      Factory Method.
      Parameters:
      location - will be the location() of the new atom.
      value - will be the content() of the new atom.
      Returns:
      the new atom.
    • content

      public String content()
      This method retrieves the series of characters that this atom contains.
      Returns:
      the content of this atom.
    • escaped

      public String escaped()
      This method returns the content() with all special characters escaped.
      Returns:
      the escaped content().
    • isAtom

      public boolean isAtom()
      This method determines whether this object is a SAtom.
      Specified by:
      isAtom in interface Sexpr<SAtom>
      Returns:
      true, iff this object is a SAtom.
    • isList

      public boolean isList()
      This method determines whether this object is a SList.
      Specified by:
      isList in interface Sexpr<SAtom>
      Returns:
      true, iff this object is a SAtom.
    • bfs

      public boolean bfs(Predicate<Sexpr<?>> condition)
      This method performs a breadth-first-search of the tree rooted at this node.
      Specified by:
      bfs in interface Sexpr<SAtom>
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • dfs

      public boolean dfs(Predicate<Sexpr<?>> condition)
      This method performs a depth-first-search of the tree rooted at this node.
      Specified by:
      dfs in interface Sexpr<SAtom>
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • preorder

      public boolean preorder(Predicate<Sexpr<?>> condition)
      This method performs a pre-order-search of the tree rooted at this node.
      Specified by:
      preorder in interface Sexpr<SAtom>
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • postorder

      public boolean postorder(Predicate<Sexpr<?>> condition)
      This method performs a post-order-search of the tree rooted at this node.
      Specified by:
      postorder in interface Sexpr<SAtom>
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • traverse

      public void traverse(Consumer<Sexpr<?>> before, Consumer<Sexpr<?>> after)
      This method performs a traversal of the tree rooted at this node.
      Specified by:
      traverse in interface Sexpr<SAtom>
      Parameters:
      before - will be invoked upon entering each sub-tree.
      after - will be invoked upon exiting each sub-tree.
    • asBoolean

      public Optional<Boolean> asBoolean()
      This method retrieves this value, as a boolean.

      If toString() equals (ignoring case) "true", "yes", "on", "T", or "1", then this method will return a true result.

      If toString() equals (ignoring case) "false", "no", "off", "F", or "0", then this method will return a false result.

      Returns:
      the value, if possible.
    • asChar

      public Optional<Character> asChar()
      This method retrieves this value, as a char.
      Returns:
      the value, if possible.
    • asByte

      public Optional<Byte> asByte()
      This method retrieves this value, as a byte.
      Returns:
      the value, if possible.
    • asShort

      public Optional<Short> asShort()
      This method retrieves this value, as a short.
      Returns:
      the value, if possible.
    • asInt

      public Optional<Integer> asInt()
      This method retrieves this value, as an integer.
      Returns:
      the value, if possible.
    • asLong

      public Optional<Long> asLong()
      This method retrieves this value, as a long.
      Returns:
      the value, if possible.
    • asFloat

      public Optional<Float> asFloat()
      This method retrieves this value, as a float.
      Returns:
      the value, if possible.
    • asDouble

      public Optional<Double> asDouble()
      This method retrieves this value, as a float.
      Returns:
      the value, if possible.
    • treeHeight

      public int treeHeight()
      This method determines the height of the tree rooted at this node.

      This is a constant-time operation.

      Specified by:
      treeHeight in interface Sexpr<SAtom>
      Returns:
      the height of this tree.
    • treeLeafCount

      public int treeLeafCount()
      This method counts the leaf nodes in the tree rooted at this node.

      This is a constant-time operation.

      Specified by:
      treeLeafCount in interface Sexpr<SAtom>
      Returns:
      the number of leaf nodes.
    • treeSize

      public int treeSize()
      This method counts the nodes in the tree rooted at this node.

      This is a constant-time operation.

      Specified by:
      treeSize in interface Sexpr<SAtom>
      Returns:
      the number of nodes, including this node.
    • location

      public SourceLocation location()
      This method retrieves an object describing the source from which this object we obtained.
      Specified by:
      location in interface Sexpr<SAtom>
      Returns:
      the source-code location of this node.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      This method retrieves the textual representation of this symbolic expression.
      Specified by:
      toString in interface Sexpr<SAtom>
      Overrides:
      toString in class Object
      Returns:
      this object as a string.