You are here

abstract class AbstractLazyCollection in Plug 7

Lazy collection that is backed by a concrete collection

@author Michaël Gallego <mic.gallego@gmail.com> @since 1.2

Hierarchy

Expanded class hierarchy of AbstractLazyCollection

1 file declares its use of AbstractLazyCollection
LazyArrayCollection.php in lib/doctrine/collections/tests/Doctrine/Tests/LazyArrayCollection.php

File

lib/doctrine/collections/lib/Doctrine/Common/Collections/AbstractLazyCollection.php, line 30

Namespace

Doctrine\Common\Collections
View source
abstract class AbstractLazyCollection implements Collection {

  /**
   * The backed collection to use
   *
   * @var Collection
   */
  protected $collection;

  /**
   * @var boolean
   */
  protected $initialized = false;

  /**
   * {@inheritDoc}
   */
  public function count() {
    $this
      ->initialize();
    return $this->collection
      ->count();
  }

  /**
   * {@inheritDoc}
   */
  public function add($element) {
    $this
      ->initialize();
    return $this->collection
      ->add($element);
  }

  /**
   * {@inheritDoc}
   */
  public function clear() {
    $this
      ->initialize();
    $this->collection
      ->clear();
  }

  /**
   * {@inheritDoc}
   */
  public function contains($element) {
    $this
      ->initialize();
    return $this->collection
      ->contains($element);
  }

  /**
   * {@inheritDoc}
   */
  public function isEmpty() {
    $this
      ->initialize();
    return $this->collection
      ->isEmpty();
  }

  /**
   * {@inheritDoc}
   */
  public function remove($key) {
    $this
      ->initialize();
    return $this->collection
      ->remove($key);
  }

  /**
   * {@inheritDoc}
   */
  public function removeElement($element) {
    $this
      ->initialize();
    return $this->collection
      ->removeElement($element);
  }

  /**
   * {@inheritDoc}
   */
  public function containsKey($key) {
    $this
      ->initialize();
    return $this->collection
      ->containsKey($key);
  }

  /**
   * {@inheritDoc}
   */
  public function get($key) {
    $this
      ->initialize();
    return $this->collection
      ->get($key);
  }

  /**
   * {@inheritDoc}
   */
  public function getKeys() {
    $this
      ->initialize();
    return $this->collection
      ->getKeys();
  }

  /**
   * {@inheritDoc}
   */
  public function getValues() {
    $this
      ->initialize();
    return $this->collection
      ->getValues();
  }

  /**
   * {@inheritDoc}
   */
  public function set($key, $value) {
    $this
      ->initialize();
    $this->collection
      ->set($key, $value);
  }

  /**
   * {@inheritDoc}
   */
  public function toArray() {
    $this
      ->initialize();
    return $this->collection
      ->toArray();
  }

  /**
   * {@inheritDoc}
   */
  public function first() {
    $this
      ->initialize();
    return $this->collection
      ->first();
  }

  /**
   * {@inheritDoc}
   */
  public function last() {
    $this
      ->initialize();
    return $this->collection
      ->last();
  }

  /**
   * {@inheritDoc}
   */
  public function key() {
    $this
      ->initialize();
    return $this->collection
      ->key();
  }

  /**
   * {@inheritDoc}
   */
  public function current() {
    $this
      ->initialize();
    return $this->collection
      ->current();
  }

  /**
   * {@inheritDoc}
   */
  public function next() {
    $this
      ->initialize();
    return $this->collection
      ->next();
  }

  /**
   * {@inheritDoc}
   */
  public function exists(Closure $p) {
    $this
      ->initialize();
    return $this->collection
      ->exists($p);
  }

  /**
   * {@inheritDoc}
   */
  public function filter(Closure $p) {
    $this
      ->initialize();
    return $this->collection
      ->filter($p);
  }

  /**
   * {@inheritDoc}
   */
  public function forAll(Closure $p) {
    $this
      ->initialize();
    return $this->collection
      ->forAll($p);
  }

  /**
   * {@inheritDoc}
   */
  public function map(Closure $func) {
    $this
      ->initialize();
    return $this->collection
      ->map($func);
  }

  /**
   * {@inheritDoc}
   */
  public function partition(Closure $p) {
    $this
      ->initialize();
    return $this->collection
      ->partition($p);
  }

  /**
   * {@inheritDoc}
   */
  public function indexOf($element) {
    $this
      ->initialize();
    return $this->collection
      ->indexOf($element);
  }

  /**
   * {@inheritDoc}
   */
  public function slice($offset, $length = null) {
    $this
      ->initialize();
    return $this->collection
      ->slice($offset, $length);
  }

