Class IntegerNumber

  • All Implemented Interfaces:
    ArithmeticOperator, Numeric, Term

    public final class IntegerNumber
    extends java.lang.Object
    implements Numeric
    Represents a value of the primitive type long as a Term.

    IntegerNumbers are constant; their values cannot be changed after they are created. IntegerNumbers have no arguments.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long value  
    • Constructor Summary

      Constructors 
      Constructor Description
      IntegerNumber​(long value)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void backtrack()
      Reverts this term back to its original state prior to any unifications.
      IntegerNumber calculate​(Term[] args)
      Returns the result of the calculation using the specified arguments.
      IntegerNumber copy​(java.util.Map<Variable,​Variable> sharedVariables)
      Returns a copy of this term.
      boolean equals​(java.lang.Object o)  
      Term[] getArgs()
      Returns an array of this terms's arguments.
      Term getArgument​(int index)
      Returns the term at the specified position in this term's arguments.
      double getDouble()
      Returns the value of this numeric as a double.
      long getLong()
      Returns the value of this numeric as a long.
      java.lang.String getName()
      Returns a String representation of the long this term represents.
      int getNumberOfArguments()
      Returns the number of arguments in this term.
      IntegerNumber getTerm()
      Returns the current instantiated state of this term.
      TermType getType()
      int hashCode()  
      boolean isImmutable()
      Returns true is this term is immutable.
      java.lang.String toString()  
      boolean unify​(Term t)
      Attempts to unify this term to the specified term.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.projog.core.term.Term

        getBound
    • Field Detail

      • value

        private final long value
    • Constructor Detail

      • IntegerNumber

        public IntegerNumber​(long value)
        Parameters:
        value - the value this term represents
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns a String representation of the long this term represents.
        Specified by:
        getName in interface Term
        Returns:
        a String representation of the long this term represents
      • getArgs

        public Term[] getArgs()
        Description copied from interface: Term
        Returns an array of this terms's arguments.

        Note: for performance reasons the array returned is the same array used internally be the term instance so be careful not to alter the array returned as changes will be reflected in the original term.

        Specified by:
        getArgs in interface Term
        Returns:
        array of this terms's arguments
        See Also:
        Term.getArgument(int)
      • getNumberOfArguments

        public int getNumberOfArguments()
        Description copied from interface: Term
        Returns the number of arguments in this term.
        Specified by:
        getNumberOfArguments in interface Term
        Returns:
        number of arguments in this term
      • getArgument

        public Term getArgument​(int index)
        Description copied from interface: Term
        Returns the term at the specified position in this term's arguments.
        Specified by:
        getArgument in interface Term
        Parameters:
        index - index of the argument to return
        Returns:
        the term at the specified position in this term's arguments
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - as this implementation of Term has no arguments
      • isImmutable

        public boolean isImmutable()
        Description copied from interface: Term
        Returns true is this term is immutable.

        A term is considered immutable if its value will never change as a result of executing its Term.unify(Term) or Term.backtrack() methods. A term will not be considered immutable if it is a Variable or any of its arguments are not immutable.

        Specified by:
        isImmutable in interface Term
        Returns:
        true is this term is immutable
      • getTerm

        public IntegerNumber getTerm()
        Description copied from interface: Term
        Returns the current instantiated state of this term.

        Returns a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.

        Specified by:
        getTerm in interface Term
        Returns:
        a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.
      • copy

        public IntegerNumber copy​(java.util.Map<Variable,​Variable> sharedVariables)
        Description copied from interface: Term
        Returns a copy of this term.

        The returned copy will share any immutable terms contained in this term. The returned copy will contain new instances for any Variables contained in this term. The sharedVariables parameter keeps track of which Variables have already been copied.

        Specified by:
        copy in interface Term
        Parameters:
        sharedVariables - keeps track of which Variables have already been copied (key = original version, value = version used in copy)
        Returns:
        a copy of this term
      • unify

        public boolean unify​(Term t)
        Description copied from interface: Term
        Attempts to unify this term to the specified term.

        The rules for deciding if two terms are unifiable are as follows:

        • An uninstantiated Variable will unify with any term. As a result the Variable will become instantiated to the other term. The instantiaton will be undone when Term.backtrack() is next called on the Variable
        • Non-variable terms will unify with other terms that are of the same TermType and have the same value. The exact meaning of "having the same value" will vary between term types but will include that the two terms being unified have the same number of arguments and that all of their corresponding arguments unify.
        Note: can leave things in "half-state" on failure as neither List or Predicate backtrack earlier args.
        Specified by:
        unify in interface Term
        Parameters:
        t - the term to unify this term against
        Returns:
        true if the attempt to unify this term to the given term was successful
        See Also:
        Term.backtrack()
      • backtrack

        public void backtrack()
        Description copied from interface: Term
        Reverts this term back to its original state prior to any unifications.

        Makes all Variables that this term consists of uninstantiated.

        Specified by:
        backtrack in interface Term
        See Also:
        Term.unify(Term)
      • getLong

        public long getLong()
        Description copied from interface: Numeric
        Returns the value of this numeric as a long.
        Specified by:
        getLong in interface Numeric
        Returns:
        the long value of this term
      • getDouble

        public double getDouble()
        Description copied from interface: Numeric
        Returns the value of this numeric as a double.
        Specified by:
        getDouble in interface Numeric
        Returns:
        the long value of this term cast to a double
      • calculate

        public IntegerNumber calculate​(Term[] args)
        Description copied from interface: ArithmeticOperator
        Returns the result of the calculation using the specified arguments.
        Specified by:
        calculate in interface ArithmeticOperator
        Parameters:
        args - the arguments to use in the calculation
        Returns:
        the result of the calculation using the specified arguments
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of the long this term represents