@@ 354-372 (lines=19) @@ | ||
351 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
352 | * @return EnumSet |
|
353 | */ |
|
354 | public function union(...$others) |
|
355 | { |
|
356 | $bitset = $this->bitset; |
|
357 | foreach ($others as $other) { |
|
358 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
359 | throw new InvalidArgumentException(sprintf( |
|
360 | 'Others should be an instance of %s of the same enumeration as this %s', |
|
361 | __CLASS__, |
|
362 | $this->enumeration |
|
363 | )); |
|
364 | } |
|
365 | ||
366 | $bitset |= $other->bitset; |
|
367 | } |
|
368 | ||
369 | $clone = clone $this; |
|
370 | $clone->bitset = $bitset; |
|
371 | return $clone; |
|
372 | } |
|
373 | ||
374 | /** |
|
375 | * Produce a new set with enumerators common to both this and other (this & other) |
|
@@ 382-400 (lines=19) @@ | ||
379 | * @param EnumSet ...$others Other EnumSet(s) of the same enumeration to produce the union |
|
380 | * @return EnumSet |
|
381 | */ |
|
382 | public function intersect(...$others) |
|
383 | { |
|
384 | $bitset = $this->bitset; |
|
385 | foreach ($others as $other) { |
|
386 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
387 | throw new InvalidArgumentException(sprintf( |
|
388 | 'Others should be an instance of %s of the same enumeration as this %s', |
|
389 | __CLASS__, |
|
390 | $this->enumeration |
|
391 | )); |
|
392 | } |
|
393 | ||
394 | $bitset &= $other->bitset; |
|
395 | } |
|
396 | ||
397 | $clone = clone $this; |
|
398 | $clone->bitset = $bitset; |
|
399 | return $clone; |
|
400 | } |
|
401 | ||
402 | /** |
|
403 | * Produce a new set with enumerators in this but not in other (this - other) |