@@ 253-271 (lines=19) @@ | ||
250 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
251 | * @return EnumSet |
|
252 | */ |
|
253 | public function union(EnumSet $other) |
|
254 | { |
|
255 | $bitset = $this->bitset; |
|
256 | foreach (func_get_args() as $other) { |
|
257 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
258 | throw new InvalidArgumentException(sprintf( |
|
259 | "Others should be an instance of %s of the same enumeration as this %s", |
|
260 | __CLASS__, |
|
261 | $this->enumeration |
|
262 | )); |
|
263 | } |
|
264 | ||
265 | $bitset |= $other->bitset; |
|
266 | } |
|
267 | ||
268 | $clone = clone $this; |
|
269 | $clone->bitset = $bitset; |
|
270 | return $clone; |
|
271 | } |
|
272 | ||
273 | /** |
|
274 | * Produce a new set with enumerators common to both this and other (this & other) |
|
@@ 278-296 (lines=19) @@ | ||
275 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
276 | * @return EnumSet |
|
277 | */ |
|
278 | public function intersect(EnumSet $other) |
|
279 | { |
|
280 | $bitset = $this->bitset; |
|
281 | foreach (func_get_args() as $other) { |
|
282 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
283 | throw new InvalidArgumentException(sprintf( |
|
284 | "Others should be an instance of %s of the same enumeration as this %s", |
|
285 | __CLASS__, |
|
286 | $this->enumeration |
|
287 | )); |
|
288 | } |
|
289 | ||
290 | $bitset &= $other->bitset; |
|
291 | } |
|
292 | ||
293 | $clone = clone $this; |
|
294 | $clone->bitset = $bitset; |
|
295 | return $clone; |
|
296 | } |
|
297 | ||
298 | /** |
|
299 | * Produce a new set with enumerators in this but not in other (this - other) |
|
@@ 303-321 (lines=19) @@ | ||
300 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
301 | * @return EnumSet |
|
302 | */ |
|
303 | public function diff(EnumSet $other) |
|
304 | { |
|
305 | $bitset = ''; |
|
306 | foreach (func_get_args() as $other) { |
|
307 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
308 | throw new InvalidArgumentException(sprintf( |
|
309 | "Others should be an instance of %s of the same enumeration as this %s", |
|
310 | __CLASS__, |
|
311 | $this->enumeration |
|
312 | )); |
|
313 | } |
|
314 | ||
315 | $bitset |= $other->bitset; |
|
316 | } |
|
317 | ||
318 | $clone = clone $this; |
|
319 | $clone->bitset = $this->bitset & ~$bitset; |
|
320 | return $clone; |
|
321 | } |
|
322 | ||
323 | /** |
|
324 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
@@ 328-346 (lines=19) @@ | ||
325 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
326 | * @return EnumSet |
|
327 | */ |
|
328 | public function symDiff(EnumSet $other) |
|
329 | { |
|
330 | $bitset = ''; |
|
331 | foreach (func_get_args() as $other) { |
|
332 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
333 | throw new InvalidArgumentException(sprintf( |
|
334 | "Others should be an instance of %s of the same enumeration as this %s", |
|
335 | __CLASS__, |
|
336 | $this->enumeration |
|
337 | )); |
|
338 | } |
|
339 | ||
340 | $bitset |= $other->bitset; |
|
341 | } |
|
342 | ||
343 | $clone = clone $this; |
|
344 | $clone->bitset = $this->bitset ^ $bitset; |
|
345 | return $clone; |
|
346 | } |
|
347 | ||
348 | /** |
|
349 | * Get ordinal numbers of the defined enumerators as array |