Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

alice.tuprolog
Class Struct  view Struct download Struct.java

java.lang.Object
  extended byalice.tuprolog.Term
      extended byalice.tuprolog.Struct
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Struct
extends Term

Struct class represents both compound prolog term and alphanumeric atom term (considered as 0-arity compound).


Field Summary
 Term[] arg
          args array
 int arity
          arity of the structure note: 0 -> string atom
private  java.lang.Object[] builtin_args
          for optimization purposes
(package private)  int code
           
 java.lang.String functor
          pure name of the structure note: without arity indication
(package private)  int hash
          to speedup hash map operation
private  java.lang.Object library
          lib object where the builtins are defined
private  java.lang.reflect.Method method
          method (of the lib object) representing the builtin behaviour
 
Fields inherited from class alice.tuprolog.Term
FALSE, FLOAT, id, INT, NULL, OBJECT, STRUCT, TRUE, VAR
 
Constructor Summary
  Struct()
          empty list constructor
private Struct(int a)
           
  Struct(java.lang.String f)
          atom
private Struct(java.lang.String f, int ar)
           
  Struct(java.lang.String f, alice.util.LinkedList al)
          1-arity constructor - providing arg linked list
  Struct(java.lang.String f, Term at0)
          1-arity constructor
  Struct(java.lang.String f, Term[] argList)
          n-arity constructor - providing arg list
  Struct(java.lang.String f, Term at0, Term at1)
          2-arity constructor
  Struct(java.lang.String f, Term at0, Term at1, Term at2)
          3-arity constructor
  Struct(java.lang.String f, Term at0, Term at1, Term at2, Term at3)
          4-arity constructor
  Struct(java.lang.String f, Term at0, Term at1, Term at2, Term at3, Term at4)
          5-arity constructor
  Struct(java.lang.String f, Term at0, Term at1, Term at2, Term at3, Term at4, Term at5)
          6-arity constructor
  Struct(java.lang.String f, Term at0, Term at1, Term at2, Term at3, Term at4, Term at5, Term at6)
          7-arity constructor
  Struct(Term h, Term t)
          constructor for list providing head and tail
 
Method Summary
 void append(Term t)
          significant only for list compound: appends an element to the list compound
 void bindToBuiltinFunctor(java.lang.Object lib)
          links this compound to builtin functor method execution of an object
 void bindToBuiltinPredicate(java.lang.Object lib)
          links this compound to builtin predicate method execution of an object
 Term copy(alice.util.LinkedList vl)
          gets a copy (with renamed variables) of the term.
 boolean equals(java.lang.Object t)
          Determine whether this Object is semantically equal to another Object.
 Term evalAsBuiltinFunctor()
          invokes the built-in functor linked to the compound
 boolean evalAsBuiltinPredicate()
          invokes the built-in predicate linked to the compound
 void free(int m)
          significant for Var terms.
 Struct fromList()
          gets a flat Struct from a list compound
 java.lang.String getName()
          significant only for Var and Struct derived class.
 java.lang.String getString(int index)
          significant only for Struct derived class.
 Struct getStruct(int index)
          gets the i-th arg as a Struct
 Struct getStruct(java.lang.String name)
          gets the first arg which is a compound with functor specified
 Term getTerm()
          gets the actual term of the object.
 Term getTerm(int index)
          gets the i-th arg as a Term
 Term getVar(java.lang.String name)
          gets the first arg which is a variable with functor specified
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 void insert(Term t)
          significant only for list compound: head insertion
 boolean isAny()
          is it a prolog any(_) variable?
 boolean isAtom()
          is it a prolog (alphanumeric) atom?
 boolean isBuiltinFunctor()
          tests for bultin functor
 boolean isBuiltinPredicate()
          tests for bultin predicate
 boolean isClause()
          is it a prolog clause?
 boolean isCompound()
          is it a prolog compound term?
 boolean isConst()
          is it a constant prolog term?
 boolean isEmptyList()
          is it a prolog empty list?
 boolean isEQU(Term t)
          is term equal to term t?
 boolean isFalse()
          is it a prolog false atom?
 boolean isGround()
          is it a ground term?
 boolean isGT(Term t)
          is term greater than term t?
 boolean isList()
          is it a prolog list?
 boolean isNum()
          is it a prolog numeric term?
 boolean isTrue()
          is it a prolog true atom?
 java.util.Iterator iterator()
          for list compound
 Term listHead()
          significant only for list compound: gets the head
 Struct listTail()
          significant only for list compound: gets the tail
 boolean match(Term t)
          matching without unification; only true or false, without bindings.
