Elektra: org.libelektra.Key Class Reference

Elektra 0.8.24

Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
org.libelektra.Key Class Reference

Key is an essential class that encapsulates key name , value and metainfo. More...

Inherits Iterable< String >.

## Public Member Functions
void | release ()
| Clean-up method to release key reference.
boolean | isNull ()
| Helper function that does null comparison. More...
String | toString ()
| Basic java function that represents object as String. More...
java.util.Iterator< String > | iterator ()
| Iterable interface function. More...
boolean | getBoolean ()
| Data type specific accessor function. More...
byte | getByte ()
| Data type specific accessor function. More...
short | getShort ()
| Data type specific accessor function. More...
int | getInteger ()
| Data type specific accessor function. More...
long | getLong ()
| Data type specific accessor function. More...
float | getFloat ()
| Data type specific accessor function. More...
double | getDouble ()
| Data type specific accessor function. More...
void | setBoolean (final boolean v)
| Data type specific setter function. More...
void | setByte (final byte v)
| Data type specific setter function. More...
void | setShort (final short v)
| Data type specific setter function. More...
void | setInteger (final int v)
| Data type specific setter function. More...
void | setLong (final long v)
| Data type specific setter function. More...
void | setFloat (final float v)
| Data type specific setter function. More...
void | setDouble (final double v)
| Data type specific setter function. More...
void | setError (final String text, final Object... args)
| Helper function to set proper error meta for key. More...
void | addWarning (final String text, final Object... args)
| Helper function to add warning meta for key. More...
Key | dup ()
| Duplicates the key. More...
void | copy (final Key source)
| Copies the information from the source key into this key. More...
int | getRef ()
| Gets the reference counter for this key. More...
int | rewindMeta ()
| Tries to rewind the meta information for this key. More...
Key | nextMeta ()
| Gets the next meta information for this key. More...
Key | currentMeta ()
| Gets the current meta information for this key. More...
int | copyMeta (final Key source, final String metaName)
| Helper function to copy some meta information from a source Key to this key. More...
int | copyAllMeta (final Key source)
| Helper function to copy all meta information from a source key to this key. More...
Key | getMeta (final String metaName)
| Getter for meta information. More...
int | setMeta (final String metaName, final String newMetaString)
| Setter for meta information. More...
int | cmp (final Key other)
| Helper function to compare two keys. More...
int | rel (final Key other)
| Helper function to check for relation between keys. More...
int | needsSync ()
| Helper function to check if synchronization is necessary. More...
boolean | isBelow (final Key other)
| Helper function to check if key is sub-key of other key. More...
boolean | isBelowOrSame (final Key other)
| Helper function to check if key is other key or sub-key of other key. More...
boolean | isDirectBelow (final Key other)
| Helper function to check if key is direct sub-key of other key. More...
boolean | isInactive ()
| Helper function to check if key is set to inactive. More...
boolean | isBinary ()
| Helper function to check if key is binary key. More...
boolean | isString ()
| Helper function to check if key is string key. More...
String | getName ()
| Helper function to get key name (key part of "key-value" pair) More...
int | getNameSize ()
| Helper function to get key name size. More...
void | setName (final String name) throws KeyInvalidName
| Helper function to set key name. More...
String | getBaseName ()
| Helper function to get key base name. More...
int | getBaseNameSize ()
| Helper function to get key base name length. More...
void | setBaseName (final String baseName) throws KeyInvalidName
| Helper function to set key base name; will replace current base name with new base name. More...
void | addBaseName (final String baseName) throws KeyInvalidName
| Helper function to add key base name; will add given base name to current key so that new key is sub key of current key. More...
int | getValueSize ()
| Helper function to get key value size/length. More...
String | getString () throws KeyTypeMismatch
| Helper function to get representation of key value. More...
int | setString (final String newString)
| Helper function to set new key value. More...

## Static Public Member Functions
static Key | create (final String name, final Object value, final Key... meta)
| Basic constructor of key class. More...
static Key | create (final String name, final Key... meta)
| Basic constructor of key class. More...

