ua.gradsoft.termware
Class AbstractPrimitiveTerm

java.lang.Object
  extended by ua.gradsoft.termware.Term
      extended by ua.gradsoft.termware.AbstractPrimitiveTerm
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AtomTerm, BigDecimalTerm, BigIntegerTerm, BooleanTerm, ByteTerm, CharTerm, DoubleTerm, FloatTerm, IntTerm, LongTerm, NILTerm, ShortTerm, StringTerm

public abstract class AbstractPrimitiveTerm
extends Term

this is abstract class for primitive term (i. e. term, which contains primitive value, like int or String)

See Also:
Serialized Form

Constructor Summary
AbstractPrimitiveTerm()
           
 
Method Summary
 boolean boundEquals(Term t)
          equality, when propositional variables are already bounded.
 boolean boundUnify(Term t, Substitution s)
          bound unification.
 Object clone()
           
 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.
abstract  boolean eq(Term x)
           
 int findSubtermIndexBoundEqualsTo(Term x)
           
 boolean freeEquals(Term t)
          Equality when all propositional variables are equal
 boolean freeUnify(Term t, Substitution s)
          free unification
 int getArity()
          get arity (i.
 BigDecimal getBigDecimal()
          get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException
 BigInteger getBigInteger()
          get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException
 boolean getBoolean()
          get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException
 byte getByte()
          get byte value, if this term represent byte, otherwise throw UnsupportedOperationException
 char getChar()
          get char value, if this term represent char, otherwise throw UnsupportedOperationException
 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, if this term represent float, otherwise throw UnsupportedOperationException.
 int getInt()
          get integer value, if this term represent integer, otherwise throw UnsupportedOperationException
 Object getJavaObject()
           
 long getLong()
          get long value, if this term represent long, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to long.
abstract  String getName()
          get name of functional symbol.
 Object getNameIndex()
          get index of name in instance symbol table.
 String getPatternName()
          return name of pattern, for which unification is applicable.
 Object getPatternNameIndex()
          return index of pattern name.
 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)
          throws UnsupporedOperationException
 Term getTerm()
          get term.
 int getXIndex()
          if this variable is a propositional variable, return index of one.
 boolean isAtom()
          is term is atom ?
 boolean isBigDecimal()
          true, if this term is BigDecimal
 boolean isBigInteger()
          true, if this term is BigInteger
 boolean isBoolean()
          is term is booleam ?
 boolean isByte()
          true, if this term is Byte
 boolean isChar()
          is term is char ?
 boolean isComplexTerm()
          true, if this term have subterms
 boolean isDouble()
          is Term is double ?
 boolean isFloat()
          is Term is float ?
 boolean isInt()
          is term is Int ?
 boolean isJavaObject()
          if this term is Java Object ?
 boolean isLong()
          is Term is long ?
 boolean isNil()
          is term is nil ?
 boolean isShort()
          is Term is short ?
 boolean isString()
          is Term is string ?
 boolean isX()
          true if this term is propositional variable.
 int maxFv()
          get maximum index of free propositional variable in term
 int minFv()
          get minimal index of free propositional variable in term.
abstract  void print(PrintWriter out)
          print term to out.
 void setSubtermAt(int i, Term t)
          set i-th subterm to t when i < arity then throw IndexOutOfBoundsException
 void shiftFv(int newMin)
          renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv
 Term subst(Substitution s)
          substitution
 boolean substInside(Substitution s)
          apply substitution s to current term.
abstract  Term termClone()
          clone
abstract  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, getNumber, getPrimaryType0, getPrimaryType1, isNumber, print, println, println
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPrimitiveTerm

public AbstractPrimitiveTerm()
Method Detail

isNil

public boolean isNil()
Description copied from class: Term
is term is nil ?

Specified by:
isNil in class Term
Returns:
false

isAtom

public boolean isAtom()
Description copied from class: Term
is term 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

isByte

public boolean isByte()
Description copied from class: Term
true, if this term is Byte

Specified by:
isByte in class Term

getByte

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

Specified by:
getByte in class Term
Returns:
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()
Description copied from class: Term
is Term is long ?

Specified by:
isLong in class Term
Returns:
true if term represents long value.