private  void readObject(java.io.ObjectInputStream in)
           
(package private)  int renameVars(alice.util.LinkedList vars, int count)
           
 int resolveVarTimes(alice.util.LinkedList vars, int count)
           
 java.lang.Object[] toArray()
          gets an array from a list compound
 Struct toList()
          gets a list Struct from a flat Struct
 java.lang.String toRawString()
          as toString but without eventually present '' in functor string
 java.lang.String toString()
          stringizing the Struct, with different representation for list, atom, compound
private  java.lang.String toString0()
           
(package private)  java.lang.String toStringAsArg(OperatorManager op, int prio, boolean x)
          stringize term as operator of priority prio.
(package private)  java.lang.String toStringAsList(OperatorManager op)
           
 void unbind()
          unlinks compound from builtin
 boolean unify(Term t, int m)
          tries to unify a term with the provided term argument.
private  void writeObject(java.io.ObjectOutputStream out)
          serialization: in order to avoid the serialization of library and method fields nullify them
 
Methods inherited from class alice.tuprolog.Term
clone, getDouble, getFloat, getInt, getIterator, getLong, getObject, getObject, isFloat, isInt, isObject, isStruct, isVar, parse, parse, parseSentence, renameVars, toString, toStringAsArgX, toStringAsArgY
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

functor

public java.lang.String functor
pure name of the structure note: without arity indication


arity

public int arity
arity of the structure note: 0 -> string atom


arg

public Term[] arg
args array


hash

int hash
to speedup hash map operation


code

int code

method

private java.lang.reflect.Method method
method (of the lib object) representing the builtin behaviour


library

private java.lang.Object library
lib object where the builtins are defined


builtin_args

private java.lang.Object[] builtin_args
for optimization purposes

Constructor Detail

Struct

public Struct(java.lang.String f)
atom


Struct

public Struct(java.lang.String f,
              Term at0)
1-arity constructor


Struct

public Struct(java.lang.String f,
              Term at0,
              Term at1)
2-arity constructor


Struct

public Struct(java.lang.String f,
              Term at0,
              Term at1,
              Term at2)
3-arity constructor


Struct

public Struct(java.lang.String f,
              Term at0,
              Term at1,
              Term at2,
              Term at3)
4-arity constructor


Struct

public Struct(java.lang.String f,
              Term at0,
              Term at1,
              Term at2,
              Term at3,
              Term at4)
5-arity constructor


Struct

public Struct(java.lang.String f,
              Term at0,
              Term at1,
              Term at2,
              Term at3,
              Term at4,
              Term at5)
6-arity constructor


Struct

public Struct(java.lang.String f,
              Term at0,
              Term at1,
              Term at2,
              Term at3,
              Term at4,
              Term at5,
              Term at6)
7-arity constructor


Struct

public Struct(java.lang.String f,
              Term[] argList)
n-arity constructor - providing arg list


Struct

public Struct(java.lang.String f,
              alice.util.LinkedList al)
1-arity constructor - providing arg linked list


Struct

public Struct()
empty list constructor


Struct

public Struct(Term h,
              Term t)
constructor for list providing head and tail


Struct

private Struct(int a)

Struct

private Struct(java.lang.String f,
               int ar)
Method Detail

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


equals

public boolean equals(java.lang.Object t)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


toList

public Struct toList()
gets a list Struct from a flat Struct


fromList

public Struct fromList()
gets a flat Struct from a list compound


toArray

public java.lang.Object[] toArray()
gets an array from a list compound


listHead

public Term listHead()
significant only for list compound: gets the head


listTail

public Struct listTail()
significant only for list compound: gets the tail


append

public void append(Term t)
significant only for list compound: appends an element to the list compound


insert

public void insert(Term t)
significant only for list compound: head insertion


getString

public java.lang.String getString(int index)
Description copied from class: Term
significant only for Struct derived class.

Overrides:
getString in class Term

getName

public java.lang.String getName()
Description copied from class: Term
significant only for Var and Struct derived class.

Overrides:
getName in class Term

getTerm

public Term getTerm(int index)
gets the i-th arg as a Term

Overrides:
getTerm in class Term

getStruct

public Struct getStruct(int index)
gets the i-th arg as a Struct

Overrides:
getStruct in class Term

getStruct

public Struct getStruct(java.lang.String name)
gets the first arg which is a compound with functor specified

Overrides:
getStruct in class Term

getVar

public Term getVar(java.lang.String name)
gets the first arg which is a variable with functor specified

Overrides:
getVar in class Term

