3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Common\Collections;
25 * Lazy collection that is backed by a concrete collection
27 * @author Michaƫl Gallego <mic.gallego@gmail.com>
30 abstract class AbstractLazyCollection implements Collection
33 * The backed collection to use
37 protected $collection;
42 protected $initialized = false;
47 public function count()
50 return $this->collection->count();
56 public function add($element)
59 return $this->collection->add($element);
65 public function clear()
68 $this->collection->clear();
74 public function contains($element)
77 return $this->collection->contains($element);
83 public function isEmpty()
86 return $this->collection->isEmpty();
92 public function remove($key)
95 return $this->collection->remove($key);
101 public function removeElement($element)
104 return $this->collection->removeElement($element);
110 public function containsKey($key)
113 return $this->collection->containsKey($key);
119 public function get($key)
122 return $this->collection->get($key);
128 public function getKeys()
131 return $this->collection->getKeys();
137 public function getValues()
140 return $this->collection->getValues();
146 public function set($key, $value)
149 $this->collection->set($key, $value);
155 public function toArray()
158 return $this->collection->toArray();
164 public function first()
167 return $this->collection->first();
173 public function last()
176 return $this->collection->last();
182 public function key()
185 return $this->collection->key();
191 public function current()
194 return $this->collection->current();
200 public function next()
203 return $this->collection->next();
209 public function exists(Closure $p)
212 return $this->collection->exists($p);
218 public function filter(Closure $p)
221 return $this->collection->filter($p);
227 public function forAll(Closure $p)
230 return $this->collection->forAll($p);
236 public function map(Closure $func)
239 return $this->collection->map($func);
245 public function partition(Closure $p)
248 return $this->collection->partition($p);
254 public function indexOf($element)
257 return $this->collection->indexOf($element);
263 public function slice($offset, $length = null)
266 return $this->collection->slice($offset, $length);
272 public function getIterator()
275 return $this->collection->getIterator();
281 public function offsetExists($offset)
284 return $this->collection->offsetExists($offset);
290 public function offsetGet($offset)
293 return $this->collection->offsetGet($offset);
299 public function offsetSet($offset, $value)
302 $this->collection->offsetSet($offset, $value);
308 public function offsetUnset($offset)
311 $this->collection->offsetUnset($offset);
315 * Is the lazy collection already initialized?
319 public function isInitialized()
321 return $this->initialized;
325 * Initialize the collection
329 protected function initialize()
331 if ( ! $this->initialized) {
332 $this->doInitialize();
333 $this->initialized = true;
338 * Do the initialization logic
342 abstract protected function doInitialize();