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 | * Add a new node in the specified index. |
||
38 | * |
||
39 | * @param integer $index the position. |
||
40 | * @param mixed $data the data to be stored. |
||
41 | */ |
||
42 | public function insert($index, $data) { |
||
46 | |||
47 | /** |
||
48 | * Removes all the array items. |
||
49 | */ |
||
50 | public function clear() { |
||
54 | |||
55 | /** |
||
56 | * Returns the array in the especified index. |
||
57 | * |
||
58 | * @param integer $index Index that must be greater than 0 |
||
59 | * and lower than the list size. |
||
60 | * @return mixed The data stored in the given index |
||
61 | * @throws OutOfBoundsException if index is out bounds. |
||
62 | */ |
||
63 | public function get($index) { |
||
70 | |||
71 | /** |
||
72 | * Returns the last node with O(1). |
||
73 | * |
||
74 | * @return mixed null if the array is empty. |
||
75 | */ |
||
76 | public function getLast() { |
||
83 | |||
84 | public function getAll() { |
||
89 | |||
90 | /** |
||
91 | * {@inheritDoc} |
||
92 | */ |
||
93 | public function contains($data) : bool { |
||
96 | |||
97 | /** |
||
98 | * {@inheritDoc} |
||
99 | */ |
||
100 | public function indexOf($data) { |
||
103 | |||
104 | /** |
||
105 | * {@inheritDoc} |
||
106 | */ |
||
107 | public function lastIndexOf($data) { |
||
116 | |||
117 | /** |
||
118 | * {@inheritDoc} |
||
119 | */ |
||
120 | public function remove($data) { |
||
134 | |||
135 | /** |
||
136 | * Delete a node in the given position and returns it back. |
||
137 | * |
||
138 | * @param integer $index the position. |
||
139 | * @throws OutOfBoundsException if index is negative |
||
140 | * or is greater than the size of the list. |
||
141 | */ |
||
142 | public function delete($index) { |
||
153 | |||
154 | /** |
||
155 | * Returns array stored in the data attribute. |
||
156 | * |
||
157 | * @return array data stored in all nodes. |
||
158 | */ |
||
159 | public function toArray() : array { |
||
162 | |||
163 | /** |
||
164 | * Reset the cursor position. |
||
165 | */ |
||
166 | public function rewind() { |
||
170 | |||
171 | /** |
||
172 | * Returns the current node data. |
||
173 | * |
||
174 | * @return mixed |
||
175 | */ |
||
176 | public function current() { |
||
179 | |||
180 | /** |
||
181 | * Key or index that indicates the cursor position. |
||
182 | * |
||
183 | * @return integer The current position. |
||
184 | */ |
||
185 | public function key() { |
||
188 | |||
189 | /** |
||
190 | * Move the cursor to the next node and increments the |
||
191 | * position counter. |
||
192 | */ |
||
193 | public function next() { |
||
197 | |||
198 | /** |
||
199 | * Returns if the current pointer position is valid. |
||
200 | * |
||
201 | * @return boolean true if pointer is not last, else false. |
||
202 | */ |
||
203 | public function valid() { |
||
206 | } |