Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
TreenodeCollection | |
100.00% |
9 / 9 |
|
100.00% |
9 / 9 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
add | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isEmpty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getElements | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace pvc\struct\tree\node; |
6 | |
7 | use IteratorIterator; |
8 | use pvc\interfaces\struct\collection\CollectionInterface; |
9 | use pvc\interfaces\struct\tree\node\TreenodeCollectionInterface; |
10 | use pvc\interfaces\struct\tree\node\TreenodeInterface; |
11 | |
12 | /** |
13 | * @template PayloadType |
14 | * @extends IteratorIterator<non-negative-int, TreenodeInterface<PayloadType>, CollectionInterface<TreenodeInterface<PayloadType>>> |
15 | * @implements TreenodeCollectionInterface<PayloadType> |
16 | */ |
17 | class TreenodeCollection extends IteratorIterator implements TreenodeCollectionInterface |
18 | { |
19 | /** |
20 | * @param CollectionInterface<TreenodeInterface<PayloadType>> $collection |
21 | */ |
22 | public function __construct(protected CollectionInterface $collection) |
23 | { |
24 | parent::__construct($this->collection); |
25 | } |
26 | |
27 | /** |
28 | * @return int |
29 | */ |
30 | public function count(): int |
31 | { |
32 | return $this->collection->count(); |
33 | } |
34 | |
35 | /** |
36 | * @param non-negative-int $key |
37 | * @param TreenodeInterface<PayloadType> $treeNode |
38 | * @return void |
39 | */ |
40 | public function add(int $key, TreenodeInterface $treeNode): void |
41 | { |
42 | $this->collection->add($key, $treeNode); |
43 | } |
44 | |
45 | /** |
46 | * @param non-negative-int $key |
47 | * @return void |
48 | */ |
49 | public function delete(int $key): void |
50 | { |
51 | $this->collection->delete($key); |
52 | } |
53 | |
54 | /** |
55 | * @param TreenodeInterface<PayloadType> $node |
56 | * @return non-negative-int|false |
57 | */ |
58 | public function getKey(mixed $node): int|false |
59 | { |
60 | return $this->collection->getKey($node); |
61 | } |
62 | |
63 | public function isEmpty(): bool |
64 | { |
65 | return $this->collection->isEmpty(); |
66 | } |
67 | |
68 | /** |
69 | * @return array<TreenodeInterface<PayloadType>> |
70 | */ |
71 | public function getElements(): array |
72 | { |
73 | return $this->collection->getElements(); |
74 | } |
75 | |
76 | public function getIndex(int $key): int |
77 | { |
78 | return $this->collection->getIndex($key); |
79 | } |
80 | |
81 | public function setIndex(int $key, int $index): void |
82 | { |
83 | $this->collection->setIndex($key, $index); |
84 | } |
85 | } |