class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface (View source)

This class provides a basic implementation of DoubleEndedQueueInterface, to minimize the effort required to implement this interface.

Traits

Provides functionality to check values for specific types.
Provides functionality to express a value as string

Properties

protected array $data The items of this array. from AbstractArray
protected int $index The index of the head of the queue. from Queue

Methods

__construct(string $queueType, array $data = [])

Constructs a queue object of the specified type, optionally with the specified data.

from Queue
getIterator()

Returns an iterator for this array.

bool
offsetExists(mixed $offset)

Returns true if the given offset exists in this array.

mixed|null
offsetGet(mixed $offset)

Returns the value at the specified offset.

void
offsetSet(mixed|null $offset, mixed $value)

Sets the given value to the given offset in the queue.

void
offsetUnset(mixed $offset)

Removes the given offset and its value from the array.

string
serialize()

Returns a serialized string representation of this array object.

void
unserialize(string $serialized)

Converts a serialized string representation into an instance object.

int
count()

Returns the number of items in this array.

void
clear()

Removes all items from this array.

array
toArray()

Returns a native PHP array representation of this array object.

bool
isEmpty()

Returns true if this array is empty.

bool
checkType(string $type, mixed $value)

Returns true if value is of the specified type.

from TypeTrait
string
toolValueToString(mixed $value)

Returns a string representation of the value.

bool
add(mixed $element)

Ensures that this queue contains the specified element.

from Queue
mixed
element()

Retrieves, but does not remove, the head of this queue.

from Queue
bool
offer(mixed $element)

Inserts the specified element into this queue.

from Queue
mixed|null
peek()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

from Queue
mixed|null
poll()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

from Queue
mixed
remove()

Retrieves and removes the head of this queue.

from Queue
string
getType()

Returns the type associated with this queue.

from Queue
bool
addFirst(mixed $element)

Ensures that the specified element is inserted at the front of this queue.

bool
addLast(mixed $element)

Ensures that the specified element in inserted at the end of this queue.

bool
offerFirst(mixed $element)

Inserts the specified element at the front this queue.

bool
offerLast(mixed $element)

Inserts the specified element at the end this queue.

mixed
removeFirst()

Retrieves and removes the head of this queue.

mixed
removeLast()

Retrieves and removes the tail of this queue.

mixed|null
pollFirst()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

mixed|null
pollLast()

Retrieves and removes the tail of this queue, or returns null if this queue is empty.

mixed
firstElement()

Retrieves, but does not remove, the head of this queue.

mixed
lastElement()

Retrieves, but does not remove, the tail of this queue.

mixed|null
peekFirst()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

mixed|null
peekLast()

Retrieves, but does not remove, the tail of this queue, or returns null if this queue is empty.

Details

__construct(string $queueType, array $data = [])

Constructs a queue object of the specified type, optionally with the specified data.

Parameters

string $queueType The type (FQCN) associated with this queue.
array $data The initial items to add to this array.

Traversable getIterator()

Returns an iterator for this array.

Return Value

Traversable

bool offsetExists(mixed $offset)

Returns true if the given offset exists in this array.

Parameters

mixed $offset The offset to check.

Return Value

bool

mixed|null offsetGet(mixed $offset)

Returns the value at the specified offset.

Parameters

mixed $offset The offset for which a value should be returned.

Return Value

mixed|null the value stored at the offset, or null if the offset does not exist.

void offsetSet(mixed|null $offset, mixed $value)

Sets the given value to the given offset in the queue.

Since arbitrary offsets may not be manipulated in a queue, this method serves only to fulfill the ArrayAccess interface requirements. It is invoked by other operations when adding values to the queue.

Parameters

mixed|null $offset The offset to set. If null, the value may be set at a numerically-indexed offset.
mixed $value The value to set at the given offset.

Return Value

void

Exceptions

InvalidArgumentException when the value does not match the specified type for this queue.

void offsetUnset(mixed $offset)

Removes the given offset and its value from the array.

Parameters

mixed $offset The offset to remove from the array.

Return Value

void

string serialize()

Returns a serialized string representation of this array object.

Return Value

string a PHP serialized string.

void unserialize(string $serialized)

Converts a serialized string representation into an instance object.

Parameters

string $serialized A PHP serialized string to unserialize.

Return Value

void

int count()

Returns the number of items in this array.

Return Value

int

void clear()

Removes all items from this array.

Return Value

void

array toArray()

Returns a native PHP array representation of this array object.

Return Value

array

bool isEmpty()

Returns true if this array is empty.

Return Value

bool

protected bool checkType(string $type, mixed $value)

Returns true if value is of the specified type.

Parameters