  /**
   * {@inheritDoc}
   */
  public function getIterator() {
    $this
      ->initialize();
    return $this->collection
      ->getIterator();
  }

  /**
   * {@inheritDoc}
   */
  public function offsetExists($offset) {
    $this
      ->initialize();
    return $this->collection
      ->offsetExists($offset);
  }

  /**
   * {@inheritDoc}
   */
  public function offsetGet($offset) {
    $this
      ->initialize();
    return $this->collection
      ->offsetGet($offset);
  }

  /**
   * {@inheritDoc}
   */
  public function offsetSet($offset, $value) {
    $this
      ->initialize();
    $this->collection
      ->offsetSet($offset, $value);
  }

  /**
   * {@inheritDoc}
   */
  public function offsetUnset($offset) {
    $this
      ->initialize();
    $this->collection
      ->offsetUnset($offset);
  }

  /**
   * Is the lazy collection already initialized?
   *
   * @return bool
   */
  public function isInitialized() {
    return $this->initialized;
  }

  /**
   * Initialize the collection
   *
   * @return void
   */
  protected function initialize() {
    if (!$this->initialized) {
      $this
        ->doInitialize();
      $this->initialized = true;
    }
  }

  /**
   * Do the initialization logic
   *
   * @return void
   */
  protected abstract function doInitialize();

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractLazyCollection::$collection protected property The backed collection to use
AbstractLazyCollection::$initialized protected property
AbstractLazyCollection::add public function Adds an element at the end of the collection. Overrides Collection::add
AbstractLazyCollection::clear public function Clears the collection, removing all elements. Overrides Collection::clear
AbstractLazyCollection::contains public function Checks whether an element is contained in the collection. This is an O(n) operation, where n is the size of the collection. Overrides Collection::contains
AbstractLazyCollection::containsKey public function Checks whether the collection contains an element with the specified key/index. Overrides Collection::containsKey
AbstractLazyCollection::count public function
AbstractLazyCollection::current public function Gets the element of the collection at the current iterator position. Overrides Collection::current
AbstractLazyCollection::doInitialize abstract protected function Do the initialization logic 1
AbstractLazyCollection::exists public function Tests for the existence of an element that satisfies the given predicate. Overrides Collection::exists
AbstractLazyCollection::filter public function Returns all the elements of this collection that satisfy the predicate p. The order of the elements is preserved. Overrides Collection::filter
AbstractLazyCollection::first public function Sets the internal iterator to the first element in the collection and returns this element. Overrides Collection::first
AbstractLazyCollection::forAll public function Tests whether the given predicate p holds for all elements of this collection. Overrides Collection::forAll
AbstractLazyCollection::get public function Gets the element at the specified key/index. Overrides Collection::get
AbstractLazyCollection::getIterator public function
AbstractLazyCollection::getKeys public function Gets all keys/indices of the collection. Overrides Collection::getKeys
AbstractLazyCollection::getValues public function Gets all values of the collection. Overrides Collection::getValues
AbstractLazyCollection::indexOf public function Gets the index/key of a given element. The comparison of two elements is strict, that means not only the value but also the type must match. For objects this means reference equality. Overrides Collection::indexOf
AbstractLazyCollection::initialize protected function Initialize the collection
AbstractLazyCollection::isEmpty public function Checks whether the collection is empty (contains no elements). Overrides Collection::isEmpty
AbstractLazyCollection::isInitialized public function Is the lazy collection already initialized?
AbstractLazyCollection::key public function Gets the key/index of the element at the current iterator position. Overrides Collection::key
AbstractLazyCollection::last public function Sets the internal iterator to the last element in the collection and returns this element. Overrides Collection::last
AbstractLazyCollection::map public function Applies the given function to each element in the collection and returns a new collection with the elements returned by the function. Overrides Collection::map
AbstractLazyCollection::next public function Moves the internal iterator position to the next element and returns this element. Overrides Collection::next
AbstractLazyCollection::offsetExists public function
AbstractLazyCollection::offsetGet public function
AbstractLazyCollection::offsetSet public function
AbstractLazyCollection::offsetUnset public function
AbstractLazyCollection::partition public function Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections. Overrides Collection::partition
AbstractLazyCollection::remove public function Removes the element at the specified index from the collection. Overrides Collection::remove
AbstractLazyCollection::removeElement public function Removes the specified element from the collection, if it is found. Overrides Collection::removeElement
AbstractLazyCollection::set public function Sets an element in the collection at the specified key/index. Overrides Collection::set
AbstractLazyCollection::slice public function Extracts a slice of $length elements starting at position $offset from the Collection. Overrides Collection::slice
AbstractLazyCollection::toArray public function Gets a native PHP array representation of the collection. Overrides Collection::toArray