Class TQueue
TQueue class
TQueue implements a queue. The typical queue operations are implemented, which include enqueue(), dequeue() and peek(). In addition, contains() can be used to check if an item is contained in the queue. To obtain the number of the items in the queue, check the Count property. Items in the queue may be traversed using foreach as follows, - foreach($queue as $item) ...
Constructor Summary |
public |
Constructor.
|
Method Summary |
void
|
Removes all items in the queue.
|
boolean
|
|
void
|
Copies iterable data into the queue.
|
integer
|
Returns the number of items in the queue.
|
mixed
|
Removes and returns the object at the beginning of the queue.
|
void
|
Adds an object to the end of the queue.
|
integer
|
|
Iterator
|
Returns an iterator for traversing the items in the queue.
|
mixed
|
Returns the item at the top of the queue.
|
array
|
|
Methods Inherited From TComponent |
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
Constructor Details |
__construct
Constructor.
Initializes the queue with an array or an iterable object.
Throws:
TInvalidDataTypeException If data is not null and neither an array nor an iterator.
|
Method Details |
clear
Removes all items in the queue.
|
contains
public boolean contains |
(mixed $item ) |
Input |
mixed | $item | the item |
Output |
boolean
| whether the queue contains the item |
Exception |
|
copyFrom
public void copyFrom |
(mixed $data ) |
Copies iterable data into the queue.
Note, existing data in the list will be cleared first.
Input |
mixed | $data | the data to be copied from, must be an array or object implementing Traversable |
Output |
Exception |
throws | TInvalidDataTypeException If data is neither an array nor a Traversable. |
|
count
Returns the number of items in the queue.
This method is required by Countable interface.
Output |
integer
| number of items in the queue. |
Exception |
|
dequeue
Removes and returns the object at the beginning of the queue.
Output |
mixed
| the item at the beginning of the queue |
Exception |
throws | TInvalidOperationException if the queue is empty |
|
enqueue
public void enqueue |
(mixed $item ) |
Adds an object to the end of the queue.
Input |
mixed | $item | the item to be appended into the queue |
Output |
Exception |
|
getCount
public integer getCount |
() |
Output |
integer
| the number of items in the queue |
Exception |
|
getIterator
public Iterator getIterator |
() |
Returns an iterator for traversing the items in the queue.
This method is required by the interface IteratorAggregate.
Output |
Iterator
| an iterator for traversing the items in the queue. |
Exception |
|
peek
Returns the item at the top of the queue.
Unlike pop(), this method does not remove the item from the queue.
Output |
mixed
| item at the top of the queue |
Exception |
throws | TInvalidOperationException if the queue is empty |
|
toArray
Output |
array
| the list of items in queue |
Exception |
|
|