## Protected Member Functions
| Key (final long p)
| Helper constructor for duplication by pointer in long format. More...
| Key (final Pointer p)
| Helper constructor for duplication by pointer. More...
void | finalize () throws Throwable
| Clean-up method to inform underlying c-library about the release of the key reference in jna-binding.
void | incRef ()
| Increments the reference counter for this key.
void | decRef ()
| Decrements the reference counter for this key.
Pointer | get ()
| Native pointer used by JNA. More...

## Static Protected Member Functions
static Key | create (final String name, final Object... args)
| Basic constructor of key class. More...

## Detailed Description

Key is an essential class that encapsulates key name , value and metainfo.

## Constructor & Destructor Documentation

## ◆ Key() [1/2]

org.libelektra.Key.Key | ( | final long | p | ) |
| inlineprotected

Helper constructor for duplication by pointer in long format.

Parameters

  p | Pointer in long format

## ◆ Key() [2/2]

org.libelektra.Key.Key | ( | final Pointer | p | ) |
| inlineprotected

Helper constructor for duplication by pointer.

Parameters

  p | Pointer as Pointer object

## Member Function Documentation

## ◆ addBaseName()

void org.libelektra.Key.addBaseName | ( | final String | baseName | ) | throws KeyInvalidName
| inline

Helper function to add key base name; will add given base name to current key so that new key is sub key of current key.

Parameters

  baseName | New key base name to add

Exceptions

  KeyInvalidName |

## ◆ addWarning()

void org.libelektra.Key.addWarning | ( | final String | text,
|  | final Object... | args
| ) |  |
| inline

Helper function to add warning meta for key.

Parameters

  text | Reason for the warning
  args | Custom arguments

## ◆ cmp()

int org.libelektra.Key.cmp | ( | final Key | other | ) |
| inline

Helper function to compare two keys.

Compares the key name with normal String comparison.

Parameters

  other | Other Key object that is used in comparison

Returns
  0 if key name is equal; -1 if this key name has lower alphabetical order than the other key; 1 if this key has higher alphabetical order

## ◆ copy()

void org.libelektra.Key.copy | ( | final Key | source | ) |
| inline

Copies the information from the source key into this key.

Does nothing if null is provided.

Parameters

  source | Source Key object containing the information to copy

## ◆ copyAllMeta()

int org.libelektra.Key.copyAllMeta | ( | final Key | source | ) |
| inline

Helper function to copy all meta information from a source key to this key.

Parameters

  source | Key object that is used as source

Returns
  1 if meta was successfully copied, 0 if source doesn't contain any meta and nothing had to be done, -1 in case of an error or if the source parameter was null

## ◆ copyMeta()

int org.libelektra.Key.copyMeta | ( | final Key | source,
|  | final String | metaName
| ) |  |
| inline

Helper function to copy some meta information from a source Key to this key.

Parameters

  source | Key object that is used as source
  metaName | Key name of the meta to be copied

Returns
  1 if meta was successfully copied, 0 if source doesn't contain the required meta and nothing had to be done, -1 in case of an error or if the source parameter was null

## ◆ create() [1/3]

static Key org.libelektra.Key.create | ( | final String | name,
|  | final Object... | args
| ) |  |
| inlinestaticprotected

Basic constructor of key class.

Parameters

  name | Key name; first part of key-value pair
  args | Arguments used for key value. Example: Key.KEY_VALUE, "custom key value", Key.KEY_END

Returns
  New key object

## ◆ create() [2/3]

static Key org.libelektra.Key.create | ( | final String | name,
|  | final Object | value,
|  | final Key... | meta
| ) |  |
| inlinestatic

Basic constructor of key class.

Parameters

  name | Key name; first part of key-value pair
  value | Key value; will be determine from the object by calling Object#toString(), null is supported too
  meta | Metadata that should be added to this key, null keys will be filtered away

Returns
  New key object

## ◆ create() [3/3]

static Key org.libelektra.Key.create | ( | final String | name,
|  | final Key... | meta
| ) |  |
| inlinestatic

