Options
All
  • Public
  • Public/Protected
  • All
Menu

Object that stores java properties file format data

Hierarchy

Index

Constructors

constructor

  • Create a JavaPropertiesObject instance. Java properties is a text file format that stores data into text files with information that is arranged as key/value pairs. For example: tag1=value1

    see

    HashMapObject

    Parameters

    • Default value string: string = ""

      String containing the contents of a .properties Java file. Note that string must be encoded with ISO-8859-1 and strictly follow the Java properties file format (Otherwise results won't be correct).

    Returns JavaPropertiesObject

    The java properties object with data accessible as key/value pairs.

Properties

Protected _data

_data: object

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 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 SORT_METHOD_STRING

SORT_METHOD_STRING: "SORT_METHOD_STRING" = "SORT_METHOD_STRING"

Sort mode that compares values as strings (alphabetically)

Static SORT_ORDER_ASCENDING

SORT_ORDER_ASCENDING: "SORT_ORDER_ASCENDING" = "SORT_ORDER_ASCENDING"

Defines that elements will be sorted upward

Static SORT_ORDER_DESCENDING

SORT_ORDER_DESCENDING: "SORT_ORDER_DESCENDING" = "SORT_ORDER_DESCENDING"

Defines that elements will be sorted downward

Methods

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

isEqualTo

  • isEqualTo(properties: any, strictOrder?: boolean): boolean
  • Check if the provided java properties is identical to this instance Only data is compared: Any comment that is found on both provided properties will be ignored.

    Parameters

    • properties: any

      java properties value to compare (a string or a JavaPropertiesObject instance)

    • Default value strictOrder: boolean = false

      If set to true, both properties elements must have the same keys with the same order. Otherwise differences in key sorting will be accepted

    Returns boolean

    true if both java properties data is exactly the same, false if not

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

toString

  • toString(): string
  • Generate the textual representation for the java properties data stored on this object. The output of this method is ready to be stored on a physical .properties file.

    Returns string

    A valid Java .properties string ready to be stored on a .properties file

Static isJavaProperties

  • isJavaProperties(value: any): boolean
  • Tells if the given value contains valid Java Properties data information or not

    Parameters

    • value: any

      A value to check (a string or a JavaPropertiesObject instance)

    Returns boolean

    true if the given value contains valid Java Properties data, false otherwise

Generated using TypeDoc