1 | <?php |
||
35 | class CollectionUtils extends Object |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Standardconstructor that marks this class as util class. |
||
40 | */ |
||
41 | protected function __construct() |
||
45 | |||
46 | /** |
||
47 | * This method iterates over the passed IndexedCollection and invokes the evaluate |
||
48 | * method of the although passed Predicate on every object of the IndexedCollection. |
||
49 | * If the evaluate method returns false, the object is removed from the passed |
||
50 | * IndexedCollection. |
||
51 | * |
||
52 | * @param \AppserverIo\Collections\CollectionInterface $collection Holds the IndexedCollection that should be filtered |
||
53 | * @param \AppserverIo\Collections\PredicateInterface $predicate The Predicate that should be used for evaluation purposes |
||
54 | * @param integer $iterations Holds the size of successful iterations, after that the filter should run |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | 1 | public static function filter(CollectionInterface $collection, PredicateInterface $predicate, $iterations = 0) |
|
84 | |||
85 | /** |
||
86 | * Finds the first element in the given collection which matches |
||
87 | * the given predicate. |
||
88 | * |
||
89 | * If no element of the collection matches the predicate, null is |
||
90 | * returned. |
||
91 | * |
||
92 | * @param \AppserverIo\Collections\CollectionInterface $collection The collection to search |
||
93 | * @param \AppserverIo\Collections\PredicateInterface $predicate The predicate to use |
||
94 | * |
||
95 | * @return object Returns the first element of the collection which matches the predicate or null if none could be found |
||
96 | */ |
||
97 | public static function find(CollectionInterface $collection, PredicateInterface $predicate) |
||
110 | |||
111 | /** |
||
112 | * This method iterates over the passed Collection and invokes the |
||
113 | * evaluate method of the although passed Predicate on every object |
||
114 | * of the Collection. |
||
115 | * If the evaluate method returns true the method |
||
116 | * returns true also. |
||
117 | * |
||
118 | * @param \AppserverIo\Collections\CollectionInterface $collection Holds the IndexedCollection that should be filtered |
||
119 | * @param \AppserverIo\Collections\PredicateInterface $predicate The Predicate that should be used for evaluation purposes |
||
120 | * |
||
121 | * @return boolean TRUE if the evaluate method of the Predicate returns TRUE |
||
122 | */ |
||
123 | public static function exists(CollectionInterface $collection, PredicateInterface $predicate) |
||
136 | |||
137 | /** |
||
138 | * This method iterates over the passed Collection and invokes |
||
139 | * the evaluate method of the although passed Predicate on every object |
||
140 | * of the Collection. |
||
141 | * If the evaluate method returns |
||
142 | * true the method returns the key of the object. |
||
143 | * |
||
144 | * @param \AppserverIo\Collections\CollectionInterface $collection Holds the Collection that should be filtered |
||
145 | * @param \AppserverIo\Collections\PredicateInterface $predicate The Predicate that should be used for evaluation purposes |
||
146 | * |
||
147 | * @return mixed Holds the key of the first object with it's evaluate() method returning TRUE |
||
148 | */ |
||
149 | public static function findKey(CollectionInterface $collection, PredicateInterface $predicate) |
||
162 | |||
163 | /** |
||
164 | * Returns a new Collection containing a - b. |
||
165 | * The cardinality of each |
||
166 | * element e in the returned Collection will be the cardinality of e |
||
167 | * in a minus the cardinality of e in b, or zero, whichever is greater. |
||
168 | * |
||
169 | * @param \AppserverIo\Collections\CollectionInterface $a The Collection to subtract from, must not be null |
||
170 | * @param \AppserverIo\Collections\CollectionInterface $b The Collection to subtract, must not be null |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public static function subtract(CollectionInterface $a, CollectionInterface $b) |
||
191 | |||
192 | /** |
||
193 | * This method sorts the passed collection depending |
||
194 | * on the comparator. |
||
195 | * |
||
196 | * @param \AppserverIo\Collections\CollectionInterface $collection Holds the Collection that should be sorted |
||
197 | * @param \AppserverIo\Collections\ComparatorInterface $comperator The Comparator that should be used for compare purposes |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | 2 | public static function sort(CollectionInterface $collection, ComparatorInterface $comperator) |
|
210 | |||
211 | /** |
||
212 | * Sorts the passed array. |
||
213 | * |
||
214 | * @param array $src The Array to be sorted |
||
215 | * @param integer $low The offset we start sorting |
||
216 | * @param integer $high The number of elements to be sorted |
||
217 | * @param \AppserverIo\Collections\ComparatorInterface $comperator The comperator used for sorting |
||
218 | * |
||
219 | * @return array The sorted array |
||
220 | */ |
||
221 | 2 | protected static function arraySort($src, $low, $high, ComparatorInterface $comperator) |
|
232 | |||
233 | /** |
||
234 | * Swaps x[a] with x[b]. |
||
235 | * |
||
236 | * @param array $x The array with the values to be swapped |
||
237 | * @param integer $a The position of the element to be swapped |
||
238 | * @param integer $b The position of the element to swap $a with |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | 2 | protected static function swap($x, $a, $b) |
|
249 | } |
||
250 |