Basic constructor of key class.

Parameters

  name | Key name; first part of key-value pair
  meta | Metadata that should be added to this key. Will filter null values.

Returns
  New key object

## ◆ currentMeta()

Key org.libelektra.Key.currentMeta | ( |  | ) |
| inline

Gets the current meta information for this key.

Returns
  new Key object containing the current meta information

## ◆ dup()

Key org.libelektra.Key.dup | ( |  | ) |
| inline

Duplicates the key.

Returns
  New Key object containing the same information as this key

## ◆ get()

Pointer org.libelektra.Key.get | ( |  | ) |
| inlineprotected

Native pointer used by JNA.

Returns
  Native pointer object for this key

## ◆ getBaseName()

String org.libelektra.Key.getBaseName | ( |  | ) |
| inline

Helper function to get key base name.

Returns
  Key base name as String

## ◆ getBaseNameSize()

int org.libelektra.Key.getBaseNameSize | ( |  | ) |
| inline

Helper function to get key base name length.

Returns
  Length of key base name

## ◆ getBoolean()

boolean org.libelektra.Key.getBoolean | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in boolean format

## ◆ getByte()

byte org.libelektra.Key.getByte | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in byte format

## ◆ getDouble()

double org.libelektra.Key.getDouble | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in double format

## ◆ getFloat()

float org.libelektra.Key.getFloat | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in float format

## ◆ getInteger()

int org.libelektra.Key.getInteger | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in integer format

## ◆ getLong()

long org.libelektra.Key.getLong | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in long integer format

## ◆ getMeta()

Key org.libelektra.Key.getMeta | ( | final String | metaName | ) |
| inline

Getter for meta information.

Parameters

  metaName | Key name of meta information to be fetched

Returns
  New Key object containing the requested meta information

## ◆ getName()

String org.libelektra.Key.getName | ( |  | ) |
| inline

Helper function to get key name (key part of "key-value" pair)

Returns
  Key name as String

## ◆ getNameSize()

int org.libelektra.Key.getNameSize | ( |  | ) |
| inline

Helper function to get key name size.

Returns
  Length of key name

## ◆ getRef()

int org.libelektra.Key.getRef | ( |  | ) |
| inline

Gets the reference counter for this key.

Returns
  Reference counter as integer

## ◆ getShort()

short org.libelektra.Key.getShort | ( |  | ) |
| inline

Data type specific accessor function.

Returns
  Key value in short integer format

## ◆ getString()

String org.libelektra.Key.getString | ( |  | ) | throws KeyTypeMismatch
| inline

Helper function to get representation of key value.

Returns
  Key value in String format

Exceptions

  KeyTypeMismatch |

## ◆ getValueSize()

int org.libelektra.Key.getValueSize | ( |  | ) |
| inline

Helper function to get key value size/length.

Returns
  Length of key value

## ◆ isBelow()

boolean org.libelektra.Key.isBelow | ( | final Key | other | ) |
| inline

Helper function to check if key is sub-key of other key.

Parameters

  other | Key that is used in check as parent key

Returns
  Boolean if this key is (non-direct) sub-key of other-key

## ◆ isBelowOrSame()

boolean org.libelektra.Key.isBelowOrSame | ( | final Key | other | ) |
| inline

Helper function to check if key is other key or sub-key of other key.

Parameters

  other | Key that is used in check as parent key

Returns
  Boolean if this key is other key or (non-direct) sub-key of other-key

## ◆ isBinary()

boolean org.libelektra.Key.isBinary | ( |  | ) |
| inline

Helper function to check if key is binary key.

Returns
  Boolean if this key is a binary key

## ◆ isDirectBelow()

boolean org.libelektra.Key.isDirectBelow | ( | final Key | other | ) |
| inline

Helper function to check if key is direct sub-key of other key.

Parameters

  other | Key that is used in check as parent key

Returns
  Boolean if this key is direct sub-key of other key ("child")

## ◆ isInactive()