getLong

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

Specified by:
getLong in class Term
Returns:
short value

isBigDecimal

public boolean isBigDecimal()
Description copied from class: Term
true, if this term is BigDecimal

Specified by:
isBigDecimal in class Term

getBigDecimal

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

Specified by:
getBigDecimal in class Term
Returns:
number value

isBigInteger

public boolean isBigInteger()
Description copied from class: Term
true, if this term is BigInteger

Specified by:
isBigInteger in class Term

getBigInteger

public BigInteger getBigInteger()
Description copied from class: Term
get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException

Specified by:
getBigInteger in class Term
Returns:
value

isFloat

public boolean isFloat()
Description copied from class: Term
is Term is float ?

Specified by:
isFloat in class Term
Returns:
true if term represents float value.

getFloat

public float getFloat()
Description copied from class: Term
get float value, if this term represent float, otherwise throw UnsupportedOperationException. Note, that getFloat does not provide conversion of other numeric types (such as double) to float. For this use getAsFloat(ITerm t);

Specified by:
getFloat in class Term
Returns:
float value

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

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

isChar

public boolean isChar()
Description copied from class: Term
is term is char ?

Specified by:
isChar in class Term
Returns:
true if this term is char

getChar

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

Specified by:
getChar in class Term
Returns:
char value

isX

public final boolean isX()
Description copied from class: Term
true if this term is propositional variable.

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

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

isComplexTerm

public final 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.

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

getName

public abstract 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

getPatternName

public final String getPatternName()
Description copied from class: Term
return name of pattern, for which unification is applicable. (i. e. if x.getPatternName()="q", than unification is applicable to pattern-name. used for implementing of pattern mathing: for example { x : y } is a pattern for set, where x - element from set, y - rest of set). Name of this term is set_pattern , but pattern name is set

Overrides:
getPatternName in class Term

getPatternNameIndex

public final 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

getXIndex

public final int getXIndex()
Description copied from class: Term
if this variable is a propositional variable, return index of one. Otherwise throw UnsupportedOperationException

Specified by:
getXIndex in class Term

getArity

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

Specified by:
getArity in class Term
Returns:
0

getSubtermAt

public final Term getSubtermAt(int i)
throws UnsupporedOperationException

Specified by:
getSubtermAt in class Term
Parameters:
i - - index of subterm, starting from 0
Returns:
i-th subterm of current term.
Throws:
UnsupportedOperationException
See Also:
Term.getSubtermAt(int i)

setSubtermAt

public final void setSubtermAt(int i,
                               Term t)
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.

freeUnify

public final boolean freeUnify(Term t,
                               Substitution s)
                        throws TermWareException
free unification

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

boundUnify

public boolean boundUnify(Term t,
                          Substitution s)
                   throws TermWareException
bound unification.

Specified by:
boundUnify in class Term
Throws:
TermWareException

subst

public final Term subst(Substitution s)
substitution

Specified by:
subst in class Term

substInside

public final boolean substInside(Substitution s)
Description copied from class: Term
apply substitution s to current term.

Specified by:
substInside in class Term

freeEquals

public final boolean freeEquals(Term t)
                         throws TermWareException
Description copied from class: Term
Equality when all propositional variables are equal

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

boundEquals

public final boolean boundEquals(Term t)
                          throws TermWareException
Description copied from class: Term
equality, when propositional variables are already bounded.

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

eq

public abstract boolean eq(Term x)
                    throws TermWareException
Throws:
TermWareException

termClone

public abstract Term termClone()
clone

Specified by:
termClone in class Term

clone

public final Object clone()
Overrides:
clone in class Object

termCompare

public abstract 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 final int findSubtermIndexBoundEqualsTo(Term x)
                                        throws SubtermNotFoundException
Specified by:
findSubtermIndexBoundEqualsTo in class Term
Throws:
SubtermNotFoundException

createSame

public final Term createSame(Term[] newBody)
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

print

public abstract void print(PrintWriter out)
print term to out. does not expect recursion.

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

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.

minFv

public final int minFv()
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.

maxFv

public final int maxFv()
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.

shiftFv

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

Specified by:
shiftFv in class Term