| @@ 241-259 (lines=19) @@ | ||
| 238 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
| 239 | * @return EnumSet |
|
| 240 | */ |
|
| 241 | public function union(EnumSet $other) |
|
| 242 | { |
|
| 243 | $bitset = $this->bitset; |
|
| 244 | foreach (func_get_args() as $other) { |
|
| 245 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
| 246 | throw new InvalidArgumentException(sprintf( |
|
| 247 | "Others should be an instance of %s of the same enumeration as this %s", |
|
| 248 | __CLASS__, |
|
| 249 | $this->enumeration |
|
| 250 | )); |
|
| 251 | } |
|
| 252 | ||
| 253 | $bitset |= $other->bitset; |
|
| 254 | } |
|
| 255 | ||
| 256 | $clone = clone $this; |
|
| 257 | $clone->bitset = $bitset; |
|
| 258 | return $clone; |
|
| 259 | } |
|
| 260 | ||
| 261 | /** |
|
| 262 | * Produce a new set with enumerators common to both this and other (this & other) |
|
| @@ 266-284 (lines=19) @@ | ||
| 263 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
| 264 | * @return EnumSet |
|
| 265 | */ |
|
| 266 | public function intersect(EnumSet $other) |
|
| 267 | { |
|
| 268 | $bitset = $this->bitset; |
|
| 269 | foreach (func_get_args() as $other) { |
|
| 270 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
| 271 | throw new InvalidArgumentException(sprintf( |
|
| 272 | "Others should be an instance of %s of the same enumeration as this %s", |
|
| 273 | __CLASS__, |
|
| 274 | $this->enumeration |
|
| 275 | )); |
|
| 276 | } |
|
| 277 | ||
| 278 | $bitset &= $other->bitset; |
|
| 279 | } |
|
| 280 | ||
| 281 | $clone = clone $this; |
|
| 282 | $clone->bitset = $bitset; |
|
| 283 | return $clone; |
|
| 284 | } |
|
| 285 | ||
| 286 | /** |
|
| 287 | * Produce a new set with enumerators in this but not in other (this - other) |
|
| @@ 291-309 (lines=19) @@ | ||
| 288 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
| 289 | * @return EnumSet |
|
| 290 | */ |
|
| 291 | public function diff(EnumSet $other) |
|
| 292 | { |
|
| 293 | $bitset = ''; |
|
| 294 | foreach (func_get_args() as $other) { |
|
| 295 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
| 296 | throw new InvalidArgumentException(sprintf( |
|
| 297 | "Others should be an instance of %s of the same enumeration as this %s", |
|
| 298 | __CLASS__, |
|
| 299 | $this->enumeration |
|
| 300 | )); |
|
| 301 | } |
|
| 302 | ||
| 303 | $bitset |= $other->bitset; |
|
| 304 | } |
|
| 305 | ||
| 306 | $clone = clone $this; |
|
| 307 | $clone->bitset = $this->bitset & ~$bitset; |
|
| 308 | return $clone; |
|
| 309 | } |
|
| 310 | ||
| 311 | /** |
|
| 312 | * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other)) |
|
| @@ 316-334 (lines=19) @@ | ||
| 313 | * @param EnumSet ...$other Other EnumSet(s) of the same enumeration to produce the union |
|
| 314 | * @return EnumSet |
|
| 315 | */ |
|
| 316 | public function symDiff(EnumSet $other) |
|
| 317 | { |
|
| 318 | $bitset = ''; |
|
| 319 | foreach (func_get_args() as $other) { |
|
| 320 | if (!$other instanceof self || $this->enumeration !== $other->enumeration) { |
|
| 321 | throw new InvalidArgumentException(sprintf( |
|
| 322 | "Others should be an instance of %s of the same enumeration as this %s", |
|
| 323 | __CLASS__, |
|
| 324 | $this->enumeration |
|
| 325 | )); |
|
| 326 | } |
|
| 327 | ||
| 328 | $bitset |= $other->bitset; |
|
| 329 | } |
|
| 330 | ||
| 331 | $clone = clone $this; |
|
| 332 | $clone->bitset = $this->bitset ^ $bitset; |
|
| 333 | return $clone; |
|
| 334 | } |
|
| 335 | ||
| 336 | /** |
|
| 337 | * Get ordinal numbers of the defined enumerators as array |
|