1 | <?php |
||
39 | class ArrayList implements IteratorAggregate, Countable { |
||
40 | |||
41 | /** @var array */ |
||
42 | private $items; |
||
43 | |||
44 | /** |
||
45 | * Class constructor. |
||
46 | * @param array $items |
||
47 | * @throws \InvalidArgumentException |
||
48 | */ |
||
49 | 1 | public function __construct(array $items = []) { |
|
52 | |||
53 | /** |
||
54 | * Return the list item by index. |
||
55 | * @param integer $index |
||
56 | * @throws \Brickoo\Component\Common\Exception\InvalidIndexException |
||
57 | * @return string |
||
58 | */ |
||
59 | 2 | public function get($index) { |
|
66 | |||
67 | /** |
||
68 | * Add an item to the list. |
||
69 | * @param mixed $value |
||
70 | * @return \Brickoo\Component\Common\ArrayList |
||
71 | */ |
||
72 | 1 | public function add($value) { |
|
76 | |||
77 | /** |
||
78 | * @param integer $index |
||
79 | * @return \Brickoo\Component\Common\ArrayList |
||
80 | * @throws InvalidIndexException |
||
81 | */ |
||
82 | 2 | public function remove($index) { |
|
90 | |||
91 | /** |
||
92 | * Reverse the items order. |
||
93 | * @return \Brickoo\Component\Common\ArrayList |
||
94 | */ |
||
95 | 1 | public function reverse() { |
|
101 | |||
102 | /** |
||
103 | * Shuffle the items order. |
||
104 | * @return \Brickoo\Component\Common\ArrayList |
||
105 | */ |
||
106 | 1 | public function shuffle() { |
|
110 | |||
111 | /** |
||
112 | * Remove duplicate items from list. |
||
113 | * @return \Brickoo\Component\Common\ArrayList |
||
114 | */ |
||
115 | 1 | public function uniquify() { |
|
119 | |||
120 | /** |
||
121 | * Check if an item with the index is available. |
||
122 | * @param integer $index |
||
123 | * @return boolean |
||
124 | */ |
||
125 | 1 | public function has($index) { |
|
129 | |||
130 | /** |
||
131 | * Return the index of the first occurrence of the value. |
||
132 | * Return -1 if the value is not in list. |
||
133 | * @param mixed $value |
||
134 | * @return integer |
||
135 | */ |
||
136 | 1 | public function indexOf($value) { |
|
140 | |||
141 | /** |
||
142 | * Check if list contains a value. |
||
143 | * @param mixed $value |
||
144 | * @return boolean |
||
145 | */ |
||
146 | 1 | public function contains($value) { |
|
149 | |||
150 | /** |
||
151 | * Return the first item in list or null if empty list. |
||
152 | * @throws \Brickoo\Component\Common\Exception\InvalidIndexException |
||
153 | * @return mixed |
||
154 | */ |
||
155 | 1 | public function first() { |
|
163 | |||
164 | /** |
||
165 | * Return the last item in list or null if empty list. |
||
166 | * @throws \Brickoo\Component\Common\Exception\InvalidIndexException |
||
167 | * @return mixed |
||
168 | */ |
||
169 | 1 | public function last() { |
|
178 | |||
179 | /** |
||
180 | * Check if the list is empty. |
||
181 | * @return boolean |
||
182 | */ |
||
183 | 1 | public function isEmpty() { |
|
186 | |||
187 | /** |
||
188 | * Return the list items as an array. |
||
189 | * @return array |
||
190 | */ |
||
191 | 3 | public function toArray() { |
|
194 | |||
195 | /** |
||
196 | * Retrieve an external iterator containing all items. |
||
197 | * @return \ArrayIterator |
||
198 | */ |
||
199 | 1 | public function getIterator() { |
|
202 | |||
203 | /** |
||
204 | * Count number of list items. |
||
205 | * @return integer |
||
206 | */ |
||
207 | 1 | public function count() { |
|
210 | |||
211 | /** |
||
212 | * Return a string representation of the list. |
||
213 | * The values are linefeed separated. |
||
214 | * @return string |
||
215 | */ |
||
216 | 1 | public function toString() { |
|
227 | |||
228 | } |
||
229 |