public class TermModel extends Object implements Serializable, TreeModel
Modifier and Type | Field and Description |
---|---|
TermModel[] |
children
public for convenience, but should not be set outside this class;
children == null means children == new TermModel[0]
|
static int |
listMaxLength |
Object |
node
public for convenience, but should not be set outside this class
|
TermModel |
root
The TermModel containing this; relevant to define variable scope.
|
Constructor and Description |
---|
TermModel() |
TermModel(int n) |
TermModel(Object n) |
TermModel(Object n,
boolean isAList) |
TermModel(Object n,
TermModel[] c) |
TermModel(Object n,
TermModel[] c,
boolean isAList) |
TermModel(Object n,
Vector<TermModel> v) |
Modifier and Type | Method and Description |
---|---|
void |
addChildren(TermModel[] more)
Add children to this term node; a new children array is created and old children are copied to it
|
void |
addTermModelListener(TermModelListener l)
Start notifying listener l of changes to this term.
|
void |
addTreeModelListener(TreeModelListener l) |
void |
assignTermChanges(TermModel other)
Assuming this and the other terms are structurally similar, replaces variable nodes in this term
by corresponding nonvar nodes.
|
void |
assignToVar(VariableNode v,
Object value)
Replaces all occurrences of v in this subterm by value, using setNodeValue
|
Object |
clone()
Clones by serialization, to keep variable bindings; these should form a closed graph
within this term, otherwise the new term instance would contain dangling references
|
void |
deleteChildren(int[] less)
Delete children with specified indexes; a new children array is created and old children are copied to it
|
void |
deleteChildren(TermModel[] less)
Removes the children in array; it finds children to remove by using the equivalent of Prolog's ==.
|
void |
destroy() |
static void |
destroy(TermModel[] children) |
static String |
doubleQuotes(String S) |
boolean |
equals(Object x)
True if both terms are structurally similar with equal nodes.
|
static ObjectExamplePair |
example() |
static TreePath |
findPathForNode(String label,
TermModel tree,
boolean exactMatch) |
void |
fireTermChanged() |
TermModel[] |
flatList()
Flattens this list into a new TermModel array, but not completely:
the result may still contain lists
|
static TermModel[] |
flatList(TermModel list)
Flattens a list into a TermModel array, but not completely:
the result may still contain lists
|
String |
flatListToString(PrologOperatorsContext ops,
boolean quoted) |
Object |
getChild(int index) |
Object |
getChild(Object parent,
int index) |
int |
getChildCount() |
int |
getChildCount(Object parent) |
TermModel[] |
getChildren() |
String |
getFunctorArity()
Return a node/arity String
|
int |
getIndexOfChild(Object parent,
Object child) |
Object |
getRoot() |
String |
getTemplate()
Return a Node(_,..._) String
|
int |
hashCode()
Returns an hashCode for the result of toString()
|
int |
intValue()
Returns node object as an int, assuming it is a Number
|
boolean |
isAtom() |
boolean |
isInteger() |
boolean |
isLeaf() |
boolean |
isLeaf(Object node) |
boolean |
isList()
May be an empty list
|
boolean |
isListEnd() |
boolean |
isLong() |
boolean |
isNumber() |
boolean |
isRoot()
This node is its own root
|
boolean |
isVar() |
String |
listToString(PrologOperatorsContext ops,
boolean quoted) |
long |
longValue()
Returns node object as a long, assuming it is a Number
|
Vector<Integer> |
makeIntegerVector()
Assuming this is a list of numbers, returns a Vector containing one Integer for each number in the list
|
static TermModel |
makeList(ArrayList<TermModel> terms)
Make a binary (non flat) list
|
static TermModel |
makeList(TermModel[] terms)
Make a binary (non flat) list
|
static TermModel |
makeList(Vector<TermModel> terms) |
boolean |
nodeIsVar() |
static String |
parenthesize(boolean yes,
String S) |
int |
precedence(PrologOperatorsContext context) |
static Hashtable<String,Object> |
props2Hashtable(TermModel[] terms) |
static String |
quoteIfFirstUpper(String S) |
static boolean |
quotesAreNeeded(String atom) |
void |
removeTermModelListener(TermModelListener l) |
void |
removeTreeModelListener(TreeModelListener l) |
void |
setChild(int index,
TermModel child)
Set the child, notifying TermModelListeners
|
void |
setChildren(TermModel[] c)
Set the children array, notifying TermModelListeners
|
void |
setNodeValue(Object v)
Set the node, notifying TermModelListeners
|
void |
setRoot()
Set the root variables of nodes in this subterm to refer this term node as their root
|
void |
setRoot(TermModel r)
Set the root variables of nodes in this subterm to refer r as their root
|
String |
toIndentedString() |
String |
toIndentedString(int level) |
String |
toString()
Returns a close imitation of a Prolog's write, following infix/prefix/postfix operartor declarations.
|
String |
toString(boolean quoted) |
String |
toString(PrologEngine engine,
boolean quoted) |
String |
toString(PrologOperatorsContext ops) |
String |
toString(PrologOperatorsContext ops,
boolean quoted)
quoted true: emulates writeq, and also ignores operator precedences, using prefix notation;
also ignores list size limits, writing the full list.
|
boolean |
unifies(TermModel term)
If two terms, each with nonrepeated variables, are unifiable, this method returns true.
|
void |
valueForPathChanged(TreePath path,
Object newValue) |
boolean |
variant(TermModel tx) |
boolean |
variant(TermModel tx,
Map<VariableNode,VariableNode> myVars) |
public Object node
public TermModel[] children
public transient TermModel root
public static final int listMaxLength
public TermModel()
public TermModel(Object n)
public TermModel(Object n, boolean isAList)
public TermModel(int n)
public static ObjectExamplePair example()
public Object clone()
public boolean equals(Object x)
public boolean variant(TermModel tx)
public boolean variant(TermModel tx, Map<VariableNode,VariableNode> myVars)
public void setNodeValue(Object v)
public void setChild(int index, TermModel child)
public void setChildren(TermModel[] c)
public TermModel[] getChildren()
public void addChildren(TermModel[] more)
public void deleteChildren(int[] less)
public void deleteChildren(TermModel[] less)
public void assignToVar(VariableNode v, Object value)
public void assignTermChanges(TermModel other)
public void setRoot()
public void setRoot(TermModel r)
public boolean isRoot()
public String getTemplate()
public String getFunctorArity()
public int getChildCount(Object parent)
getChildCount
in interface TreeModel
TreeModel
public boolean isLeaf(Object node)
public void valueForPathChanged(TreePath path, Object newValue)
valueForPathChanged
in interface TreeModel
TreeModel
public int getIndexOfChild(Object parent, Object child)
getIndexOfChild
in interface TreeModel
TreeModel
public void addTreeModelListener(TreeModelListener l)
addTreeModelListener
in interface TreeModel
TreeModel
public void removeTreeModelListener(TreeModelListener l)
removeTreeModelListener
in interface TreeModel
TreeModel
public Object getChild(int index)
public int getChildCount()
public boolean isLeaf()
public void addTermModelListener(TermModelListener l)
public void removeTermModelListener(TermModelListener l)
public void fireTermChanged()
public static TreePath findPathForNode(String label, TermModel tree, boolean exactMatch)
public void destroy()
public static void destroy(TermModel[] children)
public Vector<Integer> makeIntegerVector()
public int intValue()
public long longValue()
public String toString()
public String toString(boolean quoted)
public String toString(PrologOperatorsContext ops)
public static boolean quotesAreNeeded(String atom)
public String toString(PrologOperatorsContext ops, boolean quoted)
public String toIndentedString()
public String toIndentedString(int level)
public String toString(PrologEngine engine, boolean quoted)
public String listToString(PrologOperatorsContext ops, boolean quoted)
public String flatListToString(PrologOperatorsContext ops, boolean quoted)
public boolean isListEnd()
public boolean isList()
public boolean isAtom()
public boolean isNumber()
public boolean isInteger()
public boolean isLong()
public boolean isVar()
public boolean nodeIsVar()
public TermModel[] flatList()
public static TermModel[] flatList(TermModel list)
public boolean unifies(TermModel term)
public int hashCode()
public int precedence(PrologOperatorsContext context)