public class Integer extends Term
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) 1998 Fred Dushin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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.
Modifier and Type | Field and Description |
---|---|
protected java.math.BigInteger |
bigValue
the Integer's immutable BigInteger value, iff too big for a long, else null
|
protected long |
value
the Integer's immutable long value, iff small enough
|
Constructor and Description |
---|
Integer(java.math.BigInteger value) |
Integer(long value) |
Modifier and Type | Method and Description |
---|---|
Term[] |
args()
The arguments of this Term.
|
java.math.BigInteger |
bigValue()
Returns the value of this Integer as a java.math.BigInteger, whether or not it fits in a long
|
double |
doubleValue()
Returns the value of this Integer converted to a double (perhaps Double.NEGATIVE_INFINITY or
Double.POSITIVE_INFINITY)
|
boolean |
equals(java.lang.Object o)
two Integer instances are equal if their values are equal
|
float |
floatValue()
Returns the value of this Integer converted to a float
|
boolean |
hasFunctor(java.math.BigInteger val,
int arity)
whether this Integer's functor has (BigInteger) 'name' and 'arity' (c.f.
|
boolean |
hasFunctor(long val,
int arity)
whether this Integer's functor has (long) 'name' and 'arity' (c.f.
|
int |
hashCode() |
int |
intValue()
Returns the value of this Integer as an int if possible, else throws a JPLException
|
boolean |
isBig()
Tests whether this Integer's value is too big to represent as a long.
|
long |
longValue()
Returns the value of this org.jpl7.Integer as a long
|
protected void |
put(java.util.Map<java.lang.String,term_t> varnames_to_vars,
term_t term)
To convert an Integer into a Prolog term, we put its value into the term_t.
|
java.lang.String |
toString()
a Prolog source text representation of this Integer's value
|
int |
type()
the type of this term, as "Prolog.INTEGER"
|
java.lang.String |
typeName()
the name of the type of this term, as "Integer"
|
arg, arity, atomListToStringArray, atomType, getSubst, getSubsts, getTerm, getTerm, hasFunctor, hasFunctor, intArrayArrayToList, intArrayToList, isAtom, isAtomOfNameType, isBigInteger, isCompound, isFloat, isInteger, isJFalse, isJNull, isJRef, isJTrue, isJVoid, isList, isList, isListNil, isListPair, isVariable, jrefToObject, listLength, listLength, listToTermArray, listToTermArray, name, object, objectToJRef, put, putParams, putParams, putParams1, putParams2, putTerm, putTerms, ref, setName, stringArrayToList, termArrayToList, textParamsToTerm, textToTerm, toString, toTermArray
protected final long value
protected final java.math.BigInteger bigValue
public Integer(long value)
value
- This Integer's intended (long) valuepublic Integer(java.math.BigInteger value)
value
- This Integer's intended (BigInteger) valuepublic Term[] args()
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
public final java.math.BigInteger bigValue()
public final double doubleValue()
doubleValue
in class Term
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- The Object to compare (not necessarily an Integer)public int hashCode()
hashCode
in class java.lang.Object
public final float floatValue()
floatValue
in class Term
public final boolean hasFunctor(long val, int arity)
hasFunctor
in class Term
val
- a possible name for the functor of a termarity
- an arity 0+public final boolean hasFunctor(java.math.BigInteger val, int arity)
hasFunctor
in class Term
val
- a possible name for the functor of a termarity
- an arity 0+public final int intValue()
intValue
in class Term
JPLException
- if the value of this Integer is too great to be represented as a Java intpublic final boolean isBig()
Term
Use this in contexts where the Term is known to be an Integer.
isBig
in class Term
Term.isBigInteger()
public final long longValue()
protected final void put(java.util.Map<java.lang.String,term_t> varnames_to_vars, term_t term)
public java.lang.String toString()
toString
in class java.lang.Object
public final int type()