Class Integer
- java.lang.Object
-
- org.jpl7.Term
-
- org.jpl7.Integer
-
public class Integer extends Term
Integer is a specialised Term representing a Prolog integer value; if the value fits, it is held in a long field, else as a BigInteger.Integer i = new Integer(1024);
Once constructed, the value of an Integer instance cannot be altered. An Integer can be used (and re-used) as an argument of Compounds. Beware confusing jpl.Integer with java.lang.Integer.
Copyright (C) 2004 Paul SingletonCopyright (C) 1998 Fred Dushin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Term[]args()The arguments of this Term.java.math.BigIntegerbigValue()Returns the value of this Integer as a java.math.BigInteger, whether or not it fits in a longdoubledoubleValue()Returns the value of this Integer converted to a double (perhaps Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY)booleanequals(java.lang.Object obj)two Integer instances are equal if their values are equalfloatfloatValue()Returns the value of this Integer converted to a floatbooleanhasFunctor(long val, int arity)whether this Integer's functor has (long) 'name' and 'arity' (c.f.booleanhasFunctor(java.math.BigInteger val, int arity)whether this Integer's functor has (BigInteger) 'name' and 'arity' (c.f.intintValue()Returns the value of this Integer as an int if possible, else throws a JPLExceptionbooleanisBig()Tests whether this Integer's value is too big to represent as a long.longlongValue()Returns the value of this org.jpl7.Integer as a longjava.lang.StringtoString()a Prolog source text representation of this Integer's valueinttype()the type of this term, as "Prolog.INTEGER"java.lang.StringtypeName()the name of the type of this term, as "Integer"-
Methods inherited from class org.jpl7.Term
arg, arity, atomType, hasFunctor, hasFunctor, isAtom, isBigInteger, isCompound, isFloat, isInteger, isJFalse, isJNull, isJRef, isJTrue, isJVoid, isListNil, isListPair, isVariable, jrefToObject, listLength, name, object, objectToJRef, putParams, putTerm, ref, toString, toTermArray
-
-
-
-
Method Detail
-
args
public Term[] args()
Description copied from class:TermThe arguments of this Term.Note that a SWI Prolog 7.x compound term can have zero arguments.
This method returns an empty Term[] from an Atom, Float, Integer or JRef, approximating the behaviour of SWI Prolog's =../2
-
bigValue
public final java.math.BigInteger bigValue()
Returns the value of this Integer as a java.math.BigInteger, whether or not it fits in a long
-
doubleValue
public final double doubleValue()
Returns the value of this Integer converted to a double (perhaps Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY)- Overrides:
doubleValuein classTerm- Returns:
- the value of this Integer converted to a double (perhaps Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY)
-
equals
public final boolean equals(java.lang.Object obj)
two Integer instances are equal if their values are equal- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The Object to compare (not necessarily an Integer)- Returns:
- true if the Object satisfies the above condition
-
floatValue
public final float floatValue()
Returns the value of this Integer converted to a float- Overrides:
floatValuein classTerm- Returns:
- the value of this Integer converted to a float
-
hasFunctor
public final boolean hasFunctor(long val, int arity)whether this Integer's functor has (long) 'name' and 'arity' (c.f. traditional functor/3)- Overrides:
hasFunctorin classTerm- Parameters:
val- a possible name for the functor of a termarity- an arity 0+- Returns:
- whether this Integer's functor has (long) 'name' and 'arity'
-
hasFunctor
public final boolean hasFunctor(java.math.BigInteger val, int arity)whether this Integer's functor has (BigInteger) 'name' and 'arity' (c.f. traditional functor/3)- Overrides:
hasFunctorin classTerm- Parameters:
val- a possible name for the functor of a termarity- an arity 0+- Returns:
- whether this Integer's functor has (BigInteger) 'name' and 'arity'
-
intValue
public final int intValue()
Returns the value of this Integer as an int if possible, else throws a JPLException- Overrides:
intValuein classTerm- Returns:
- the int value of this Integer
- Throws:
JPLException- if the value of this Integer is too great to be represented as a Java int
-
isBig
public final boolean isBig()
Description copied from class:TermTests whether this Integer's value is too big to represent as a long.Use this in contexts where the Term is known to be an Integer.
- Overrides:
isBigin classTerm- Returns:
- whether this Integer's value is too big to represent as a long
- See Also:
Term.isBigInteger()
-
longValue
public final long longValue()
Returns the value of this org.jpl7.Integer as a long
-
toString
public java.lang.String toString()
a Prolog source text representation of this Integer's value- Overrides:
toStringin classjava.lang.Object- Returns:
- a Prolog source text representation of this Integer's value
-
type
public final int type()
the type of this term, as "Prolog.INTEGER"
-
-