| @@ 434-456 (lines=23) @@ | ||
| 431 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
| 432 | * @return EnumSet |
|
| 433 | */ |
|
| 434 | public function diff(...$others) |
|
| 435 | { |
|
| 436 | $clone = clone $this; |
|
| 437 | ||
| 438 | if (isset($others[0])) { |
|
| 439 | $bitset = $others[0]->bitset; |
|
| 440 | foreach ($others as $other) { |
|
| 441 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
| 442 | throw new InvalidArgumentException(sprintf( |
|
| 443 | 'Others should of the same enumeration as this %s', |
|
| 444 | __CLASS__, |
|
| 445 | $this->enumeration |
|
| 446 | )); |
|
| 447 | } |
|
| 448 | ||
| 449 | $bitset |= $other->bitset; |
|
| 450 | } |
|
| 451 | ||
| 452 | $clone->bitset = $this->bitset & ~$bitset; |
|
| 453 | } |
|
| 454 | ||
| 455 | return $clone; |
|
| 456 | } |
|
| 457 | ||
| 458 | /** |
|
| 459 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
| @@ 466-488 (lines=23) @@ | ||
| 463 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
| 464 | * @return EnumSet |
|
| 465 | */ |
|
| 466 | public function symDiff(...$others) |
|
| 467 | { |
|
| 468 | $clone = clone $this; |
|
| 469 | ||
| 470 | if (isset($others[0])) { |
|
| 471 | $bitset = $others[0]->bitset; |
|
| 472 | foreach ($others as $other) { |
|
| 473 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
| 474 | throw new InvalidArgumentException(sprintf( |
|
| 475 | 'Others should be an instance of %s of the same enumeration as this %s', |
|
| 476 | __CLASS__, |
|
| 477 | $this->enumeration |
|
| 478 | )); |
|
| 479 | } |
|
| 480 | ||
| 481 | $bitset |= $other->bitset; |
|
| 482 | } |
|
| 483 | ||
| 484 | $clone->bitset = $this->bitset ^ $bitset; |
|
| 485 | } |
|
| 486 | ||
| 487 | return $clone; |
|
| 488 | } |
|
| 489 | ||
| 490 | /** |
|
| 491 | * Get ordinal numbers of the defined enumerators as array |
|