@@ 377-395 (lines=19) @@ | ||
374 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
375 | * @return EnumSet |
|
376 | */ |
|
377 | public function union(...$others) |
|
378 | { |
|
379 | $bitset = $this->bitset; |
|
380 | foreach ($others as $other) { |
|
381 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
382 | throw new InvalidArgumentException(sprintf( |
|
383 | 'Others should be an instance of %s of the same enumeration as this %s', |
|
384 | __CLASS__, |
|
385 | $this->enumeration |
|
386 | )); |
|
387 | } |
|
388 | ||
389 | $bitset |= $other->bitset; |
|
390 | } |
|
391 | ||
392 | $clone = clone $this; |
|
393 | $clone->bitset = $bitset; |
|
394 | return $clone; |
|
395 | } |
|
396 | ||
397 | /** |
|
398 | * Produce a new set with enumerators common to both this and other (this & other) |
|
@@ 405-423 (lines=19) @@ | ||
402 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
403 | * @return EnumSet |
|
404 | */ |
|
405 | public function intersect(...$others) |
|
406 | { |
|
407 | $bitset = $this->bitset; |
|
408 | foreach ($others as $other) { |
|
409 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
410 | throw new InvalidArgumentException(sprintf( |
|
411 | 'Others should be an instance of %s of the same enumeration as this %s', |
|
412 | __CLASS__, |
|
413 | $this->enumeration |
|
414 | )); |
|
415 | } |
|
416 | ||
417 | $bitset &= $other->bitset; |
|
418 | } |
|
419 | ||
420 | $clone = clone $this; |
|
421 | $clone->bitset = $bitset; |
|
422 | return $clone; |
|
423 | } |
|
424 | ||
425 | /** |
|
426 | * Produce a new set with enumerators in this but not in other (this - other) |