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