@@ 399-420 (lines=22) @@ | ||
396 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
397 | * @return EnumSet |
|
398 | */ |
|
399 | public function diff(EnumSet ...$others) |
|
400 | { |
|
401 | $clone = clone $this; |
|
402 | ||
403 | if (isset($others[0])) { |
|
404 | $bitset = $others[0]->bitset; |
|
405 | foreach ($others as $other) { |
|
406 | if ($this->enumeration !== $other->enumeration) { |
|
407 | throw new InvalidArgumentException(sprintf( |
|
408 | 'Others should of the same enumeration as this %s', |
|
409 | $this->enumeration |
|
410 | )); |
|
411 | } |
|
412 | ||
413 | $bitset |= $other->bitset; |
|
414 | } |
|
415 | ||
416 | $clone->bitset = $this->bitset & ~$bitset; |
|
417 | } |
|
418 | ||
419 | return $clone; |
|
420 | } |
|
421 | ||
422 | /** |
|
423 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
@@ 427-448 (lines=22) @@ | ||
424 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
425 | * @return EnumSet |
|
426 | */ |
|
427 | public function symDiff(EnumSet ...$others) |
|
428 | { |
|
429 | $clone = clone $this; |
|
430 | ||
431 | if (isset($others[0])) { |
|
432 | $bitset = $others[0]->bitset; |
|
433 | foreach ($others as $other) { |
|
434 | if ($this->enumeration !== $other->enumeration) { |
|
435 | throw new InvalidArgumentException(sprintf( |
|
436 | 'Others should be of the same enumeration as this %s', |
|
437 | $this->enumeration |
|
438 | )); |
|
439 | } |
|
440 | ||
441 | $bitset |= $other->bitset; |
|
442 | } |
|
443 | ||
444 | $clone->bitset = $this->bitset ^ $bitset; |
|
445 | } |
|
446 | ||
447 | return $clone; |
|
448 | } |
|
449 | ||
450 | /** |
|
451 | * Get ordinal numbers of the defined enumerators as array |