http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 7 LOC: 116 Statements: 17
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Collection.php 100.0% 100.0% 100.0%
 
1
<?php
2
3
/**
4
 * Xyster Framework
5
 *
6
 * This source file is subject to the new BSD license that is bundled
7
 * with this package in the file LICENSE.txt.
8
 * It is also available through the world-wide-web at this URL:
9
 * http://www.opensource.org/licenses/bsd-license.php
10
 *
11
 * @category  Xyster
12
 * @package   Xyster_Collection
13
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
14
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
15
 * @version   $Id$
16
 */
17
namespace Xyster\Collection;
18
/**
19
 * Implementation of AbstractCollection with static helper methods
20
 *
21
 * @category  Xyster
22
 * @package   Xyster_Collection
23
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
24
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
25
 */
26
class Collection extends AbstractCollection
27 1
{
28
    /**
29
     * @var EmptyList
30
     */
31
    static private $_emptyList = null;
32
33
    /**
34
     * Creates a new simple collection
35
     *
36
     * @param ICollection $collection
37
     * @param boolean $immutable
38
     */
39
    public function __construct(ICollection $collection = null)
40
    {
41 53
        if ($collection) {
42 1
            $this->merge($collection);
43 1
        }
44
    }
45
46
    /**
47
     * Gets an immutable, empty list
48
     *
49
     * @return IList
50
     */
51
    static public function emptyList()
52
    {
53 1
        if (self::$_emptyList === null) {
54 1
            self::$_emptyList = new EmptyList;
55 1
        }
56 1
        return self::$_emptyList;
57
    }
58
59
    /**
60
     * Returns a new unchangable collection containing all the supplied values
61
     *
62
     * @param ICollection $collection
63
     * @return ICollection
64
     */
65
    static public function fixedCollection(ICollection $collection)
66
    {
67 15
        return new FixedCollection($collection);
68
    }
69
70
    /**
71
     * Returns a new unchangable list containing all the supplied values
72
     *
73
     * @param IList $list
74
     * @return IList
75
     */
76
    static public function fixedList(IList $list)
77
    {
78 1
        return new FixedList($list);
79
    }
80
81
    /**
82
     * Returns a new unchangable map containing all the supplied key/value pairs
83
     *
84
     * @param IMap $map
85
     * @return IMap
86
     */
87
    static public function fixedMap(IMap $map)
88
    {
89 1
        return new FixedMap($map);
90
    }
91
92
    /**
93
     * Returns a new unchangable set containing all the supplied values
94
     *
95
     * @param ISet $set
96
     * @return ISet
97
     */
98
    static public function fixedSet(ISet $set)
99
    {
100 12
        return new FixedSet($set);
101
    }
102
103
    /**
104
     * Creates a new collection containing the values
105
     *
106
     * @param array $values
107
     * @param boolean $immutable
108
     * @return ICollection
109
     */
110
    static public function using(array $values, $immutable = false)
111
    {
112 13
        $collection = new self;
113 13
        $collection->_items = array_values($values);
114 13
        return $immutable ? self::fixedCollection($collection) : $collection;
115
    }
116 1
}


Report generated at 2010-10-18T17:19:49-04:00