1
|
|
|
<?php namespace GenericCollections; |
2
|
|
|
|
3
|
|
|
use GenericCollections\Abstracts\AbstractDeque; |
4
|
|
|
use GenericCollections\Traits\ElementTypeProperty; |
5
|
|
|
use GenericCollections\Traits\OptionsProperty; |
6
|
|
|
use GenericCollections\Utils\TypeProperty; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Generic double ended queue implementation |
10
|
|
|
* |
11
|
|
|
* This class has a FIFO behavior on add, offer, element, peek, remove & poll methods |
12
|
|
|
* |
13
|
|
|
* Options: |
14
|
|
|
* - Defaults: not allow nulls, allow duplicates, identical comparisons |
15
|
|
|
* |
16
|
|
|
* It is not recommended to allow nulls since several methods |
17
|
|
|
* (element, pollFirst, pollLast, poll, peekFirst, peekLast and peek) |
18
|
|
|
* returns null if not found or empty |
19
|
|
|
* |
20
|
|
|
* It is not recommended to set unique values option, this will search inside the |
21
|
|
|
* container on every insert and it could be expensive on large containers |
22
|
|
|
* |
23
|
|
|
* @package GenericCollections |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
class Deque extends AbstractDeque |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
use ElementTypeProperty; |
28
|
|
|
use OptionsProperty; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $elementType |
32
|
|
|
* @param array $elements |
33
|
|
|
* @param int $options |
34
|
|
|
*/ |
35
|
195 |
|
public function __construct($elementType, array $elements = [], $options = 0) |
36
|
|
|
{ |
37
|
195 |
|
$this->options = new Options($options); |
38
|
195 |
|
$this->elementType = new TypeProperty($elementType, $this->optionAllowNullMembers()); |
39
|
195 |
|
$this->createStorageObject(); |
40
|
195 |
|
$this->addAll($elements); |
41
|
195 |
|
} |
42
|
|
|
} |
43
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.