Options
All
  • Public
  • Public/Protected
  • All
Menu

HashMapObject abstraction

Hierarchy

Index

Constructors

constructor

  • An Object that defines a sorted collection of key/value pairs and all their related operations.

    Parameters

    • Default value data: any = null

      A value that will be used to initialize the HashMapObject. It can be an object instance (where each key/value will be directly assigned to the HashMap), or a plain array in which case the keys will be created from each element numeric index

    Returns HashMapObject

Properties

Protected _data

_data: {}

Structure that contains the HashMapObject data Note that javascript objects do not guarantee key order, so we must also keep a sepparate array with the sorted list of keys

Type declaration

  • [key: string]: any

Protected _keys

_keys: string[] = []

Javascript objects specification does not guarantee object keys order. So we must keep a sepparate array with the currently sorted hashmap keys to be sure that sorting is guaranteed

Protected _length

_length: number = 0

Stores the number of elements inside the HashMapObject

Static Readonly SORT_METHOD_NUMERIC

SORT_METHOD_NUMERIC: "SORT_METHOD_NUMERIC" = "SORT_METHOD_NUMERIC"

Sort mode that compares values as numbers (Avoid using it with non numeric values)

Static Readonly SORT_METHOD_STRING

SORT_METHOD_STRING: "SORT_METHOD_STRING" = "SORT_METHOD_STRING"

Sort mode that compares values as strings (alphabetically)

Static Readonly SORT_ORDER_ASCENDING

SORT_ORDER_ASCENDING: "SORT_ORDER_ASCENDING" = "SORT_ORDER_ASCENDING"

Defines that elements will be sorted upward

Static Readonly SORT_ORDER_DESCENDING

SORT_ORDER_DESCENDING: "SORT_ORDER_DESCENDING" = "SORT_ORDER_DESCENDING"

Defines that elements will be sorted downward

Methods

Private _validateKeyFormat

  • _validateKeyFormat(key: any): void
  • Checks that specified key value has a valid format (Non empty string)

    throws

    Error

    Parameters

    • key: any

      The key value to test

    Returns void

    void

get

  • get(key: string): any
  • Get the value that is associated to a key from an existing key/value pair

    throws

    error If key does not exist or is invalid

    Parameters

    • key: string

      The key we are looking for

    Returns any

    The value that is associated to the provided key

getAt

  • getAt(index: number): any
  • Get the value that is located at a certain position at the ordered list of key/pair values

    throws

    Error If index does not exist or is invalid

    Parameters

    • index: number

      The position we are looking for

    Returns any

    The value that is located at the specified position

getKeys

  • getKeys(): string[]
  • Get a list with all the keys from the HashMapObject with the same order as they are stored.

    Returns string[]

    List of strings containing all the HashMapObject sorted keys.

getValues

  • getValues(): any[]
  • Get a list with all the values from the HashMapObject with the same order as they are stored.

    Returns any[]

    List of elements containing all the HashMapObject sorted values

isKey

  • isKey(key: any): boolean
  • Tells if the provided value matches a key that's stored inside the HashMapObject

    Parameters

    • key: any

    Returns boolean

    True if the provided value is a valid HashMap key, false in any other case

length

  • length(): number
  • Get the number of key/value pairs that are currently stored on this HashMapObject instance

    Returns number

    integer The number of items inside the collection

pop

  • pop(): any
  • Remove and get the last element value from the HashMapObject sorted list

    throws

    Error If the HashMapObject is empty

    Returns any

    The value on the last element of the list

remove

  • remove(key: any): any
  • Delete a key/value pair from the HashMapObject, given it's key.

    throws

    Error

    Parameters

    • key: any

      The key for the key/value pair we want to delete

    Returns any

    The value from the key/value pair that's been deleted.

rename

  • rename(key: any, newKey: any): boolean
  • Change the name for an existing key

    throws

    Error

    Parameters

    • key: any

      The name we want to change

    • newKey: any

      The new name that will replace the previous one

    Returns boolean

    True if rename was successful

reverse

  • reverse(): boolean
  • Reverse the order of the HashMapObject elements

    Returns boolean

    void

set

  • set(key: string, value: any): any
  • Define a key / value pair and add it to the collection. If the key already exists, value will be replaced.

    Parameters

    • key: string

      A string that labels the provided value

    • value: any

      A value to be stored with the provided key

    Returns any

    The value after being stored to the collection

shift

  • shift(): any
  • Remove and get the first element value from the HashMapObject sorted list

    throws

    Error If the HashMapObject is empty

    Returns any

    The value on the first element of the list

sortByKey

  • sortByKey(method?: string, order?: string): boolean
  • Sort the key/value pairs inside the HashMapObject by their key values.

    throws

    Error

    Parameters

    • Default value method: string = HashMapObject.SORT_METHOD_STRING

      Defines sort mode: HashMapObject.SORT_STRING or HashMapObject.SORT_NUMERIC

    • Default value order: string = HashMapObject.SORT_ORDER_ASCENDING

      Defines the order for the sorted elements: HashMapObject.SORT_ORDER_ASCENDING (default) or HashMapObject.SORT_ORDER_DESCENDING

    Returns boolean

    True if sort was successful false on failure

swap

  • swap(key1: string, key2: string): boolean
  • Exchange the positions for two key/value pairs on the HashMapObject sorted elements list

    throws

    Error If any of the two provided keys does not exist or is invalid

    Parameters

    • key1: string

      The first key to exchange

    • key2: string

      The second key to exchange

    Returns boolean

    True if the two key/value pairs positions were correctly exchanged

Generated using TypeDoc