CQueue

优质
小牛编辑
129浏览
2023-12-01
所有包 | 属性 | 方法
system.collections
继承class CQueue » CComponent
实现IteratorAggregate, Traversable, Countable
源自1.0
版本$Id: CQueue.php 3427 2011-10-25 00:03:52Z alexander.makarow $
源码framework/collections/CQueue.php
CQueue实现了一个队列。

这个实现的典型的队列操作,包括 enqueue(),dequeue()和peek()。另外, contains()可以用来检查一个项目是否包含在 队列。通过Count属性,可以取得 列表中的项目数。

队列中的项目可以像下面那样使用foreach遍历,
foreach($queue as $item) ...

公共属性

隐藏继承属性

属性类型描述定义在
countinteger返回队列中的项目数。CQueue
iteratorIterator返回遍历这个项目队列的迭代器。CQueue

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造方法。CQueue
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
clear()删除队列中所有项目。CQueue
contains()CQueue
copyFrom()将迭代器中的数据复制到队列。CQueue
count()返回队列中的项目数。CQueue
dequeue()删除并返回处于列表开始处的对象。CQueue
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
enqueue()添加一个对象到队列尾部。CQueue
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getCount()返回队列中的项目数。CQueue
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getIterator()返回遍历这个项目队列的迭代器。CQueue
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
peek()返回处于队列头部的项目。CQueue
raiseEvent()发起一个事件。CComponent
toArray()CQueue

属性详细

count 属性 只读 public integer getCount()

返回队列中的项目数。

iterator 属性 只读 public Iterator getIterator()

返回遍历这个项目队列的迭代器。 此方法为接口IteratorAggregate强制要求实现。

方法详细

__construct() 方法
public void __construct(array $data=NULL)
$dataarray初始化的数据。默认为null,意味着不会初始化。
源码: framework/collections/CQueue.php#52 (显示) publicfunction__construct($data=null)
{
if($data!==null)
$this->copyFrom($data);
}

构造方法。 根据数组或者迭代对象初始化这个队列。

clear() 方法
public void clear()
源码: framework/collections/CQueue.php#90 (显示) publicfunctionclear()
{
$this->_c=0;
$this->_d=array();
}

删除队列中所有项目。

contains() 方法
public boolean contains(mixed $item)
$itemmixed项目对象
{return}boolean返回值说明队列中是否包含该项目
源码: framework/collections/CQueue.php#100 (显示) publicfunctioncontains($item)
{
returnarray_search($item,$this->_d,true)!==false;
}
copyFrom() 方法
public void copyFrom(mixed $data)
$datamixed要复制的数据, 只能是数组或者继承于Traversable的对象。
源码: framework/collections/CQueue.php#72 (显示) publicfunctioncopyFrom($data)
{
if(is_array($data)||($datainstanceofTraversable))
{
$this->clear();
foreach($dataas$item)
{
$this->_d[]=$item;
++$this->_c;
}
}
elseif($data!==null)
thrownewCException(Yii::t('yii','QueuedatamustbeanarrayoranobjectimplementingTraversable.'));
}

将迭代器中的数据复制到队列。 注意,队列中已经存在的数据会被首先删除。

count() 方法
public integer count()
{return}integer返回队列中的项目数。
源码: framework/collections/CQueue.php#168 (显示) publicfunctioncount()
{
return$this->getCount();
}

返回队列中的项目数。 此方法为接口Countable强制要求实现。

dequeue() 方法
public mixed dequeue()
{return}mixed返回处于列表开始处的对象
源码: framework/collections/CQueue.php#123 (显示) publicfunctiondequeue()
{
if($this->_c===0)
thrownewCException(Yii::t('yii','Thequeueisempty.'));
else
{
--$this->_c;
returnarray_shift($this->_d);
}
}

删除并返回处于列表开始处的对象。

enqueue() 方法
public void enqueue(mixed $item)
$itemmixed要添加到队列尾部的项目
源码: framework/collections/CQueue.php#138 (显示) publicfunctionenqueue($item)
{
++$this->_c;
array_push($this->_d,$item);
}

添加一个对象到队列尾部。

getCount() 方法
public integer getCount()
{return}integer返回队列中的项目数。
源码: framework/collections/CQueue.php#158 (显示) publicfunctiongetCount()
{
return$this->_c;
}

返回队列中的项目数。

getIterator() 方法
public Iterator getIterator()
{return}Iterator返回遍历这个项目队列的迭代器。
源码: framework/collections/CQueue.php#149 (显示) publicfunctiongetIterator()
{
returnnewCQueueIterator($this->_d);
}

返回遍历这个项目队列的迭代器。 此方法为接口IteratorAggregate强制要求实现。

peek() 方法
public mixed peek()
{return}mixed返回处于队列头部的项目。
源码: framework/collections/CQueue.php#110 (显示) publicfunctionpeek()
{
if($this->_c===0)
thrownewCException(Yii::t('yii','Thequeueisempty.'));
else
return$this->_d[0];
}

返回处于队列头部的项目。

toArray() 方法
public array toArray()
{return}array队列中的项目列表。
源码: framework/collections/CQueue.php#61 (显示) publicfunctiontoArray()
{
return$this->_d;
}