ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBuddySystemArrayCollection.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Contact/BuddySystem/interfaces/interface.ilBuddySystemCollection.php';
5
12{
16 private $elements = array();
17
21 public function __construct(array $elements = array())
22 {
23 $this->elements = $elements;
24 }
25
29 public function getIterator()
30 {
31 return new ArrayIterator($this->elements);
32 }
33
37 public function offsetExists($offset)
38 {
39 return $this->containsKey($offset);
40 }
41
45 public function offsetGet($offset)
46 {
47 return $this->get($offset);
48 }
49
53 public function offsetSet($offset, $value)
54 {
55 if (!isset($offset)) {
56 $this->add($value);
57 return;
58 }
59
60 $this->set($offset, $value);
61 }
62
66 public function offsetUnset($offset)
67 {
68 $this->remove($offset);
69 }
70
74 public function count()
75 {
76 return count($this->elements);
77 }
78
82 public function add($element)
83 {
84 $this->elements[] = $element;
85 }
86
90 public function remove($key)
91 {
92 if (!isset($this->elements[$key]) && !array_key_exists($key, $this->elements)) {
93 throw new InvalidArgumentException(sprintf("Could not find an element for key: ", $key));
94 }
95 unset($this->elements[$key]);
96 }
97
101 public function removeElement($element)
102 {
103 $key = array_search($element, $this->elements, true);
104 if (false === $key) {
105 throw new InvalidArgumentException("Could not find an key for the passed element.");
106 }
107 unset($this->elements[$key]);
108 }
109
113 public function containsKey($key)
114 {
115 return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
116 }
117
122 public function getKey($element)
123 {
124 return array_search($element, $this->elements, true);
125 }
126
130 public function clear()
131 {
132 $this->elements = array();
133 }
134
138 public function contains($element)
139 {
140 return in_array($element, $this->elements, true);
141 }
142
146 public function get($key)
147 {
148 return isset($this->elements[$key]) ? $this->elements[$key] : null;
149 }
150
154 public function set($key, $value)
155 {
156 $this->elements[$key] = $value;
157 }
158
162 public function isEmpty()
163 {
164 return empty($this->elements);
165 }
166
170 public function getKeys()
171 {
172 return array_keys($this->elements);
173 }
174
178 public function getValues()
179 {
180 return array_values($this->elements);
181 }
182
186 public function filter(Closure $p)
187 {
188 return new static(array_filter($this->elements, $p));
189 }
190
194 public function slice($offset, $length = null)
195 {
196 return new static(array_slice($this->elements, $offset, $length, true));
197 }
198
202 public function toArray()
203 {
204 return $this->elements;
205 }
206}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class ilBuddySystemArrayCollection A collection which contains all entries of a buddy list.
contains($element)
boolean true if the collection contains the element, false otherwise.
containsKey($key)
boolean true if the collection contains the element, false otherwise.
slice($offset, $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection....
isEmpty()
boolean true if the collection is empty, false otherwise.
filter(Closure $p)
Returns all the elements of this collection that satisfy the predicate $callable.ilBuddySystemCollect...
getKeys()
Gets all indices of the collection.array The indices of the collection, in the order of the correspon...
add($element)
Adds an element at the end of the collection.
getValues()
Gets all values of the collection.array The values of all elements in the collection,...
$key
Definition: croninfo.php:18
Interface ilBuddySystemCollection.