1 | <?php |
||
23 | class ArrayList extends ListAbstract { |
||
24 | use ArrayAccessTrait; |
||
25 | |||
26 | private $data; |
||
27 | private $current; |
||
28 | private $position; |
||
29 | |||
30 | public function __construct() { |
||
35 | |||
36 | /** |
||
37 | * {@inheritDoc} |
||
38 | */ |
||
39 | public function insert($index, $data) { |
||
40 | array_splice($this->data, $index, 0, $data); |
||
41 | $this->size++; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritDoc} |
||
46 | */ |
||
47 | protected function insertAt($index, $data) {} |
||
48 | |||
49 | /** |
||
50 | * {@inheritDoc} |
||
51 | */ |
||
52 | protected function insertEnd($data) {} |
||
53 | |||
54 | /** |
||
55 | * {@inheritDoc} |
||
56 | */ |
||
57 | protected function insertBeginning($data) {} |
||
58 | |||
59 | /** |
||
60 | * Removes all the array items. |
||
61 | */ |
||
62 | public function clear() { |
||
66 | |||
67 | /** |
||
68 | * Returns the array in the especified index. |
||
69 | * |
||
70 | * @param integer $index Index that must be greater than 0 |
||
71 | * and lower than the list size. |
||
72 | * @return mixed The data stored in the given index |
||
73 | * @throws OutOfBoundsException if index is out bounds. |
||
74 | */ |
||
75 | public function get($index) { |
||
82 | |||
83 | /** |
||
84 | * Returns the last node with O(1). |
||
85 | * |
||
86 | * @return mixed null if the array is empty. |
||
87 | */ |
||
88 | public function getLast() { |
||
95 | |||
96 | public function getAll() { |
||
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | */ |
||
105 | public function contains($data) : bool { |
||
108 | |||
109 | /** |
||
110 | * {@inheritDoc} |
||
111 | */ |
||
112 | public function indexOf($data) { |
||
115 | |||
116 | /** |
||
117 | * {@inheritDoc} |
||
118 | */ |
||
119 | public function lastIndexOf($data) { |
||
128 | |||
129 | /** |
||
130 | * {@inheritDoc} |
||
131 | */ |
||
132 | public function remove($data) { |
||
146 | |||
147 | /** |
||
148 | * Delete a node in the given position and returns it back. |
||
149 | * |
||
150 | * @param integer $index the position. |
||
151 | * @throws OutOfBoundsException if index is negative |
||
152 | * or is greater than the size of the list. |
||
153 | */ |
||
154 | public function delete($index) { |
||
165 | |||
166 | protected function deleteBeginning() {} |
||
167 | |||
168 | protected function deleteAt($index) {} |
||
169 | |||
170 | protected function deleteEnd() {} |
||
171 | |||
172 | /** |
||
173 | * Returns array stored in the data attribute. |
||
174 | * |
||
175 | * @return array data stored in all nodes. |
||
176 | */ |
||
177 | public function toArray() : array { |
||
180 | |||
181 | /** |
||
182 | * Reset the cursor position. |
||
183 | */ |
||
184 | public function rewind() { |
||
188 | |||
189 | /** |
||
190 | * Returns the current node data. |
||
191 | * |
||
192 | * @return mixed |
||
193 | */ |
||
194 | public function current() { |
||
197 | |||
198 | /** |
||
199 | * Key or index that indicates the cursor position. |
||
200 | * |
||
201 | * @return integer The current position. |
||
202 | */ |
||
203 | public function key() { |
||
206 | |||
207 | /** |
||
208 | * Move the cursor to the next node and increments the |
||
209 | * position counter. |
||
210 | */ |
||
211 | public function next() { |
||
215 | |||
216 | /** |
||
217 | * Returns if the current pointer position is valid. |
||
218 | * |
||
219 | * @return boolean true if pointer is not last, else false. |
||
220 | */ |
||
221 | public function valid() { |
||
224 | } |