getTerm

public Term getTerm()
Description copied from class: Term
gets the actual term of the object.

if the Term is a bound variable, the method get the Term linked to the variable

Overrides:
getTerm in class Term

isConst

public boolean isConst()
Description copied from class: Term
is it a constant prolog term?

Overrides:
isConst in class Term

isNum

public boolean isNum()
Description copied from class: Term
is it a prolog numeric term?

Overrides:
isNum in class Term

isCompound

public boolean isCompound()
Description copied from class: Term
is it a prolog compound term?

Overrides:
isCompound in class Term

isAtom

public boolean isAtom()
Description copied from class: Term
is it a prolog (alphanumeric) atom?

Overrides:
isAtom in class Term

isClause

public boolean isClause()
Description copied from class: Term
is it a prolog clause?

Overrides:
isClause in class Term

isList

public boolean isList()
Description copied from class: Term
is it a prolog list?

Overrides:
isList in class Term

isEmptyList

public boolean isEmptyList()
Description copied from class: Term
is it a prolog empty list?

Overrides:
isEmptyList in class Term

isTrue

public boolean isTrue()
Description copied from class: Term
is it a prolog true atom?

Overrides:
isTrue in class Term

isFalse

public boolean isFalse()
Description copied from class: Term
is it a prolog false atom?

Overrides:
isFalse in class Term

isAny

public boolean isAny()
Description copied from class: Term
is it a prolog any(_) variable?

Overrides:
isAny in class Term

isGround

public boolean isGround()
Description copied from class: Term
is it a ground term?

Overrides:
isGround in class Term

unify

public boolean unify(Term t,
                     int m)
Description copied from class: Term
tries to unify a term with the provided term argument.

Try the unification among the term and the term specified The unification is qualified with the integer passed as argument m in order to make reverisble unification using free(int), passing a code >= of m

Overrides:
unify in class Term

match

public boolean match(Term t)
Description copied from class: Term
matching without unification; only true or false, without bindings.

Overrides:
match in class Term

free

public void free(int m)
Description copied from class: Term
significant for Var terms.

Overrides:
free in class Term

copy

public Term copy(alice.util.LinkedList vl)
Description copied from class: Term
gets a copy (with renamed variables) of the term.

the list argument passed contains the list of variables to be renamed (if empty list then no renaming)

Overrides:
copy in class Term

renameVars

int renameVars(alice.util.LinkedList vars,
               int count)
Overrides:
renameVars in class Term

resolveVarTimes

public int resolveVarTimes(alice.util.LinkedList vars,
                           int count)

isGT

public boolean isGT(Term t)
Description copied from class: Term
is term greater than term t?

Overrides:
isGT in class Term

isEQU

public boolean isEQU(Term t)
Description copied from class: Term
is term equal to term t?

Overrides:
isEQU in class Term

toString

public java.lang.String toString()
stringizing the Struct, with different representation for list, atom, compound

Overrides:
toString in class Term

toRawString

public java.lang.String toRawString()
as toString but without eventually present '' in functor string

Overrides:
toRawString in class Term

toString0

private java.lang.String toString0()

toStringAsList

java.lang.String toStringAsList(OperatorManager op)

toStringAsArg

java.lang.String toStringAsArg(OperatorManager op,
                               int prio,
                               boolean x)
Description copied from class: Term
stringize term as operator of priority prio.

x true then X arg, if false then Y arg; actually for example +(a,*(b,c)) becomes 5+6*3

significant only for Struct Term

Overrides:
toStringAsArg in class Term

evalAsBuiltinPredicate

public boolean evalAsBuiltinPredicate()
invokes the built-in predicate linked to the compound


evalAsBuiltinFunctor

public Term evalAsBuiltinFunctor()
invokes the built-in functor linked to the compound


bindToBuiltinPredicate

public void bindToBuiltinPredicate(java.lang.Object lib)
                            throws java.lang.NoSuchMethodException
links this compound to builtin predicate method execution of an object


bindToBuiltinFunctor

public void bindToBuiltinFunctor(java.lang.Object lib)
                          throws java.lang.NoSuchMethodException
links this compound to builtin functor method execution of an object


unbind

public void unbind()
unlinks compound from builtin


isBuiltinPredicate

public boolean isBuiltinPredicate()
tests for bultin predicate


isBuiltinFunctor

public boolean isBuiltinFunctor()
tests for bultin functor


writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException
serialization: in order to avoid the serialization of library and method fields nullify them


readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.lang.Exception

iterator

public java.util.Iterator iterator()
for list compound