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