konfiger
konfiger

The parent repository for this organisation, Contains list of implementations and functions frame.

This project is the closest thing to Android Shared Preference in other languages and off the Android platform.

The Implementated Languages


Language Links
NodeJS documentation
  npm
  source
JVM languages. Java, Kotlin, Scala e.t.c documentation
  source
C, C++ documentation
  source
Python documentation
  pip
  source
.NET, C#, Visual Basic documentation
  nuget
  source
BEAM languages. Elixir, Erlang, e.t.c documentation
  source
Rust documentation
  source
Dart documentation
  source
Ring documentation
  source
Powershell documentation
  source
Haskell documentation
  source

Contributors

Table of content

Documentation Brief

KonfigerStream

KonfigerStream Constructors

Function Description
fileStream(String, Char, Char, Boolean) Set the KonfigerStream file path, this cannot be changed, the last parameter is boolean if true the stream is error tolerant and does not throw any exception on invalid entry, only the first parameter is cumpulsory
stringStream(String, Char, Char, Boolean) Set the KonfigerStream string value, this cannot be changed, the second param is the delimeter and the third param is the seperator, the last parameter is boolean if true the stream is error tolerant and does not throw any exception on invalid entry, only the first parameter is cumpulsory

Methods

Function Description
hasNext() Check if the KonfigerStream has another KonfigerObject in it before reading
next() The current KonfigerObjeect in the stream
isTrimingKey() Check if the stream is configured to trim key, true by default
setTrimingKey(Boolean) Change the stream to enable/disable key trimming
isTrimingValue() Check if the stream is configured to trim the entry value, true by default
setTrimingValue(Boolean) Change the stream to enable/disable entry value trimming
getCommentPrefix() Get the prefix string that indicate a pair entry if commented
setCommentPrefix(String) Change the stream comment prefix, any entry starting with the comment prefix will be skipped. Comment in KonfigerStream is relative to the key value entry and not relative to a line.
setContinuationChar(Char) Set the character that indicates to the stream to continue reading for the entry value on the next line. The follwoing line leading spaces is trimmed. The default is \
getContinuationChar() Get the continuation character used in the stream.
validateFileExistence(String) Validate the specified parameter (filePath) exists on the FileSystem
errorTolerance(Boolean) Enable or disable the error tolerancy property of the konfiger
isErrorTolerant() Check if the konfiger object errTolerance is set to true

Konfiger

The Key must always be string, the Value can be any type but the String value will be saved and when requested the value returned by default is the String value else requested with a typed get e.g. getBoolean then the value will be converted to a valid boolean in the language. Keys are case sensitive by default such that get("Key") and get("key") will not give same value.

Konfiger Constructors

Function Description
fromFile(String, Boolean) Load the configer datas from a file, the first parameter is the file path, the second boolean parameter indicates whether to read all the entry in the file in the constructor or when needed, the default delimeter(=) and seperator(\n) will be used
fromFile(String, Boolean, Char, Char) Load the configer datas from a file, the first parameter is the file path, the second boolean parameter indicates whether to read all the entry in the file in the constructor or when needed, the third param is the delimeter and the fourth param is the seperator
fromString(String, Boolean) Load the configer datas from a file, the first parameter is the String(can be empty), the second boolean parameter indicates whether to read all the entry in the file in the constructor or when needed, the default delimeter(=) and seperator(\n) will be used
fromString(String, Boolean, Char, Char) Load the configer datas from a file, the first parameter is the String(can be empty), the second boolean parameter indicates whether to read all the entry in the file in the constructor or when needed, the third param is the delimeter and the fourth param is the seperator
fromStream(KonfigerStream, Boolean) Load the configer datas from a KonfigerStream object, the second boolean parameter indicates whether to read all the entry in the file in the constructor or when needed this make data loading progressive as data is only loaded from the file when put or get until the Stream reaches EOF

Public Fields

Function Description
MAX_CAPACITY The number of datas the konfiger can take, 10000000

Putting

The put functions also update the value at the location if it already in the konfiger

