Class StringDictionary<T>
Type Parameters
- T
Constructors
constructor
-
Type Parameters
- T
Returns StringDictionary<T>
Methods
add
-
Add a new key and its corresponding value
Parameters
- key: string
the key to add
- value: T
the value corresponding to the key
Returns boolean
true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary
- key: string
clear
-
Clear the whole content of the dictionary
Returns void
contains
-
Check if there's a given key in the dictionary
Parameters
- key: string
the key to check for
Returns boolean
true if the key is present, false otherwise
- key: string
copy From
-
This will clear this dictionary and copy the content from the 'source' one. If the T value is a custom object, it won't be copied/cloned, the same object will be used
Parameters
- source: StringDictionary<T>
the dictionary to take the content from and copy to this dictionary
Returns void
- source: StringDictionary<T>
first
-
Execute a callback on every occurrence of the dictionary until it returns a valid TRes object. If the callback returns null or undefined the method will iterate to the next key/value pair Note that you can remove any element in this dictionary in the callback implementation
Type Parameters
- TRes
Parameters
Returns NonNullable<TRes> | null
the first item
for Each
-
Execute a callback on each key/val of the dictionary. Note that you can remove any element in this dictionary in the callback implementation
Parameters
- callback: (key: string, val: T) => void
the callback to execute on a given key/value pair
Returns void
- callback: (key: string, val: T) => void
get
-
Get a value based from its key
Parameters
- key: string
the given key to get the matching value from
Returns T | undefined
the value if found, otherwise undefined is returned
- key: string
get And Remove
get Or Add
get Or Add With Factory
-
Get a value from its key or add it if it doesn't exist. This method will ensure you that a given key/data will be present in the dictionary.
Parameters
- key: string
the given key to get the matching value from
- factory: (key: string) => T
the factory that will create the value if the key is not present in the dictionary. The factory will only be invoked if there's no data for the given key.
Returns T
the value corresponding to the key.
- key: string
remove
-
Remove a key/value from the dictionary.
Parameters
- key: string
the key to remove
Returns boolean
true if the item was successfully deleted, false if no item with such key exist in the dictionary
- key: string
set
-
Update a specific value associated to a key
Parameters
- key: string
defines the key to use
- value: T
defines the value to store
Returns boolean
true if the value was updated (or false if the key was not found)
- key: string
This class implement a typical dictionary using a string as key and the generic type T as value. The underlying implementation relies on an associative array to ensure the best performances. The value can be anything including 'null' but except 'undefined'