Class Index | File Index

Classes


Class R.struct.Container


Extends R.engine.BaseObject.
A container is a logical collection of objects. A container is responsible for maintaining the list of objects within it. When a container is destroyed, none of the objects within the container are destroyed with it. If the objects must be destroyed, call #cleanUp. A container is a doubly linked list.
Defined in: container.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
R.struct.Container(containerName)
Create a container.
Field Summary
Field Attributes Field Name and Description
 
An empty container - DO NOT MODIFY!!
Method Summary
Method Attributes Method Name and Description
 
add(obj)
Add an object to the container.
 
addAll(arr)
Add all of the objects in the container or array to this container, at the end of this container.
 
append(c)
Append a container to the end of this container.
 
Remove and destroy all objects in the container.
 
Remove all references to objects in the container.
 
Clone this container, returning a new container which points to all of the objects in this container.
 
concat(arr)
Concatenate a container or array to the end of this container, returning a new container with all of the elements.
 
contains(obj)
Returns true if the object is in the container.
 
Clears the container, however, all of the objects within the container are not destroyed automatically.
 
filter(fn, thisp)
Filters the container with the function, returning a new Container with the objects that pass the test in the function.
 
forEach(fn, thisp)
For each object in the container, the function will be executed.
 
fromArray(array)
Create a new R.struct.Container from an Array.
 
get(idx)
Get the object at the index specified.
 
Get an array of all of the objects in this container.
 
Get the class name of this object
 
getObjects(filterFn)
Get the array of all objects within this container.
 
Returns a property object with accessor methods to modify the property.
 
insert(index, obj)
Insert an object into the container at the given index.
 
Returns an iterator over the collection.
 
reduce(length)
Reduce the container so that it's length is the specified length.
 
Release the object back into the object pool.
 
remove(obj)
Remove an object from the container.
 
Remove an object from the container at the specified index.
 
replace(oldObj, newObj)
Replaces the given object with the new object.
 
replaceAt(index, obj)
Replaces the object at the given index, returning the object that was there previously.
 
size()
Returns the count of the number of objects within the container.
 
sort(fn)
Sort the objects within the container, using the provided function.
 
subset(start, end, b)
A new Container which is a subset of the current container from the starting index (inclusive) to the ending index (exclusive).
 
toXML(indent)
Serializes a container to XML.
Methods borrowed from class R.engine.BaseObject:
addEvent, addEvents, getElement, jQ, removeEvent, setElement, triggerEvent, update
Methods borrowed from class R.engine.PooledObject:
clearObjectDataModel, getId, getName, getObjectDataModel, isDestroyed, setName, setObjectDataModel, toString
Class Detail
R.struct.Container(containerName)
Create a container.
Parameters:
containerName
{String} The name of the container
Field Detail
EMPTY
An empty container - DO NOT MODIFY!!
Method Detail
add(obj)
Add an object to the container.
Parameters:
obj
{Object} The object to add to the container.

addAll(arr)
Add all of the objects in the container or array to this container, at the end of this container. If "arr" is a container, the head of "arr" is joined to the tail of this, resulting in a very fast operation. Because this method, when performed on a container, is just joining the two lists, no duplication of elements from the container is performed. As such, removing elements from the new container will affect this container as well.
Parameters:
arr
{R.struct.Container|Array} A container or array of objects

append(c)
Append a container to the end of this container. When you append a container, its head will now point to the tail of this container and the tail of this container will become the tail of the appended container. The appended container will still exist, but navigating the container in reverse past the head of the container will navigate into the container which was appended to. If you need the containers to remain independent of eachother, see the #concat method.
Parameters:
c
{R.struct.Container} The container to append.

cleanUp()
Remove and destroy all objects in the container.

clear()
Remove all references to objects in the container. None of the objects are actually destroyed. Use #cleanUp to remove and destroy all objects.

{R.struct.Container} clone()
Clone this container, returning a new container which points to all of the objects in this container.
Returns:
{R.struct.Container} A new container with all of the objects from the current container

{R.struct.Container} concat(arr)
Concatenate a container or array to the end of this container, returning a new container with all of the elements. The array or container will be copied and appended to this container. While the actual pointers to the objects aren't deep copied, one can be assured that modifying the array or container structure being appended will not affect either container. Note, however, that modifying the objects within the container will modify the objects in the original containers as well.
Parameters:
arr
{R.struct.Container|Array} A container or array of objects
Returns:
{R.struct.Container} A new container with all objects from both

{Boolean} contains(obj)
Returns true if the object is in the container.
Parameters:
obj
{Object} The object to find
Returns:
{Boolean}

destroy()
Clears the container, however, all of the objects within the container are not destroyed automatically. This is to prevent the early clean up of objects which are being used by a transient container.