Function Description
put(String, Object) Put any object into the konfiger the Object value string value will be saved
putString(String, String) Put a String into the konfiger
putBoolean(String, Boolean) Put a Boolean` into the konfiger
putLong(String, Long) Put a Long into the konfiger
putInt(String, int) Put a Int into the konfiger
putFloat(String, Float) Put a Float into the konfiger
putDouble(String, Double) Put a Double into the konfiger

Getting

Function Description
keys() Get all the keys entries in the konfiger
values() Get all the values entries in the konfiger
entries() Get all the entries in the konfiger in a Map<K, V>
get(String, Any) Get a value as string, if the key does not exist the seconds parameter will be returned
getString(String, String) Get a value as string, if the key does not exist the second parameter is returned
getBoolean(String, Boolean) Get a value as boolean, if the key does not exist the second parameter is returned, if the second parameter is null false if returned.
getLong(String, Long) Get a value as long, if the key does not exist the second parameter is returned
getInt(String, Int) Get a value as int, if the key does not exist the second parameter is returned
getFloat(String, Float) Get a value as float, if the key does not exist the second parameter is returned
getDouble(String, Double) Get a value as double, if the key does not exist the second parameter is returned

Removing

Function Description
remove(int) Remove the entry at a particular index. Returns the value of the entry that was removed.
remove(String) Remove the entry using the data Key. Returns the value of the entry that was removed.

Read and Write

Function Description
appendString(String) Append new data to the konfiger from a string, the new string delimeter and seperator must be the same with the current konfigure delimeter and seperator
appendFile(String) Read new datas from the file path and append, the new file delimeter and seperator must be the same with the current konfigure delimeter and seperator
appendString(String, char, char) Append new data to the konfiger from a string, second parameter is new entry delimeter and separator.
appendFile(String, char, char) Read new datas from the file path and append, second parameter is new entry delimeter and separator.
save(String?) Save the konfiger datas into it IO path if specified, if no IO path specifed in the parameter the file path used in constructor is used, this does not clear the data

Delimeter and Seperator

Function Description
getSeperator() Get seperator char that seperate the datas
getDelimeter() Get delimeter char that seperated the key from object
setSeperator(Char) Change seperator char that seperate the datas, note that the file is not updates, to change the file call the save() function. If the new seperator is different from the old one all the entries values will be re parsed to get the new proper values, this process can take time if the entries is much.
setDelimeter(Char) Change delimeter char that seperated the key from object, note that the file is not updates, to change the file call the save() function

Native Object Attachment

Function Description
resolve(Object) Attach an object to konfiger, on attachment the values of the entries in the object will be set to the coresponding value in konfiger. The object can have the matchGetKey function which is called with a key in konfiger to get the value to map to the entry and the function matchPutKey to check which value to fetch from the object to put into konfiger.
dissolve(Object) Each string fields in the object will be put into konfiger. The object can have the matchGetKey function which is called with a key in konfiger to get the value to map to the entry. This does not attach the object.
attach(Object) Attach an object to konfiger without dissolving it field into konfiger or setting it fields to a matching konfiger entry. Use this if the values in an object is to be left intact but updated if a matching entry in konfiger changes.
detach() Detach the object attached to konfiger when the resolve function is called. The detached object is returned.

Others

Function Description
size() Get the total size of datas in the konfiger
clear() clear all the datas in the konfiger. if the konfiger is attached to a file, the file is updated immediatly
isEmpty() Check if the konfiger does not have an data
updateAt(Int, Object) Update the value at the specified index with the new Object String value, throws an error if OutOfRange sn errTolerance is false
contains(String) Check if the konfiger contains a key
enableCache(Boolean) Enable or disable caching, caching speeds up data search but can take up space in memory (very small though)
toString() All the kofiger datas are parsed into valid string with regards to the delimeter and seprator
setCaseSensitivity(Boolean) change the case sensitivity of the konfiger object, if true get("Key") and get("key") will return different value, if false same value will be returned.
isCaseSensitive() Return true if the konfiger object is case sensitive and false if it not case sensitive

TODOS

How it works

Konfiger stream progressively load the key value entry from a file or string when needed, it uses two method hasNext which check if there is still an entry in the stream and next for the current key value entry in the stream.

In Konfiger the key value pair is stored in a map, all search updating and removal is done on the konfigerObjects in the class. The string sent as first parameter if parsed into valid key value using the separator and delimiter fields and if loaded from file it content is parsed into valid key value pair. The toString method also parse the keyValueObjects content into a valid string with regards to the separator and delimeter. The value is properly escaped and unescaped.

The save function write the current Konfiger to the file, if the file does not exist it is created if it can. Everything is written in memory and is disposed on app exit hence it important to call the save function when nessasary.

Contributing

Before you begin contribution please read the contribution guide at CONTRIBUTING GUIDE

You can open issue or file a request that only address problems in this implementation on this repo, if the issue address the concepts of the package then create an issue or rfc here

Support

You can support some of this community as they make big impact in the training of individual to get started with software engineering and open source contribution.

License

MIT License Copyright (c) 2020 Adewale Azeez - konfiger