@@ 346-364 (lines=19) @@ | ||
343 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
344 | * @return EnumSet |
|
345 | */ |
|
346 | public function union(EnumSet $other) |
|
347 | { |
|
348 | $bitset = $this->bitset; |
|
349 | foreach (func_get_args() as $other) { |
|
350 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
351 | throw new InvalidArgumentException(sprintf( |
|
352 | "Others should be an instance of %s of the same enumeration as this %s", |
|
353 | __CLASS__, |
|
354 | $this->enumeration |
|
355 | )); |
|
356 | } |
|
357 | ||
358 | $bitset |= $other->bitset; |
|
359 | } |
|
360 | ||
361 | $clone = clone $this; |
|
362 | $clone->bitset = $bitset; |
|
363 | return $clone; |
|
364 | } |
|
365 | ||
366 | /** |
|
367 | * Produce a new set with enumerators common to both this and other (this & other) |
|
@@ 371-389 (lines=19) @@ | ||
368 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
369 | * @return EnumSet |
|
370 | */ |
|
371 | public function intersect(EnumSet $other) |
|
372 | { |
|
373 | $bitset = $this->bitset; |
|
374 | foreach (func_get_args() as $other) { |
|
375 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
376 | throw new InvalidArgumentException(sprintf( |
|
377 | "Others should be an instance of %s of the same enumeration as this %s", |
|
378 | __CLASS__, |
|
379 | $this->enumeration |
|
380 | )); |
|
381 | } |
|
382 | ||
383 | $bitset &= $other->bitset; |
|
384 | } |
|
385 | ||
386 | $clone = clone $this; |
|
387 | $clone->bitset = $bitset; |
|
388 | return $clone; |
|
389 | } |
|
390 | ||
391 | /** |
|
392 | * Produce a new set with enumerators in this but not in other (this - other) |
|
@@ 396-414 (lines=19) @@ | ||
393 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
394 | * @return EnumSet |
|
395 | */ |
|
396 | public function diff(EnumSet $other) |
|
397 | { |
|
398 | $bitset = $other->bitset; |
|
399 | foreach (func_get_args() as $other) { |
|
400 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
401 | throw new InvalidArgumentException(sprintf( |
|
402 | "Others should be an instance of %s of the same enumeration as this %s", |
|
403 | __CLASS__, |
|
404 | $this->enumeration |
|
405 | )); |
|
406 | } |
|
407 | ||
408 | $bitset |= $other->bitset; |
|
409 | } |
|
410 | ||
411 | $clone = clone $this; |
|
412 | $clone->bitset = $this->bitset & ~$bitset; |
|
413 | return $clone; |
|
414 | } |
|
415 | ||
416 | /** |
|
417 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
@@ 421-439 (lines=19) @@ | ||
418 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
419 | * @return EnumSet |
|
420 | */ |
|
421 | public function symDiff(EnumSet $other) |
|
422 | { |
|
423 | $bitset = $other->bitset; |
|
424 | foreach (func_get_args() as $other) { |
|
425 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
426 | throw new InvalidArgumentException(sprintf( |
|
427 | "Others should be an instance of %s of the same enumeration as this %s", |
|
428 | __CLASS__, |
|
429 | $this->enumeration |
|
430 | )); |
|
431 | } |
|
432 | ||
433 | $bitset |= $other->bitset; |
|
434 | } |
|
435 | ||
436 | $clone = clone $this; |
|
437 | $clone->bitset = $this->bitset ^ $bitset; |
|
438 | return $clone; |
|
439 | } |
|
440 | ||
441 | /** |
|
442 | * Get ordinal numbers of the defined enumerators as array |