boolean org.libelektra.Key.isInactive | ( |  | ) |
| inline

Helper function to check if key is set to inactive.

Returns
  Boolean if this key is inactive

## ◆ isNull()

boolean org.libelektra.Key.isNull | ( |  | ) |
| inline

Helper function that does null comparison.

Returns
  Boolean if key is null

## ◆ isString()

boolean org.libelektra.Key.isString | ( |  | ) |
| inline

Helper function to check if key is string key.

Returns
  Boolean if this key is a string key

## ◆ iterator()

java.util.Iterator<String> org.libelektra.Key.iterator | ( |  | ) |
| inline

Iterable interface function.

Returns
  Custom KeyNameIterator

## ◆ needsSync()

int org.libelektra.Key.needsSync | ( |  | ) |
| inline

Helper function to check if synchronization is necessary.

Returns
  1 if needs sync, 0 if no change done and -1 in case of a null pointer

## ◆ nextMeta()

Key org.libelektra.Key.nextMeta | ( |  | ) |
| inline

Gets the next meta information for this key.

Returns
  new Key object containing the next meta information

## ◆ rel()

int org.libelektra.Key.rel | ( | final Key | other | ) |
| inline

Helper function to check for relation between keys.

Parameters

  other | Other Key object that is used in relation check

Returns
  0 if other is equal to this; > 0 if other is sub-key of this key; < 0 otherwise or in case of an error

## ◆ rewindMeta()

int org.libelektra.Key.rewindMeta | ( |  | ) |
| inline

Tries to rewind the meta information for this key.

Returns
  0 in case of no errors; 1 if key is not found; 2 if metakey is not found

## ◆ setBaseName()

void org.libelektra.Key.setBaseName | ( | final String | baseName | ) | throws KeyInvalidName
| inline

Helper function to set key base name; will replace current base name with new base name.

Parameters

  baseName | New key base name to use

Exceptions

  KeyInvalidName |

## ◆ setBoolean()

void org.libelektra.Key.setBoolean | ( | final boolean | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Boolean value to set

## ◆ setByte()

void org.libelektra.Key.setByte | ( | final byte | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Byte value to set

## ◆ setDouble()

void org.libelektra.Key.setDouble | ( | final double | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Double value to set

## ◆ setError()

void org.libelektra.Key.setError | ( | final String | text,
|  | final Object... | args
| ) |  |
| inline

Helper function to set proper error meta for key.

Parameters

  text | Reason for the error
  args | Custom arguments

## ◆ setFloat()

void org.libelektra.Key.setFloat | ( | final float | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Float value to set

## ◆ setInteger()

void org.libelektra.Key.setInteger | ( | final int | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Integer value to set

## ◆ setLong()

void org.libelektra.Key.setLong | ( | final long | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Long integer value to set

## ◆ setMeta()

int org.libelektra.Key.setMeta | ( | final String | metaName,
|  | final String | newMetaString
| ) |  |
| inline

Setter for meta information.

Parameters

  metaName | Key name of meta information to be set
  newMetaString | Meta value to be set

Returns
  -1 in case of an error, 0 if no meta with given name is available for the key and value > 0 representing the size of newMetaString if update successful

## ◆ setName()

void org.libelektra.Key.setName | ( | final String | name | ) | throws KeyInvalidName
| inline

Helper function to set key name.

Parameters

  name | New key name to use

Exceptions

  KeyInvalidName |

## ◆ setShort()

void org.libelektra.Key.setShort | ( | final short | v | ) |
| inline

Data type specific setter function.

Parameters

  v | Short integer value to set

## ◆ setString()

int org.libelektra.Key.setString | ( | final String | newString | ) |
| inline

Helper function to set new key value.

Parameters

  newString | New key value to set

Returns
  value > 0 representing saved bytes (+null byte), -1 in case of an error (null key)

## ◆ toString()

String org.libelektra.Key.toString | ( |  | ) |
| inline

Basic java function that represents object as String.

Returns
  Key name in String format

The documentation for this class was generated from the following file:

- Key.java