string $type The type to check the value against.
mixed $value The value to check.

Return Value

bool

protected string toolValueToString(mixed $value)

Returns a string representation of the value.

  • null value: 'NULL'
  • boolean: 'TRUE', 'FALSE'
  • array: 'Array'
  • scalar: converted-value
  • resource: '(type resource #number)'
  • object with __toString(): result of __toString()
  • object DateTime: ISO 8601 date
  • object: '(className Object)'
  • anonymous function: same as object

Parameters

mixed $value the value to return as a string.

Return Value

string

bool add(mixed $element)

Ensures that this queue contains the specified element.

This method differs from offer() only in that it throws an exception if it cannot add the element to the queue.

Parameters

mixed $element The element to add to this queue.

Return Value

bool true if this queue changed as a result of the call.

Exceptions

InvalidArgumentException when the element does not match the specified type for this queue.

See also

Queue::offer

mixed element()

Retrieves, but does not remove, the head of this queue.

This method differs from peek() only in that it throws an exception if this queue is empty.

Return Value

mixed the head of this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

Queue::peek

bool offer(mixed $element)

Inserts the specified element into this queue.

This method differs from add() only in that it does not throw an exception if it cannot add the element to the queue.

Parameters

mixed $element The element to add to this queue.

Return Value

bool true if the element was added to this queue, else false.

See also

Queue::add

mixed|null peek()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Return Value

mixed|null the head of this queue, or null if this queue is empty.

See also

Queue::element

mixed|null poll()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Return Value

mixed|null the head of this queue, or null if this queue is empty.

See also

Queue::remove

mixed remove()

Retrieves and removes the head of this queue.

This method differs from poll() only in that it throws an exception if this queue is empty.

Return Value

mixed the head of this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

Queue::poll

string getType()

Returns the type associated with this queue.

Return Value

string

bool addFirst(mixed $element)

Ensures that the specified element is inserted at the front of this queue.

Parameters

mixed $element The element to add to the front of this queue.

Return Value

bool true if this queue changed as a result of the call.

Exceptions

InvalidArgumentException when the value does not match the specified type for this queue.

See also

DoubleEndedQueue::offerFirst

bool addLast(mixed $element)

Ensures that the specified element in inserted at the end of this queue.

Parameters

mixed $element The element to add to the end of this queue.

Return Value

bool true if this queue changed as a result of the call.

Exceptions

InvalidArgumentException when the value does not match the specified type for this queue.

See also

Queue::add

bool offerFirst(mixed $element)

Inserts the specified element at the front this queue.

Parameters

mixed $element The element to add to the front of this queue.

Return Value

bool true if the element was added to this queue, else false.

See also

DoubleEndedQueue::addFirst

bool offerLast(mixed $element)

Inserts the specified element at the end this queue.

Parameters

mixed $element The element to add to the end of this queue.

Return Value

bool true if the element was added to this queue, else false.

See also

DoubleEndedQueue::addLast
Queue::offer

mixed removeFirst()

Retrieves and removes the head of this queue.

This method differs from pollFirst() only in that it throws an exception if this queue is empty.

Return Value

mixed the first element in this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

DoubleEndedQueue::pollFirst
Queue::remove

mixed removeLast()

Retrieves and removes the tail of this queue.

This method differs from pollLast() only in that it throws an exception if this queue is empty.

Return Value

mixed the last element in this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

DoubleEndedQueue::pollLast

mixed|null pollFirst()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Return Value

mixed|null the head of this queue, or null if this queue is empty.

See also

DoubleEndedQueue::removeFirst

mixed|null pollLast()

Retrieves and removes the tail of this queue, or returns null if this queue is empty.

Return Value

mixed|null the tail of this queue, or null if this queue is empty.

See also

DoubleEndedQueue::removeLast

mixed firstElement()

Retrieves, but does not remove, the head of this queue.

This method differs from peekFirst() only in that it throws an exception if this queue is empty.

Return Value

mixed the head of this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

DoubleEndedQueue::peekFirst
Queue::element

mixed lastElement()

Retrieves, but does not remove, the tail of this queue.

This method differs from peekLast() only in that it throws an exception if this queue is empty.

Return Value

mixed the tail of this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

DoubleEndedQueue::peekLast

mixed|null peekFirst()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Return Value

mixed|null the head of this queue, or null if this queue is empty.

See also

DoubleEndedQueue::firstElement
Queue::peek

mixed|null peekLast()

Retrieves, but does not remove, the tail of this queue, or returns null if this queue is empty.

Return Value

mixed|null the tail of this queue, or null if this queue is empty.

See also

DoubleEndedQueue::lastElement