annotate vendor/doctrine/collections/lib/Doctrine/Common/Collections/Collection.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2 /*
Chris@0 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@0 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@0 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@0 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Chris@0 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Chris@0 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Chris@0 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Chris@0 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Chris@0 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Chris@0 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Chris@0 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@0 14 *
Chris@0 15 * This software consists of voluntary contributions made by many individuals
Chris@0 16 * and is licensed under the MIT license. For more information, see
Chris@0 17 * <http://www.doctrine-project.org>.
Chris@0 18 */
Chris@0 19
Chris@0 20 namespace Doctrine\Common\Collections;
Chris@0 21
Chris@0 22 use ArrayAccess;
Chris@0 23 use Closure;
Chris@0 24 use Countable;
Chris@0 25 use IteratorAggregate;
Chris@0 26
Chris@0 27 /**
Chris@0 28 * The missing (SPL) Collection/Array/OrderedMap interface.
Chris@0 29 *
Chris@0 30 * A Collection resembles the nature of a regular PHP array. That is,
Chris@0 31 * it is essentially an <b>ordered map</b> that can also be used
Chris@0 32 * like a list.
Chris@0 33 *
Chris@0 34 * A Collection has an internal iterator just like a PHP array. In addition,
Chris@0 35 * a Collection can be iterated with external iterators, which is preferable.
Chris@0 36 * To use an external iterator simply use the foreach language construct to
Chris@0 37 * iterate over the collection (which calls {@link getIterator()} internally) or
Chris@0 38 * explicitly retrieve an iterator though {@link getIterator()} which can then be
Chris@0 39 * used to iterate over the collection.
Chris@0 40 * You can not rely on the internal iterator of the collection being at a certain
Chris@0 41 * position unless you explicitly positioned it before. Prefer iteration with
Chris@0 42 * external iterators.
Chris@0 43 *
Chris@0 44 * @since 2.0
Chris@0 45 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
Chris@0 46 * @author Jonathan Wage <jonwage@gmail.com>
Chris@0 47 * @author Roman Borschel <roman@code-factory.org>
Chris@0 48 */
Chris@0 49 interface Collection extends Countable, IteratorAggregate, ArrayAccess
Chris@0 50 {
Chris@0 51 /**
Chris@0 52 * Adds an element at the end of the collection.
Chris@0 53 *
Chris@0 54 * @param mixed $element The element to add.
Chris@0 55 *
Chris@0 56 * @return boolean Always TRUE.
Chris@0 57 */
Chris@0 58 public function add($element);
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Clears the collection, removing all elements.
Chris@0 62 *
Chris@0 63 * @return void
Chris@0 64 */
Chris@0 65 public function clear();
Chris@0 66
Chris@0 67 /**
Chris@0 68 * Checks whether an element is contained in the collection.
Chris@0 69 * This is an O(n) operation, where n is the size of the collection.
Chris@0 70 *
Chris@0 71 * @param mixed $element The element to search for.
Chris@0 72 *
Chris@0 73 * @return boolean TRUE if the collection contains the element, FALSE otherwise.
Chris@0 74 */
Chris@0 75 public function contains($element);
Chris@0 76
Chris@0 77 /**
Chris@0 78 * Checks whether the collection is empty (contains no elements).
Chris@0 79 *
Chris@0 80 * @return boolean TRUE if the collection is empty, FALSE otherwise.
Chris@0 81 */
Chris@0 82 public function isEmpty();
Chris@0 83
Chris@0 84 /**
Chris@0 85 * Removes the element at the specified index from the collection.
Chris@0 86 *
Chris@0 87 * @param string|integer $key The kex/index of the element to remove.
Chris@0 88 *
Chris@0 89 * @return mixed The removed element or NULL, if the collection did not contain the element.
Chris@0 90 */
Chris@0 91 public function remove($key);
Chris@0 92
Chris@0 93 /**
Chris@0 94 * Removes the specified element from the collection, if it is found.
Chris@0 95 *
Chris@0 96 * @param mixed $element The element to remove.
Chris@0 97 *
Chris@0 98 * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
Chris@0 99 */
Chris@0 100 public function removeElement($element);
Chris@0 101
Chris@0 102 /**
Chris@0 103 * Checks whether the collection contains an element with the specified key/index.
Chris@0 104 *
Chris@0 105 * @param string|integer $key The key/index to check for.
Chris@0 106 *
Chris@0 107 * @return boolean TRUE if the collection contains an element with the specified key/index,
Chris@0 108 * FALSE otherwise.
Chris@0 109 */
Chris@0 110 public function containsKey($key);
Chris@0 111
Chris@0 112 /**
Chris@0 113 * Gets the element at the specified key/index.
Chris@0 114 *
Chris@0 115 * @param string|integer $key The key/index of the element to retrieve.
Chris@0 116 *
Chris@0 117 * @return mixed
Chris@0 118 */
Chris@0 119 public function get($key);
Chris@0 120
Chris@0 121 /**
Chris@0 122 * Gets all keys/indices of the collection.
Chris@0 123 *
Chris@0 124 * @return array The keys/indices of the collection, in the order of the corresponding
Chris@0 125 * elements in the collection.
Chris@0 126 */
Chris@0 127 public function getKeys();
Chris@0 128
Chris@0 129 /**
Chris@0 130 * Gets all values of the collection.
Chris@0 131 *
Chris@0 132 * @return array The values of all elements in the collection, in the order they
Chris@0 133 * appear in the collection.
Chris@0 134 */
Chris@0 135 public function getValues();
Chris@0 136
Chris@0 137 /**
Chris@0 138 * Sets an element in the collection at the specified key/index.
Chris@0 139 *
Chris@0 140 * @param string|integer $key The key/index of the element to set.
Chris@0 141 * @param mixed $value The element to set.
Chris@0 142 *
Chris@0 143 * @return void
Chris@0 144 */
Chris@0 145 public function set($key, $value);
Chris@0 146
Chris@0 147 /**
Chris@0 148 * Gets a native PHP array representation of the collection.
Chris@0 149 *
Chris@0 150 * @return array
Chris@0 151 */
Chris@0 152 public function toArray();
Chris@0 153
Chris@0 154 /**
Chris@0 155 * Sets the internal iterator to the first element in the collection and returns this element.
Chris@0 156 *
Chris@0 157 * @return mixed
Chris@0 158 */
Chris@0 159 public function first();
Chris@0 160
Chris@0 161 /**
Chris@0 162 * Sets the internal iterator to the last element in the collection and returns this element.
Chris@0 163 *
Chris@0 164 * @return mixed
Chris@0 165 */
Chris@0 166 public function last();
Chris@0 167
Chris@0 168 /**
Chris@0 169 * Gets the key/index of the element at the current iterator position.
Chris@0 170 *
Chris@0 171 * @return int|string
Chris@0 172 */
Chris@0 173 public function key();
Chris@0 174
Chris@0 175 /**
Chris@0 176 * Gets the element of the collection at the current iterator position.
Chris@0 177 *
Chris@0 178 * @return mixed
Chris@0 179 */
Chris@0 180 public function current();
Chris@0 181
Chris@0 182 /**
Chris@0 183 * Moves the internal iterator position to the next element and returns this element.
Chris@0 184 *
Chris@0 185 * @return mixed
Chris@0 186 */
Chris@0 187 public function next();
Chris@0 188
Chris@0 189 /**
Chris@0 190 * Tests for the existence of an element that satisfies the given predicate.
Chris@0 191 *
Chris@0 192 * @param Closure $p The predicate.
Chris@0 193 *
Chris@0 194 * @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
Chris@0 195 */
Chris@0 196 public function exists(Closure $p);
Chris@0 197
Chris@0 198 /**
Chris@0 199 * Returns all the elements of this collection that satisfy the predicate p.
Chris@0 200 * The order of the elements is preserved.
Chris@0 201 *
Chris@0 202 * @param Closure $p The predicate used for filtering.
Chris@0 203 *
Chris@0 204 * @return Collection A collection with the results of the filter operation.
Chris@0 205 */
Chris@0 206 public function filter(Closure $p);
Chris@0 207
Chris@0 208 /**
Chris@0 209 * Tests whether the given predicate p holds for all elements of this collection.
Chris@0 210 *
Chris@0 211 * @param Closure $p The predicate.
Chris@0 212 *
Chris@0 213 * @return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
Chris@0 214 */
Chris@0 215 public function forAll(Closure $p);
Chris@0 216
Chris@0 217 /**
Chris@0 218 * Applies the given function to each element in the collection and returns
Chris@0 219 * a new collection with the elements returned by the function.
Chris@0 220 *
Chris@0 221 * @param Closure $func
Chris@0 222 *
Chris@0 223 * @return Collection
Chris@0 224 */
Chris@0 225 public function map(Closure $func);
Chris@0 226
Chris@0 227 /**
Chris@0 228 * Partitions this collection in two collections according to a predicate.
Chris@0 229 * Keys are preserved in the resulting collections.
Chris@0 230 *
Chris@0 231 * @param Closure $p The predicate on which to partition.
Chris@0 232 *
Chris@0 233 * @return array An array with two elements. The first element contains the collection
Chris@0 234 * of elements where the predicate returned TRUE, the second element
Chris@0 235 * contains the collection of elements where the predicate returned FALSE.
Chris@0 236 */
Chris@0 237 public function partition(Closure $p);
Chris@0 238
Chris@0 239 /**
Chris@0 240 * Gets the index/key of a given element. The comparison of two elements is strict,
Chris@0 241 * that means not only the value but also the type must match.
Chris@0 242 * For objects this means reference equality.
Chris@0 243 *
Chris@0 244 * @param mixed $element The element to search for.
Chris@0 245 *
Chris@0 246 * @return int|string|bool The key/index of the element or FALSE if the element was not found.
Chris@0 247 */
Chris@0 248 public function indexOf($element);
Chris@0 249
Chris@0 250 /**
Chris@0 251 * Extracts a slice of $length elements starting at position $offset from the Collection.
Chris@0 252 *
Chris@0 253 * If $length is null it returns all elements from $offset to the end of the Collection.
Chris@0 254 * Keys have to be preserved by this method. Calling this method will only return the
Chris@0 255 * selected slice and NOT change the elements contained in the collection slice is called on.
Chris@0 256 *
Chris@0 257 * @param int $offset The offset to start from.
Chris@0 258 * @param int|null $length The maximum number of elements to return, or null for no limit.
Chris@0 259 *
Chris@0 260 * @return array
Chris@0 261 */
Chris@0 262 public function slice($offset, $length = null);
Chris@0 263 }