# AbstractCollection.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2008 by Denis M. Gabaidulin                             *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00012     abstract class AbstractCollection implements Collection
    00013     {
    00014         protected $items  = array();
    00015
    00016         public function add(CollectionItem $item)
    00017         {
    00018             $this->items[$item->getId()] = $item;
    00019
    00020             return $this;
    00021         }
    00022
    00023         public function addAll(array /*of CollectionItem*/ $items)
    00024         {
    00025             foreach ($items as $item)
    00026                 $this->items[$item->getId()] = $item;
    00027
    00028             return $this;
    00029         }
    00030
    00031         public function clear()
    00032         {
    00033             $this->items = array();
    00034
    00035             return $this;
    00036         }
    00037
    00038         public function contains(CollectionItem $item)
    00039         {
    00040             return isset($this->items[$item->getId()]);
    00041         }
    00042
    00043         public function containsAll(array /*of CollectionItem*/ $items)
    00044         {
    00045             return (array_intersect($items, $this->items) == $items);
    00046         }
    00047
    00048         public function isEmpty()
    00049         {
    00050             return (count($this->items) == 0);
    00051         }
    00052
    00053         public function size()
    00054         {
    00055             return count($this->items);
    00056         }
    00057
    00058         public function remove(CollectionItem $item)
    00059         {
    00060             if (isset($this->items[$item->getId()]))
    00061                 unset($this->items[$item->getId()]);
    00062
    00063             return $this;
    00064         }
    00065
    00066         public function removeAll(array /*of CollectionItem*/ $items)
    00067         {
    00068             $this->items = array_diff($this->items, $items);
    00069
    00070             return $this;
    00071         }
    00072
    00073         public function retainAll(array /*of CollectionItem*/ $items)
    00074         {
    00075             $this->items = $items;
    00076
    00077             return $this;
    00078         }
    00079
    00080         public function getList()
    00081         {
    00082             return $this->items;
    00083         }
    00084
    00088         public function getByName($name)
    00089         {
    00090             return $this->items[$name];
    00091         }
    00092
    00093         public function has($name)
    00094         {
    00095             return isset($this->items[$name]);
    00096         }
    00097     }
    00098 ?>