@@ 410-432 (lines=23) @@ | ||
407 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
408 | * @return EnumSet |
|
409 | */ |
|
410 | public function diff(...$others) |
|
411 | { |
|
412 | $clone = clone $this; |
|
413 | ||
414 | if (isset($others[0])) { |
|
415 | $bitset = $others[0]->bitset; |
|
416 | foreach ($others as $other) { |
|
417 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
418 | throw new InvalidArgumentException(sprintf( |
|
419 | 'Others should of the same enumeration as this %s', |
|
420 | __CLASS__, |
|
421 | $this->enumeration |
|
422 | )); |
|
423 | } |
|
424 | ||
425 | $bitset |= $other->bitset; |
|
426 | } |
|
427 | ||
428 | $clone->bitset = $this->bitset & ~$bitset; |
|
429 | } |
|
430 | ||
431 | return $clone; |
|
432 | } |
|
433 | ||
434 | /** |
|
435 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
@@ 442-464 (lines=23) @@ | ||
439 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
440 | * @return EnumSet |
|
441 | */ |
|
442 | public function symDiff(...$others) |
|
443 | { |
|
444 | $clone = clone $this; |
|
445 | ||
446 | if (isset($others[0])) { |
|
447 | $bitset = $others[0]->bitset; |
|
448 | foreach ($others as $other) { |
|
449 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
450 | throw new InvalidArgumentException(sprintf( |
|
451 | 'Others should be an instance of %s of the same enumeration as this %s', |
|
452 | __CLASS__, |
|
453 | $this->enumeration |
|
454 | )); |
|
455 | } |
|
456 | ||
457 | $bitset |= $other->bitset; |
|
458 | } |
|
459 | ||
460 | $clone->bitset = $this->bitset ^ $bitset; |
|
461 | } |
|
462 | ||
463 | return $clone; |
|
464 | } |
|
465 | ||
466 | /** |
|
467 | * Get ordinal numbers of the defined enumerators as array |