{R.struct.Container} filter(fn, thisp)
Filters the container with the function, returning a new Container with the objects that pass the test in the function. If the object should be included in the new Container, the function should return true. The function takes one argument: the object being processed. Unless otherwise specified, this refers to the container.
Parameters:
fn
{Function} The function to execute for each object
thisp Optional
{Object} The object to use as this inside the function
Returns:
{R.struct.Container}

forEach(fn, thisp)
For each object in the container, the function will be executed. The function takes one argument: the object being processed. Unless otherwise specified, this refers to the container.

Returning false from fn will immediately halt any further iteration over the container.

Parameters:
fn
{Function} The function to execute for each object
thisp Optional
{Object} The object to use as this inside the function

{R.struct.Container} fromArray(array)
Create a new R.struct.Container from an Array.
Parameters:
array
{Array} An array of objects
Returns:
{R.struct.Container}

{Object} get(idx)
Get the object at the index specified. If the container has been sorted, objects might not be in the position you'd expect.
Parameters:
idx
{Number} The index of the object to get
Throws:
{Error}
Index out of bounds if the index is out of the list of objects
Returns:
{Object} The object at the index within the container

{Array} getAll()
Get an array of all of the objects in this container.
Returns:
{Array} An array of all of the objects in the container

{String} getClassName()
Get the class name of this object
Returns:
{String} "R.struct.Container"

{Array} getObjects(filterFn)
Get the array of all objects within this container. If a filtering function is provided, only objects matching the filter will be returned from the object collection.

The filter function needs to return true for each element that should be contained in the filtered set. The function will be passed the following arguments:

Say you wanted to filter a host objects components based on a particular type. You might do something like the following:
var logicComponents = host.getObjects(function(el, idx) {
   if (el.getType() == BaseComponent.TYPE_LOGIC) {
      return true;
   }
});
Parameters:
filterFn
{Function} A function to filter the set of elements with. If you pass null the entire set of objects will be returned.
Returns:
{Array} The array of filtered objects

{Object} getProperties()
Returns a property object with accessor methods to modify the property.
Returns:
{Object} The properties object

insert(index, obj)
Insert an object into the container at the given index. Asserts if the index is out of bounds for the container. The index must be greater than or equal to zero, and less than or equal to the size of the container minus one. The effect is to extend the length of the container by one.
Parameters:
index
{Number} The index to insert the object at.
obj
{Object} The object to insert into the container

{R.lang.Iterator} iterator()
Returns an iterator over the collection.
Returns:
{R.lang.Iterator} An iterator

{R.struct.Container} reduce(length)
Reduce the container so that it's length is the specified length. If length is larger than the size of this container, no operation is performed. Setting length to zero is effectively the same as calling #clear. Objects which would logically fall after length are not automatically destroyed.
Parameters:
length
{Number} The maximum number of elements
Returns:
{R.struct.Container} The subset of elements being removed

release()
Release the object back into the object pool.

{Object} remove(obj)
Remove an object from the container. The object is not destroyed when it is removed from the container.
Parameters:
obj
{Object} The object to remove from the container.
Returns:
{Object} The object that was removed

{Object} removeAtIndex(idx)
Remove an object from the container at the specified index. The object is not destroyed when it is removed.
Parameters:
idx
{Number} An index between zero and the size of the container minus 1.
Returns:
{Object} The object removed from the container.

{Object} replace(oldObj, newObj)
Replaces the given object with the new object. If the old object is not found, no action is performed.
Parameters:
oldObj
{Object} The object to replace
newObj
{Object} The object to put in place
Returns:
{Object} The object which was replaced

{Object} replaceAt(index, obj)
Replaces the object at the given index, returning the object that was there previously. Asserts if the index is out of bounds for the container. The index must be greater than or equal to zero, and less than or equal to the size of the container minus one.
Parameters:
index
{Number} The index at which to replace the object
obj
{Object} The object to put in place
Returns:
{Object} The object which was replaced

{Number} size()
Returns the count of the number of objects within the container.
Returns:
{Number} The number of objects in the container

sort(fn)
Sort the objects within the container, using the provided function. The function will be provided object A and B. If the result of the function is less than zero, A will be sorted before B. If the result is zero, A and B retain their order. If the result is greater than zero, A will be sorted after B.
Parameters:
fn Optional
{Function} The function to sort with. If null the objects will be sorted in "natural" order.

{R.struct.Container} subset(start, end, b)
A new Container which is a subset of the current container from the starting index (inclusive) to the ending index (exclusive). Modifications made to the objects in the subset will affect this container's objects.
Parameters:
start
{Number} The starting index in the container
end
{Number} The engine index in the container
b
Returns:
{R.struct.Container} A subset of the container.

{String} toXML(indent)
Serializes a container to XML.
Parameters:
indent
Returns:
{String} The XML string

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Mar 18 2013 16:09:21 GMT-0400 (EDT)