PHP Class MabeEnum\EnumSet

Inheritance: implements Iterato\Iterator, implements Countabl\Countable
Show file Open project: marc-mabe/php-enum Class Usage Examples

Public Methods

Method Description
__construct ( string $enumeration ) Constructor
attach ( Enum | null | boolean | integer | float | string $enumerator ) : void Attach a new enumerator or overwrite an existing one
contains ( Enum | null | boolean | integer | float | string $enumerator ) : boolean Test if the given enumerator was attached
count ( ) : integer Count the number of elements
current ( ) : Enum | null Get the current enumerator
detach ( Enum | null | boolean | integer | float | string $enumerator ) : void Detach the given enumerator
diff ( EnumSet $other ) : EnumSet Produce a new set with enumerators in this but not in other (this - other)
getBinaryBitsetBe ( ) : string Get binary bitset in big-endian order
getBinaryBitsetLe ( ) : string Get binary bitset in little-endian order
getBitset ( ) : string Get the binary bitset
getEnumClass ( ) : string Get the classname of enumeration this set is for
getEnumeration ( ) : string Get the classname of the enumeration
getEnumerators ( ) : Enum[] Get the defined enumerators as array
getNames ( ) : string[] Get names of the defined enumerators as array
getOrdinals ( ) : int[] Get ordinal numbers of the defined enumerators as array
getValues ( ) : null[] | bool[] | int[] | float[] | string[] Get values of the defined enumerators as array
intersect ( EnumSet $other ) : EnumSet Produce a new set with enumerators common to both this and other (this & other)
isEqual ( EnumSet $other ) : boolean Check if this EnumSet is the same as other
isSubset ( EnumSet $other ) : boolean Check if this EnumSet is a subset of other
isSuperset ( EnumSet $other ) : boolean Check if this EnumSet is a superset of other
key ( ) : integer Get the ordinal number of the current iterator position
next ( ) : void Go to the next valid iterator position.
rewind ( ) : void Go to the first valid iterator position.
setBinaryBitsetBe ( string $bitset ) : void Set binary bitset in big-endian order
setBinaryBitsetLe ( string $bitset ) : void Set binary bitset in little-endian order
setBitset ( string $bitset ) : void Set the bitset.
symDiff ( EnumSet $other ) : EnumSet Produce a new set with enumerators in either this and other but not in both (this ^ (other | other))
union ( EnumSet $other ) : EnumSet Produce a new set with enumerators from both this and other (this | other)
valid ( ) : boolean Test if the iterator in a valid state

Private Methods

Method Description
getBit ( $ordinal ) : boolean Get a bit at the given ordinal number
setBit ( $ordinal ) : void Set a bit at the given ordinal number
unsetBit ( $ordinal ) : void Unset a bit at the given ordinal number

Method Details

__construct() public method

Constructor
public __construct ( string $enumeration )
$enumeration string The classname of the enumeration

attach() public method

Attach a new enumerator or overwrite an existing one
public attach ( Enum | null | boolean | integer | float | string $enumerator ) : void
$enumerator Enum | null | boolean | integer | float | string
return void

contains() public method

Test if the given enumerator was attached
public contains ( Enum | null | boolean | integer | float | string $enumerator ) : boolean
$enumerator Enum | null | boolean | integer | float | string
return boolean

count() public method

Count the number of elements
public count ( ) : integer
return integer

current() public method

Get the current enumerator
public current ( ) : Enum | null
return Enum | null Returns the current enumerator or NULL on an invalid iterator position

detach() public method

Detach the given enumerator
public detach ( Enum | null | boolean | integer | float | string $enumerator ) : void
$enumerator Enum | null | boolean | integer | float | string
return void

diff() public method

Produce a new set with enumerators in this but not in other (this - other)
public diff ( EnumSet $other ) : EnumSet
$other EnumSet Other EnumSet(s) of the same enumeration to produce the union
return EnumSet

getBinaryBitsetBe() public method

Get binary bitset in big-endian order
public getBinaryBitsetBe ( ) : string
return string

getBinaryBitsetLe() public method

Get binary bitset in little-endian order
public getBinaryBitsetLe ( ) : string
return string

getBitset() public method

Get the binary bitset
Deprecation: Please use getBinaryBitsetBe() instead
public getBitset ( ) : string
return string Returns the binary bitset in big-endian order

getEnumClass() public method

Get the classname of enumeration this set is for
Deprecation: Please use getEnumeration() instead
public getEnumClass ( ) : string
return string

getEnumeration() public method

Get the classname of the enumeration
public getEnumeration ( ) : string
return string

getEnumerators() public method

Get the defined enumerators as array
public getEnumerators ( ) : Enum[]
return Enum[]

getNames() public method

Get names of the defined enumerators as array
public getNames ( ) : string[]
return string[]

getOrdinals() public method

Get ordinal numbers of the defined enumerators as array
public getOrdinals ( ) : int[]
return int[]

getValues() public method

Get values of the defined enumerators as array
public getValues ( ) : null[] | bool[] | int[] | float[] | string[]
return null[] | bool[] | int[] | float[] | string[]

intersect() public method

Produce a new set with enumerators common to both this and other (this & other)
public intersect ( EnumSet $other ) : EnumSet
$other EnumSet Other EnumSet(s) of the same enumeration to produce the union
return EnumSet

isEqual() public method

Check if this EnumSet is the same as other
public isEqual ( EnumSet $other ) : boolean
$other EnumSet
return boolean

isSubset() public method

Check if this EnumSet is a subset of other
public isSubset ( EnumSet $other ) : boolean
$other EnumSet
return boolean

isSuperset() public method

Check if this EnumSet is a superset of other
public isSuperset ( EnumSet $other ) : boolean
$other EnumSet
return boolean

key() public method

Get the ordinal number of the current iterator position
public key ( ) : integer
return integer

next() public method

If no valid iterator position is found the iterator position will be the last possible + 1.
public next ( ) : void
return void

rewind() public method

If no valid iterator position in found the iterator position will be 0.
public rewind ( ) : void
return void

setBinaryBitsetBe() public method

NOTE: It resets the current position of the iterator
public setBinaryBitsetBe ( string $bitset ) : void
$bitset string
return void

setBinaryBitsetLe() public method

NOTE: It resets the current position of the iterator
public setBinaryBitsetLe ( string $bitset ) : void
$bitset string
return void

setBitset() public method

NOTE: It resets the current position of the iterator
Deprecation: Please use setBinaryBitsetBe() instead
public setBitset ( string $bitset ) : void
$bitset string The binary bitset in big-endian order
return void

symDiff() public method

Produce a new set with enumerators in either this and other but not in both (this ^ (other | other))
public symDiff ( EnumSet $other ) : EnumSet
$other EnumSet Other EnumSet(s) of the same enumeration to produce the union
return EnumSet

union() public method

Produce a new set with enumerators from both this and other (this | other)
public union ( EnumSet $other ) : EnumSet
$other EnumSet Other EnumSet(s) of the same enumeration to produce the union
return EnumSet

valid() public method

Test if the iterator in a valid state
public valid ( ) : boolean
return boolean