ua.gradsoft.termware
Class JTerm

java.lang.Object
  extended by ua.gradsoft.termware.Term
      extended by ua.gradsoft.termware.JTerm
All Implemented Interfaces:
Serializable, Cloneable

public class JTerm
extends Term

Term wich incapsulate opaque Java Object.

See Also:
Serialized Form

Constructor Summary
JTerm(Object o)
          construct instance of JTerm from Java Object
 
Method Summary
 boolean boundEquals(Term x)
          equality, when propositional variables are already bounded.
 boolean boundUnify(Term t, Substitution s)
          unification when we already have s and when same propositional variables means same things
 PartialOrderingResult concreteOrder(Term x, Substitution s)
          compare for 'more concrete' relation.
 Term createSame(Term[] newBody)
          create term, with same name but new body.
 boolean emptyFv()
          true, if term does not contains free propositional variables.
 int findSubtermIndexBoundEqualsTo(Term x)
           
 boolean freeEquals(Term x)
          Equality when all propositional variables are equal
 boolean freeUnify(Term t, Substitution s)
          do unification of this and t and store in s substitution.
 int getArity()
          get arity (i.
 BigDecimal getBigDecimal()
          getBigDecimal
 BigInteger getBigInteger()
          get BigInteger value
 boolean getBoolean()
          get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException
 byte getByte()
          get byte value
 char getChar()
          get character value
 double getDouble()
          get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.
 float getFloat()
          get float value
 int getInt()
          get integer value, if this term represent integer, otherwise throw UnsupportedOperationException
 Object getJavaObject()
           
 long getLong()
          get long value
 String getName()
          get name of functional symbol.
 Object getNameIndex()
          get index of name in instance symbol table.
 Number getNumber()
          return Number value of underlaying number term, if one exists.
 String getPatternName()
          return name of pattern, for which unification is applicable.
 Object getPatternNameIndex()
          return index of pattern name.
 int getPrimaryType0()
          get Primary Type
 short getShort()
          get short value, if this term represent short, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to short.
 String getString()
          get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException
 Term getSubtermAt(int i)
          get subterm of current term.
 Term getTerm()
          get term.
 int getXIndex()
          get x index.
 boolean isAtom()
          if this is atom ?
 boolean isBigDecimal()
          if this is BigDecimal
 boolean isBigInteger()
          if this is BigInteger
 boolean isBoolean()
          is term is booleam ?
 boolean isByte()
          if this is Byte
 boolean isChar()
          if this is Char
 boolean isComplexTerm()
          true, if this term have subterms
 boolean isDouble()
          is Term is double ?
 boolean isFloat()
          if this is Float
 boolean isInt()
          is term is Int ?
 boolean isJavaObject()
          if this term is Java Object ?
 boolean isLong()
          if this is long
 boolean isNil()
          is this term is nil ?
 boolean isNumber()
          is term is Number ?
 boolean isShort()
          is Term is short ?
 boolean isString()
          is Term is string ?
 boolean isX()
          if this is x ?
 int maxFv()
          get maximum index of free propositional variable in term
 int minFv()
          get minimal index of free propositional variable in term.
 void print(PrintWriter out)
          print term on out
 void setSubtermAt(int i, Term t)
          set i-th subterm to t when i < arity then throw IndexOutOfBoundsException
 void shiftFv(int newMinFv)
          renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv
 Term subst(Substitution s)
          receive new term, which is sibstution of current term and s
 boolean substInside(Substitution s)
          apply substitution s to current term.
 Term termClone()
          deep clone of term.
 int termCompare(Term x)
          compare functions.
 
Methods inherited from class ua.gradsoft.termware.Term
containsSubtermBoundEqualsTo, getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsJavaObject, getAsLong, getAsNumber, getAsShort, getAsString, getPrimaryType1, print, println, println
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTerm

public JTerm(Object o)
construct instance of JTerm from Java Object

Method Detail

getPrimaryType0

public int getPrimaryType0()
get Primary Type

Specified by:
getPrimaryType0 in class Term
Returns:
code of primary type
See Also:
PrimaryTypes

isNil

public boolean isNil()
is this term is nil ?

Specified by:
isNil in class Term
Returns:
true if this term is Nil

isAtom

public boolean isAtom()
if this is atom ?

Specified by:
isAtom in class Term
Returns:
true if this term is atom

isBoolean

public boolean isBoolean()
Description copied from class: Term
is term is booleam ?

Specified by:
isBoolean in class Term
Returns:
true if this term is boolean

getBoolean

public boolean getBoolean()
Description copied from class: Term
get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException

Specified by:
getBoolean in class Term
Returns:
boolean value

isBigDecimal

public boolean isBigDecimal()
if this is BigDecimal

Specified by:
isBigDecimal in class Term
Returns:
true if inderlaying object is BigDecimal term, otherwise - false

getBigDecimal

public BigDecimal getBigDecimal()
getBigDecimal

Specified by:
getBigDecimal in class Term
Returns:
underlying BigDecimal Object, if one exists. Otherwise throws UnsupportedOperationException

isBigInteger

public boolean isBigInteger()
if this is BigInteger

Specified by:
isBigInteger in class Term
Returns:
true if inderlaying object is BigInteger term, otherwise - false

getBigInteger

public BigInteger getBigInteger()
get BigInteger value

Specified by:
getBigInteger in class Term
Returns:
value of underlaying BigInteger term object, if one exists. Otherwise throws UnsupportedOperationException

isByte

public boolean isByte()
if this is Byte

Specified by:
isByte in class Term
Returns:
true if inderlaying object is byte term, otherwise - false

getByte

public byte getByte()
get byte value

Specified by:
getByte in class Term
Returns:
value underlying byte term object, if one exists. Otherwise throws UnsupportedOperationException

isChar

public boolean isChar()
if this is Char

Specified by:
isChar in class Term
Returns:
true if inderlaying object is character term, otherwise - false

getChar

public char getChar()
get character value

Specified by:
getChar in class Term
Returns:
value of underlying character term object, if one exists. Otherwise throws UnsupportedOperationException

isFloat

public boolean isFloat()
if this is Float

Specified by:
isFloat in class Term
Returns:
true if inderlaying object is Float or FloatTerm, otherwise - false

getFloat

public float getFloat()
get float value

Specified by:
getFloat in class Term
Returns:
underlying character Object, if one exists. Otherwise throws InvalifTypeException

isDouble

public boolean isDouble()
Description copied from class: Term
is Term is double ?

Specified by:
isDouble in class Term
Returns:
true if term represents double value.

getDouble

public double getDouble()
Description copied from class: Term
get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.

Specified by:
getDouble in class Term
Returns:
double value

isShort

public boolean isShort()
Description copied from class: Term
is Term is short ?

Specified by:
isShort in class Term
Returns:
true if term represents short value.

getShort

public short getShort()
Description copied from class: Term
get short value, if this term represent short, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to short. Use ITermHelper.getAsShort(ITerm t, TermWareInstance instance) for this purpose.

Specified by:
getShort in class Term
Returns:
short value

isInt

public boolean isInt()
Description copied from class: Term
is term is Int ?

Specified by:
isInt in class Term
Returns:
true if term represents integer value.

getInt

public int getInt()
Description copied from class: Term
get integer value, if this term represent integer, otherwise throw UnsupportedOperationException

Specified by:
getInt in class Term
Returns:
int value

isLong

public boolean isLong()
if this is long

Specified by:
isLong in class Term
Returns:
true if inderlaying object is LongTerm, otherwise - false

getLong

public long getLong()
get long value

Specified by:
getLong in class Term
Returns:
long value of underlying term, if we hold non-term Object - throws UnsupportedOperationException
Throws:
UnsupportedOperationException

isString

public boolean isString()
Description copied from class: Term
is Term is string ?

Specified by:
isString in class Term
Returns:
true if term represents string value.

getString

public String getString()
Description copied from class: Term
get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException

Specified by:
getString in class Term
Returns:
string value

isX

public boolean isX()
if this is x ?

Specified by:
isX in class Term
Returns:
true if this term is propositional variable

getXIndex

public int getXIndex()
get x index.

Specified by:
getXIndex in class Term

isComplexTerm

public boolean isComplexTerm()
Description copied from class: Term
true, if this term have subterms

Specified by:
isComplexTerm in class Term
Returns:
true if this term have subterms.

getName

public String getName()
Description copied from class: Term
get name of functional symbol.

Specified by:
getName in class Term
Returns:
name

getNameIndex

public Object getNameIndex()
Description copied from class: Term
get index of name in instance symbol table. If name is not inde (during unifications names are compared by indexes. This allows to speedup unification process)

Specified by:
getNameIndex in class Term

getArity

public int getArity()
Description copied from class: Term
get arity (i. e. number of subterms)

Specified by:
getArity in class Term
Returns:
arity of term.

isJavaObject

public final boolean isJavaObject()
Description copied from class: Term
if this term is Java Object ?

Specified by:
isJavaObject in class Term

getJavaObject

public final Object getJavaObject()
Specified by:
getJavaObject in class Term
Returns:
Java Object, if this term holds opaque Java Object, otherwise throw UnsupportedOperationException

getTerm

public Term getTerm()
Description copied from class: Term
get term. Semantics is "return this term". Non-trivial implementations are used for deallocating proxy terms.

Specified by:
getTerm in class Term

getSubtermAt

public Term getSubtermAt(int i)
get subterm of current term.

Specified by:
getSubtermAt in class Term
Parameters:
i - - index of subterm, starting from 0
Returns:
i-th subterm of current term.

setSubtermAt

public void setSubtermAt(int i,
                         Term t)
                  throws TermWareException
Description copied from class: Term
set i-th subterm to t when i < arity then throw IndexOutOfBoundsException

Specified by:
setSubtermAt in class Term
Parameters:
i - - index of subterm to set.
t - - subterm to set.
Throws:
TermWareException

getPatternName

public String getPatternName()
return name of pattern, for which unification is applicable. (i. e. if x.getPatternName()="q", than unification is applicable to pattern-name.

Overrides:
getPatternName in class Term

freeUnify

public boolean freeUnify(Term t,
                         Substitution s)
                  throws TermWareException
do unification of this and t and store in s substitution.

Specified by:
freeUnify in class Term
Returns:
true, if unification was succesfull.
Throws:
TermWareException

boundUnify

public boolean boundUnify(Term t,
                          Substitution s)
                   throws TermWareException
unification when we already have s and when same propositional variables means same things

Specified by:
boundUnify in class Term
Throws:
TermWareException

substInside

public boolean substInside(Substitution s)
                    throws TermWareException
apply substitution s to current term.

Specified by:
substInside in class Term
Throws:
TermWareException

subst

public Term subst(Substitution s)
           throws TermWareException
receive new term, which is sibstution of current term and s

Specified by:
subst in class Term
Throws:
TermWareException

freeEquals

public boolean freeEquals(Term x)
                   throws TermWareException
Equality when all propositional variables are equal

Specified by:
freeEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are free-equals.
Throws:
TermWareException

boundEquals

public boolean boundEquals(Term x)
                    throws TermWareException
equality, when propositional variables are already bounded.

Specified by:
boundEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are equals.
Throws:
TermWareException

termClone

public Term termClone()
               throws TermWareException
Description copied from class: Term
deep clone of term. (only immunitable terms are not cloned)

Specified by:
termClone in class Term
Throws:
TermWareException

termCompare

public int termCompare(Term x)
Description copied from class: Term
compare functions. define ordering on set of terms. Note, that ordering is not the same as Java build-in compare.

Specified by:
termCompare in class Term
Parameters:
x - - term to compare

concreteOrder

public PartialOrderingResult concreteOrder(Term x,
                                           Substitution s)
                                    throws TermWareException
Description copied from class: Term
compare for 'more concrete' relation. i. e. x.<(concrete)<(y) means, that for each substitution of free variables sx exists substituion sy : x[sx] = y[sy] .
Substitution s store previously matched variables.

Specified by:
concreteOrder in class Term
Throws:
TermWareException

findSubtermIndexBoundEqualsTo

public int findSubtermIndexBoundEqualsTo(Term x)
                                  throws TermWareException
Specified by:
findSubtermIndexBoundEqualsTo in class Term
Throws:
TermWareException

minFv

public int minFv()
          throws TermWareException
Description copied from class: Term
get minimal index of free propositional variable in term.

Specified by:
minFv in class Term
Returns:
index of propositional variable with minimal index.
Throws:
TermWareException

maxFv

public int maxFv()
          throws TermWareException
Description copied from class: Term
get maximum index of free propositional variable in term

Specified by:
maxFv in class Term
Returns:
index of propositional variable with maximal index.
Throws:
TermWareException

shiftFv

public void shiftFv(int newMinFv)
             throws TermWareException
Description copied from class: Term
renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv

Specified by:
shiftFv in class Term
Throws:
TermWareException

emptyFv

public final boolean emptyFv()
Description copied from class: Term
true, if term does not contains free propositional variables. (fv-set for this term is empty.)

Specified by:
emptyFv in class Term
Returns:
true, if fv_set does not contains free proporsitional variables.

createSame

public final Term createSame(Term[] newBody)
                      throws TermWareException
Description copied from class: Term
create term, with same name but new body. If this term have arity 0, or other than original - throws exception.

Specified by:
createSame in class Term
Throws:
TermWareException

isNumber

public boolean isNumber()
Description copied from class: Term
is term is Number ?

Specified by:
isNumber in class Term
Returns:
true if term represents number value.

getNumber

public Number getNumber()
return Number value of underlaying number term, if one exists.

Specified by:
getNumber in class Term
Returns:
number value

getPatternNameIndex

public Object getPatternNameIndex()
Description copied from class: Term
return index of pattern name. (If term is adopted to current instance - index in instance symbol table, or just name)

Overrides:
getPatternNameIndex in class Term

print

public void print(PrintWriter out)
Description copied from class: Term
print term on out

Specified by:
print in class Term
Parameters:
out - - PrintWriter, where to print term.