Class AtomicTerm

  • All Implemented Interfaces:
    Iterable<Term>

    public class AtomicTerm
    extends Term
    AtomicTerms is the class used to represent literal Terms such as String and Numbers. The functor() method for AtomicTerms return a type name for the stored literals.
    Author:
    djl 2009.08.31
    • Field Detail

      • STRINGLITERAL

        public static final int STRINGLITERAL
        The numberic code for a string literal
        See Also:
        Constant Field Values
      • INTEGERLITERAL

        public static final int INTEGERLITERAL
        The numberic code for a integer literal
        See Also:
        Constant Field Values
      • LONGLITERAL

        public static final int LONGLITERAL
        The numberic code for a long literal
        See Also:
        Constant Field Values
      • FLOATLITERAL

        public static final int FLOATLITERAL
        The numberic code for a float literal
        See Also:
        Constant Field Values
      • DOUBLELITERAL

        public static final int DOUBLELITERAL
        The numberic code for a double literal
        See Also:
        Constant Field Values
      • BOOLEANLITERAL

        public static final int BOOLEANLITERAL
        The numberic code for a boolean literal
        See Also:
        Constant Field Values
      • NULLLITERAL

        public static final int NULLLITERAL
        The numberic code for a boolean literal
        See Also:
        Constant Field Values
      • SHORTLITERAL

        public static final int SHORTLITERAL
        The numberic code for a symbol literal
        See Also:
        Constant Field Values
      • SYMBOLLITERAL

        public static final int SYMBOLLITERAL
        The numberic code for a symbol literal
        See Also:
        Constant Field Values
    • Constructor Detail

      • AtomicTerm

        public AtomicTerm​(String sValue,
                          int nType)
        Construct a new AtomicTerm with the given parameters.
        Parameters:
        sValue - the String representation of the literal
        nType - the type code for the given literal
    • Method Detail

      • getTypeCode

        public int getTypeCode()
        Obtain the typecode for the node.
        Returns:
        the typecode
      • getValue

        public String getValue()
        Obtain the string value for the node.
        Returns:
        the string value
      • getFunctor

        public String getFunctor()
        Obtain the functor representation of the Term.
        Specified by:
        getFunctor in class Term
        Returns:
        the functor
      • fullFormString

        public String fullFormString()
        Answer a String representation of the Term that is allowed to show more internal details than toString() which does not compress information. Similar to Object.toString().
        Specified by:
        fullFormString in class Term
        Returns:
        a String representation of the receiver
      • isNumber

        public boolean isNumber()
        Answer whether the receiver is an Atomic Term representing a Number.
        Overrides:
        isNumber in class Term
        Returns:
        the boolean result of the isNumber() test
      • withChild

        public Term withChild​(Term t)
        Join the receiver with the given child Term. AtomicTerms will construct a general list term (functor .list.) and NodeTerms may be mutated.
        Specified by:
        withChild in class Term
        Parameters:
        t - the term to join with
        Returns:
        the Term resulting from joining.
      • children

        public Term[] children()
        Obtain the childern Terms
        Specified by:
        children in class Term
        Returns:
        the children of the receiver
      • termAt

        public Term termAt​(int index)
        Obtain the child term at the given index. The index is 1 based for children and with at(0) returning the functor as an AtomicTerm. Beware, your 0 based habits can cause problems but 1 based indexing is useful since the functor is an interesting part of the information space. We are bowing here to the wisdom of Mathematica Expressions.
        Specified by:
        termAt in class Term
        Parameters:
        index - index of the child or functor to return
        Returns:
        the child Term or functor as AtomicTerm if index is 0
      • findChild

        public Term findChild​(String fn)
        Find the Term amoungst the children whose functor equals the given functor.
        Overrides:
        findChild in class Term
        Parameters:
        fn - the functor to search for
        Returns:
        the found Term or null if not found
      • termEqual

        public boolean termEqual​(Term t)
        Answer whether the receiver is equal to the given Term. Terms are equal if their functors are equal and their children are termEqual to the children of the given term.
        Specified by:
        termEqual in class Term
        Parameters:
        t - the Term to check for termEqual
        Returns:
        the boolean result of the comparison
      • getObject

        public Object getObject()
        Obtain the Object representation of the node. This will be one of the java Types String, Integer, Long, Float, Double, or Boolean.
        Returns:
        the Object
      • getNumber

        public Number getNumber()
        Obtain the Number representation of the node.
        Returns:
        the Comparable
      • negativeNumber

        public Number negativeNumber​(Number num)
        Make negative the given number that supposedly came from this node.
        Parameters:
        num - a Number that was created by this node
        Returns:
        a negated
      • negate

        public void negate()
        Make negavite the representation of this node.
      • isValidNumber

        public boolean isValidNumber()
        Test whether the value is of a valid number format.
        Returns:
        the the results of testing for numeric format validity
      • accept

        public void accept​(TermWalker walker)
        Description copied from class: Term
        Do a dispatch back to the given walker.
        Overrides:
        accept in class Term
        Parameters:
        walker - the TermWalker that implements the visitor for Terms
      • toString

        public String toString()
        Return a human-readable description for this Node.
        Overrides:
        toString in class Object
        Returns:
        a String description of the Node
      • createString

        public static AtomicTerm createString​(String value)
        Create new AtomicTerm representing a String with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a String
      • createShort

        public static AtomicTerm createShort​(String value)
        Create new AtomicTerm representing a Short with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a Integer
      • createInteger

        public static AtomicTerm createInteger​(String value)
        Create new AtomicTerm representing a Integer with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a Integer
      • createLong

        public static AtomicTerm createLong​(String value)
        Create new AtomicTerm representing a Long with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a Long
      • createFloat

        public static AtomicTerm createFloat​(String value)
        Create new AtomicTerm representing a float with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a Float
      • createDouble

        public static AtomicTerm createDouble​(String value)
        Create new AtomicTerm representing a Double with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a Double
      • createBoolean

        public static AtomicTerm createBoolean​(String value)
        Create new AtomicTerm representing a Boolean with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a boolean
      • createNull

        public static AtomicTerm createNull​(String value)
        Create new AtomicTerm representing a null with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a null
      • createNull

        public static AtomicTerm createNull()
        Create new AtomicTerm representing a null.
        Returns:
        a AtomicTerm for a null
      • createSymbol

        public static AtomicTerm createSymbol​(String value)
        Create new AtomicTerm representing a Symbol with given value
        Parameters:
        value - the text of the literal
        Returns:
        a AtomicTerm for a Symbol