Skip to content

Latest commit

 

History

History
584 lines (228 loc) · 6.88 KB

EnumMap.md

File metadata and controls

584 lines (228 loc) · 6.88 KB

EnumMap

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

Properties

keyType

The class name of the key.

private string $keyType

valueType

The type of the value.

private string $valueType

allowNullValues

private bool $allowNullValues

keyUniverse

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

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

values

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

size

private int $size

Methods

__construct

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

expect

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

size

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

public size(): int

containsValue

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

containsKey

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

get

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

put

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.)


remove

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.)


clear

Removes all mappings from this map.

public clear(): void

equals

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

values

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).


serialize

public serialize(): string

unserialize

public unserialize(mixed $serialized): void

Parameters:

Parameter Type Description
$serialized mixed

getIterator

public getIterator(): \Traversable

maskNull

private maskNull(mixed $value): mixed

Parameters:

Parameter Type Description
$value mixed

unmaskNull

private unmaskNull(mixed $value): mixed

Parameters:

Parameter Type Description
$value mixed

checkKeyType

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

Parameters:

Parameter Type Description
$key \DASPRiD\Enum\AbstractEnum

isValidValue

private isValidValue(mixed $value): bool

Parameters:

Parameter Type Description
$value mixed