@@ 349-367 (lines=19) @@ | ||
346 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
347 | * @return EnumSet |
|
348 | */ |
|
349 | public function union(EnumSet $other) |
|
350 | { |
|
351 | $bitset = $this->bitset; |
|
352 | foreach (func_get_args() as $other) { |
|
353 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
354 | throw new InvalidArgumentException(sprintf( |
|
355 | "Others should be an instance of %s of the same enumeration as this %s", |
|
356 | __CLASS__, |
|
357 | $this->enumeration |
|
358 | )); |
|
359 | } |
|
360 | ||
361 | $bitset |= $other->bitset; |
|
362 | } |
|
363 | ||
364 | $clone = clone $this; |
|
365 | $clone->bitset = $bitset; |
|
366 | return $clone; |
|
367 | } |
|
368 | ||
369 | /** |
|
370 | * Produce a new set with enumerators common to both this and other (this & other) |
|
@@ 374-392 (lines=19) @@ | ||
371 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
372 | * @return EnumSet |
|
373 | */ |
|
374 | public function intersect(EnumSet $other) |
|
375 | { |
|
376 | $bitset = $this->bitset; |
|
377 | foreach (func_get_args() as $other) { |
|
378 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
379 | throw new InvalidArgumentException(sprintf( |
|
380 | "Others should be an instance of %s of the same enumeration as this %s", |
|
381 | __CLASS__, |
|
382 | $this->enumeration |
|
383 | )); |
|
384 | } |
|
385 | ||
386 | $bitset &= $other->bitset; |
|
387 | } |
|
388 | ||
389 | $clone = clone $this; |
|
390 | $clone->bitset = $bitset; |
|
391 | return $clone; |
|
392 | } |
|
393 | ||
394 | /** |
|
395 | * Produce a new set with enumerators in this but not in other (this - other) |
|
@@ 399-417 (lines=19) @@ | ||
396 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
397 | * @return EnumSet |
|
398 | */ |
|
399 | public function diff(EnumSet $other) |
|
400 | { |
|
401 | $bitset = $other->bitset; |
|
402 | foreach (func_get_args() as $other) { |
|
403 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
404 | throw new InvalidArgumentException(sprintf( |
|
405 | "Others should be an instance of %s of the same enumeration as this %s", |
|
406 | __CLASS__, |
|
407 | $this->enumeration |
|
408 | )); |
|
409 | } |
|
410 | ||
411 | $bitset |= $other->bitset; |
|
412 | } |
|
413 | ||
414 | $clone = clone $this; |
|
415 | $clone->bitset = $this->bitset & ~$bitset; |
|
416 | return $clone; |
|
417 | } |
|
418 | ||
419 | /** |
|
420 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
@@ 424-442 (lines=19) @@ | ||
421 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
422 | * @return EnumSet |
|
423 | */ |
|
424 | public function symDiff(EnumSet $other) |
|
425 | { |
|
426 | $bitset = $other->bitset; |
|
427 | foreach (func_get_args() as $other) { |
|
428 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
429 | throw new InvalidArgumentException(sprintf( |
|
430 | "Others should be an instance of %s of the same enumeration as this %s", |
|
431 | __CLASS__, |
|
432 | $this->enumeration |
|
433 | )); |
|
434 | } |
|
435 | ||
436 | $bitset |= $other->bitset; |
|
437 | } |
|
438 | ||
439 | $clone = clone $this; |
|
440 | $clone->bitset = $this->bitset ^ $bitset; |
|
441 | return $clone; |
|
442 | } |
|
443 | ||
444 | /** |
|
445 | * Get ordinal numbers of the defined enumerators as array |