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} and {@see}.
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.
- Full name:
\DASPRiD\Enum\EnumMap
- This class is marked as final and can't be subclassed
- This class implements:
\Serializable
,\IteratorAggregate
- This class is a Final class
The class name of the key.
private string $keyType
The type of the value.
private string $valueType
private bool $allowNullValues
All of the constants comprising the enum, cached for performance.
private array<int,\DASPRiD\Enum\AbstractEnum> $keyUniverse
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.
private array<int,mixed> $values
private int $size
Creates a new enum map.
public __construct(string $keyType, string $valueType, bool $allowNullValues): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$keyType |
string | the type of the keys, must extend AbstractEnum |
$valueType |
string | the type of the values |
$allowNullValues |
bool | whether to allow null values |
Checks whether the map types match the supplied ones.
public expect(string $keyType, string $valueType, bool $allowNullValues): void
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:
Parameter | Type | Description |
---|---|---|
$keyType |
string | |
$valueType |
string | |
$allowNullValues |
bool |
Returns the number of key-value mappings in this map.
public size(): int
Returns true if this map maps one or more keys to the specified value.
public containsValue(mixed $value): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
mixed |
Returns true if this map contains a mapping for the specified key.
public containsKey(\DASPRiD\Enum\AbstractEnum $key): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
\DASPRiD\Enum\AbstractEnum |
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
public get(\DASPRiD\Enum\AbstractEnum $key): mixed
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} operation may be used to distinguish these two cases.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
\DASPRiD\Enum\AbstractEnum |
Associates the specified value with the specified key in this map.
public put(\DASPRiD\Enum\AbstractEnum $key, mixed $value): mixed
If the map previously contained a mapping for this key, the old value is replaced.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
\DASPRiD\Enum\AbstractEnum | |
$value |
mixed |
Return Value:
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.)
Removes the mapping for this key frm this map if present.
public remove(\DASPRiD\Enum\AbstractEnum $key): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
\DASPRiD\Enum\AbstractEnum |
Return Value:
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.)
Removes all mappings from this map.
public clear(): void
Compares the specified map with this map for quality.
public equals(self $other): bool
Returns true if the two maps represent the same mappings.
Parameters:
Parameter | Type | Description |
---|---|---|
$other |
self |
Returns the values contained in this map.
public values(): array
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).
public serialize(): string
public unserialize(mixed $serialized): void
Parameters:
Parameter | Type | Description |
---|---|---|
$serialized |
mixed |
public getIterator(): \Traversable
private maskNull(mixed $value): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
mixed |
private unmaskNull(mixed $value): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
mixed |
private checkKeyType(\DASPRiD\Enum\AbstractEnum $key): void
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
\DASPRiD\Enum\AbstractEnum |
private isValidValue(mixed $value): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
mixed |