\DASPRiD\EnumEnumMap

A specialized map implementation for use with enum type keys.

All of the keys in an enum map must come from a single enum type that is specified, when the map is created. Enum maps are represented internally as arrays. This representation is extremely compact and efficient.

Enum maps are maintained in the natural order of their keys (the order in which the enum constants are declared). This is reflected in the iterators returned by the collection views {@see \DASPRiD\Enum\self::getIterator()} and {@see \DASPRiD\Enum\self::values()}.

Iterators returned by the collection views are not consistent: They may or may not show the effects of modifications to the map that occur while the iteration is in progress.

Summary

Methods
Properties
Constants
__construct()
expect()
size()
containsValue()
containsKey()
get()
put()
remove()
clear()
equals()
values()
serialize()
unserialize()
getIterator()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
maskNull()
unmaskNull()
checkKeyType()
isValidValue()
$keyType
$valueType
$allowNullValues
$keyUniverse
$values
$size
N/A

Properties

$keyType

$keyType : string

The class name of the key.

Type

string

$valueType

$valueType : string

The type of the value.

Type

string

$allowNullValues

$allowNullValues : bool

Type

bool

$keyUniverse

$keyUniverse : array<int,\DASPRiD\Enum\AbstractEnum>

All of the constants comprising the enum, cached for performance.

Type

AbstractEnum>

$values

$values : array<int,mixed>

Array representation of this map. The ith element is the value to which universe[i] is currently mapped, or null if it isn't mapped to anything, or NullValue if it's mapped to null.

Type

array

$size

$size : int

Type

int

Methods

__construct()

__construct(string  $keyType, string  $valueType, bool  $allowNullValues) : mixed

Creates a new enum map.

Parameters

string $keyType

the type of the keys, must extend AbstractEnum

string $valueType

the type of the values

bool $allowNullValues

whether to allow null values

Throws

\DASPRiD\Enum\Exception\IllegalArgumentException

when key type does not extend AbstractEnum

Returns

mixed —

expect()

expect(string  $keyType, string  $valueType, bool  $allowNullValues) : void

Checks whether the map types match the supplied ones.

You should call this method when an EnumMap is passed to you and you want to ensure that it's made up of the correct types.

Parameters

string $keyType
string $valueType
bool $allowNullValues

Throws

\DASPRiD\Enum\Exception\ExpectationException

when supplied key type mismatches local key type

\DASPRiD\Enum\Exception\ExpectationException

when supplied value type mismatches local value type

\DASPRiD\Enum\Exception\ExpectationException

when the supplied map allows null values, abut should not

size()

size() : int

Returns the number of key-value mappings in this map.

Returns

int —

containsValue()

containsValue(mixed  $value) : bool

Returns true if this map maps one or more keys to the specified value.

Parameters

mixed $value

Returns

bool —

containsKey()

containsKey(\DASPRiD\Enum\AbstractEnum  $key) : bool

Returns true if this map contains a mapping for the specified key.

Parameters

\DASPRiD\Enum\AbstractEnum $key

Returns

bool —

get()

get(\DASPRiD\Enum\AbstractEnum  $key) : mixed

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key to a value, then this method returns the value; otherwise it returns null (there can be at most one such mapping).

A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that hte map explicitly maps the key to null. The {@see \DASPRiD\Enum\self::containsKey()} operation may be used to distinguish these two cases.

Parameters

\DASPRiD\Enum\AbstractEnum $key

Returns

mixed —

put()

put(\DASPRiD\Enum\AbstractEnum  $key, mixed  $value) : mixed

Associates the specified value with the specified key in this map.

If the map previously contained a mapping for this key, the old value is replaced.

Parameters

\DASPRiD\Enum\AbstractEnum $key
mixed $value

Throws

\DASPRiD\Enum\Exception\IllegalArgumentException

when the passed values does not match the internal value type

Returns

mixed —

the previous value associated with the specified key, or null if there was no mapping for the key. (a null return can also indicate that the map previously associated null with the specified key.)

remove()

remove(\DASPRiD\Enum\AbstractEnum  $key) : mixed

Removes the mapping for this key frm this map if present.

Parameters

\DASPRiD\Enum\AbstractEnum $key

Returns

mixed —

the previous value associated with the specified key, or null if there was no mapping for the key. (a null return can also indicate that the map previously associated null with the specified key.)

clear()

clear() : void

Removes all mappings from this map.

equals()

equals(self  $other) : bool

Compares the specified map with this map for quality.

Returns true if the two maps represent the same mappings.

Parameters

self $other

Returns

bool —

values()

values() : array

Returns the values contained in this map.

The array will contain the values in the order their corresponding keys appear in the map, which is their natural order (the order in which the num constants are declared).

Returns

array —

serialize()

serialize() : string

Returns

string —

unserialize()

unserialize(mixed  $serialized) : void

Parameters

mixed $serialized

getIterator()

getIterator() : \Traversable

Returns

\Traversable —

maskNull()

maskNull(mixed  $value) : mixed

Parameters

mixed $value

Returns

mixed —

unmaskNull()

unmaskNull(mixed  $value) : mixed

Parameters

mixed $value

Returns

mixed —

checkKeyType()

checkKeyType(\DASPRiD\Enum\AbstractEnum  $key) : void

Parameters

\DASPRiD\Enum\AbstractEnum $key

Throws

\DASPRiD\Enum\Exception\IllegalArgumentException

when the passed key does not match the internal key type

isValidValue()

isValidValue(mixed  $value) : bool

Parameters

mixed $value

Returns

bool —