|
Sydney | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Object | +--Composite
Defined in composite.js
| Constructor Summary | |
Composite
(<string> name, <Object> value)
Creates a composite. |
|
| Method Summary | |
void
|
addChild(<Composite> child)
Adds the given Composite node to this node's list of
children.
|
void
|
addChildren(<AbstractList> list)
Iteratively adds the contents of list to this node's child
list.
|
void
|
apply(<Function> preFunc, <Function> postFunc)
Visits each node in the composite tree and calls preFunc
and/or postFunc at each node.
|
void
|
clear()
Empties this node's child list. |
Composite
|
clone(<int> depth, <string> newName)
Clones this node, optionally cloning its children. |
boolean
|
contains(<string> path)
Returns true if this node or one of its descendants can
be found using the given path and false otherwise.
|
boolean
|
containsNodeWithValue(<string> path, <string> value)
Returns true if this node or one of its descendants has a
path matching path and a value matching value.
|
Composite
|
createPath(<string> path)
Creates and inserts enough Composites to make sure that
this.findFirst(path) will return a non-null value.
|
Object
|
diff(<Composite> other)
First stab at a tree-based diff function. |
AbstractList
|
find(<string> path, <Function> hash)
Finds and returns all nodes beneath this one that have a path equal to path, relative to this node.
|
Composite
|
findByIndex(<string> path, <int> index)
Finds and returns the indexth node beneath this one that
has a path equal to path.
|
Composite
|
findFirst(<string> path)
Finds and returns the first node beneath this one that has a path equal to path.
|
Composite
|
findFirstNodeWithValue(path, value)
|
string
|
findFirstValue(<string> path)
Finds and returns the value of the first node beneath this one that has a path equal to path.
|
Composite
|
findLast(path)
|
Composite
|
findLastNodeWithValue(path, value)
|
Object
|
findLastValue(path)
|
AbstractList
|
findNodesWithValue(<string> path, <string> value, <Function> hash)
Returns a list of all nodes with the given path that have the given value. |
string
|
findValueByIndex(<string> path, <int> index)
Finds and returns the value of the indexth node beneath
this one that has a path equal to path.
|
AbstractList
|
findValues(<string> path, <bool> makeHash)
Finds and returns the values of all the nodes beneath this one that have a path equal to path.
|
Composite
|
getChild(index)
|
int
|
getChildCount()
|
Iterator
|
getChildIterator()
Returns an iterator over this node's child list. |
Array
|
getChildren()
|
string
|
getName()
|
Composite
|
getParent()
|
string
|
getPath()
|
Object
|
getValue()
|
boolean
|
hasChildren()
|
Object
|
merge(<Composite> comp, <boolean> returnOldCopy, <boolean> writableInput)
Updates the model to match what is specified by comp.
|
void
|
removeChild(<Composite> child)
Removes the given Composite from this one.
|
void
|
removeChildren(<AbstractList> childList)
Removes a list of Composites from this one.
|
void
|
setValue(newValue)
|
string
|
toString()
|
<static> Composite
|
fromLoL(<string> name, <string> value, <Array> children)
Creates and returns a Composite from a list of lists.
|
<static> Composite
|
fromXML(<DOMNode> xml)
Creates a Composite tree based on the XML provided.
|
<static> Array
|
getPathSegments(<string> path)
Returns an array of path segments given a path. |
<static> string
|
toXML(<Composite> node, <Array> roots, <boolean> include)
Serializes the Composite tree rooted at node
to an XML string.
|
| Constructor Detail |
function Composite(<string> name, <Object> value)
name - the name of this node
value - (Optional) - the value of this node. Defaults to the empty string.
| Method Detail |
void addChild(<Composite> child)
Composite node to this node's list of
children.
child - the node to add
void addChildren(<AbstractList> list)
list to this node's child
list.
list - a list of Composites to add as children of this node
void apply(<Function> preFunc, <Function> postFunc)
preFunc
and/or postFunc at each node. preFunc is
called before visiting the current node's children and
postFunc is called after visiting the children. If either
preFunc or postFunc is undefined
(or null) then apply behaves as though the
undefined function were a function that does nothing but return
false.
preFunc has the following signature:
node - the Composite currently
being visited by applydepth - the depth of node (where
the Composite on which
apply was originally
called is at depth 0)postFunc has the following signature:
node - the Composite currently
being visited by applydepth - the depth of node.
depth is defined the same
as for preFunc.preAbort - a boolean indicating
whether or not preFunc's
return value caused
apply to skip
node's childrenchildAbort - a boolean indicating
whether or not any of
node's children caused
postFunc to abort.If preFunc is defined and returns true then
the current node's children will be skipped. If
postFunc is defined and returns true then
the current node's remaining siblings will be skipped. In either
case, postFunc is called whenever it is defined.
It is more efficient (but functionally equivalent) to pass
null or undefined for either
preFunc or postFunc than it is to pass a
function that does nothing.
preFunc - (Optional) - a function accepting a Composite and an int as defined above. Defaults to a function that does nothing.
postFunc - (Optional) - a function accepting a Composite, an int, and two booleans as defined above. Defaults to a function that does nothing.
void clear()
Composite clone(<int> depth, <string> newName)
depth is 0 then a new Composite
is returned with the same name and value as this node. If
depth is positive then this node is cloned and all of its
children are cloned with depth = depth - 1 and added to the
clone of this node (ie. depth is an indicator of how deep
to do the clone.) If depth is less than zero then the
clone is made as deep as it will go.
depth - the depth to which the clone should be made. Pass a negative number to do a complete deep copy.
newName - (Optional) - the name of the returned Composite. Defaults to this.getName().
boolean contains(<string> path)
true if this node or one of its descendants can
be found using the given path and false otherwise.
path - the path to search for
true if the match succeeds and false otherwise
boolean containsNodeWithValue(<string> path, <string> value)
true if this node or one of its descendants has a
path matching path and a value matching value.
path - the path to search for
value - the value to query for
true if the match succeeds and false otherwise
Composite createPath(<string> path)
Composites to make sure that
this.findFirst(path) will return a non-null value. Returns
the Composite at the tail of the path.
createPath always chooses the first element in a vector if
it has to make a decision about where to create a new node.
path - a path to a possibly non-existent node beneath this one
Composite that path points to, which may have been created in order to satisfy this request
Object diff(<Composite> other)
other - the node to diff against this one
AbstractList find(<string> path, <Function> hash)
path, relative to this node. The return value is a list of
all matching nodes, and may be empty.
path - the path of the nodes to return
hash - (Optional) - a hash function as used by HashList. If hash is supplied, the list that is returned will be a HashList that uses hash as its hash function. If hash is not supplied, the list that is returned will be a plain LinkedList.
Composite findByIndex(<string> path, <int> index)
indexth node beneath this one that
has a path equal to path. Nodes are indexed starting from
zero, so findFirst(path) is equivalent to
findByIndex(path, 0). Like findFirst, this
method returns null if there is no matching node.
path - the path to search for, relative to this node
index - an index into the list of possible return values
null if none matches
Composite findFirst(<string> path)
path. Returns null if there is no such
node.
path - the path to search for, relative to this node
Composite node, or null if none matches
Composite findFirstNodeWithValue(path, value)
string findFirstValue(<string> path)
path. Returns the empty string if there is
no such node. findFirstValue(path) returns the same value
as findFirst(path).getValue() except it won't cause an
error if there are no nodes matching the given path.
path - the path to search for, relative to this node
Composite node, or the empty string if there is no such node
Composite findLast(path)
Composite findLastNodeWithValue(path, value)
Object findLastValue(path)
AbstractList findNodesWithValue(<string> path, <string> value, <Function> hash)
path - the path to search for, relative to this node
value - the value matching nodes must have
hash - (Optional) - a hash function as used by HashList. If hash is supplied, the list that is returned will be a HashList that uses hash as its hash function. If hash is not supplied, the list that is returned will be a plain LinkedList.
Composites, which may be empty
string findValueByIndex(<string> path, <int> index)
indexth node beneath
this one that has a path equal to path. Returns the empty
string if there is no such node.
findValueByIndex(path, index) returns the same value as
findByIndex(path, index).getValue() except it won't cause
an error if there are no matching nodes.
path - the path to search for, relative to this node
index - an index into the list of possible return values
Composite node, or the empty string if there is no such node
AbstractList findValues(<string> path, <bool> makeHash)
path. The return value is a list of the values of
all matching nodes, and may be empty.
path - the path to search for, relative to this node
makeHash - (Optional) - If true it will place the values in a hash list, using Hash.IDENTITY(). The behaviour is undefined if values are not unique and makeHash is true.
Composite getChild(index)
int getChildCount()
Iterator getChildIterator()
AbstractList.iterator()
Array getChildren()
string getName()
Composite getParent()
string getPath()
Object getValue()
boolean hasChildren()
Object merge(<Composite> comp, <boolean> returnOldCopy, <boolean> writableInput)
comp. If a
node exists in both the model and comp then
comp is taken to be correct. If a node exists in the model
but not in comp then the model is left alone, except in the
case of vectors where comp's version of the vector is used.
Only the children of comp are merged into the model. This
way a group of siblings can be merged with one call by grouping them
under a nameless node.
comp - the Composite to merge into this model
returnOldCopy - (Optional) - a boolean indicating whether or not to return a Composite that is a copy of this before the merge was performed. Defaults to false.
writableInput - (Optional) - a flag indicating whether or not comp is writable. If false, comp will be cloned as necessary to update this. If true, the Composite descendants of comp will be moved, rather than copied, into this. Passing true can be significantly faster than false, but it invalidates comp. Defaults to false.
undefined if returnOldCopy is false, a pre-merge, deep clone of the merge root otherwise
void removeChild(<Composite> child)
Composite from this one.
child - the Composite to remove
void removeChildren(<AbstractList> childList)
Composites from this one.
childList - a list of Composites to remove
void setValue(newValue)
string toString()
<static> Composite fromLoL(<string> name, <string> value, <Array> children)
Composite from a list of lists. The
returned Composite will have name and value equal to
name and value, respectively, and its children
will be determined by the remaining arguments to fromLoL. Each
argument to fromLoL after value should be an
array of length at least one. Each such array recursively describes a
Composite. The zeroth element is taken to be the name, the
first element is the value, and each successive element is an array
describing a child using the same format as was used to describe the parent.
For example, the following code
var root = Composite.fromLoL('Parent', '',
['Child', '',
['GrandChild', 'foo'],
['GrandChild', 'bar']],
['Child', '',
['GrandChild', 'baz']]);
is equivalent to the following
var root = new Composite('Parent');
var firstChild = new Composite('Child');
firstChild.addChild(new Composite('GrandChild', 'foo'));
firstChild.addChild(new Composite('GrandChild', 'bar'));
root.addChild(firstChild);
var secondChild = new Composite('Child');
secondChild.addChild(new Composite('GrandChild', 'baz'));
root.addChild(secondChild);
name - the name of the returned Composite
value - (Optional) - the value of the returned Composite. Defaults to ''.
children - (Optional) - the argument list is of variable length, but each argument should be an array as described above. Calling Composite.fromLoL(name, value) (with no children at all) is an inefficient way to call the Composite constructor.
Composite described by the arguments
<static> Composite fromXML(<DOMNode> xml)
Composite tree based on the XML provided.
xml - the root of an XML tree to be converted to a Composite tree
Composite tree
<static> Array getPathSegments(<string> path)
path - a path into a Composite tree
path not containing the '/' character
<static> string toXML(<Composite> node, <Array> roots, <boolean> include)
Composite tree rooted at node
to an XML string. The contents of the resulting string can be controlled by
the roots and include parameters. If both of
these optional parameters are set to their default values then all the
Composites descending from node will be serialized
to XML. If a non-empty list is supplied for roots then
node plus all of node's children either in or not
in roots (depending on the value of include) will
be serialized and the other children of node will be ignored.
node - the root of the Composite tree to be XML-ified
roots - (Optional) - a array of node names to either include or exclude from the serialization process, depending on the value of include. Defaults to the zero-length array.
include - (Optional) - a flag indicating whether roots is a list of nodes to include or exclude. If include is true the node names in roots are included, and if it's false they're excluded. Defaults to false.
node and all its descendants in a string
|
Sydney | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||