package org.libelektra.app;

import org.libelektra.KDB;
import org.libelektra.KDB.KDBException;
import org.libelektra.Key;
import org.libelektra.KeySet;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

class App{

    private final static String MOUNT_SPACE = "user";
    private final static String KEY_PREFIX = MOUNT_SPACE + "/sw/clock/central/";

    public static void main(String[] args) {
        Map<String, String> stringStringMap = loadConfigurationSettings();
        //do whatever you need with the value starting from here
    }

    private static Map<String, String> loadConfigurationSettings() {
        //all keys we want to retrieve
        String[] keys = new String[]{
            "server/port",
            "spring/profiles/active",
            "spring/datasource/type",
            "spring/datasource/url",
            "spring/datasource/username",
            "spring/datasource/password",
            "spring/jpa/database-platform",
            "spring/jpa/database",
            "spring/mail/host",
            "spring/mail/port",
            "jhipster/mail/from",
            "jhipster/mail/base-url",
        };
        //read the keys
        return readKeys(keys);
    }

    private static Map<String, String> readKeys(String[] keys) {
        //create a key without specifying a name, which is allowed
        Key key = Key.create("");
        //open KDB with autoclose functionality
        //keep in mind this is an expensive operation, avoid calling it too frequently
        try (KDB kdb = KDB.open(key)) {
            //create keyset
            KeySet keySet = KeySet.create();
            //set mount space
            kdb.get(keySet, Key.create(MOUNT_SPACE));
            //fetch values
            return Arrays.stream(keys)
                .map(k -> {
                    Key lookedUpValue = keySet.lookup(KEY_PREFIX + k);
                    //if null (not found), set it to null value
                    //if specification with default value is applied, this actually should never happen
                    return new String[]{k, (lookedUpValue != null) ? lookedUpValue.getString() : null};
                })
                //collect to map
                .collect(Collectors.toMap(keyValue -> keyValue[0], keyValue -> keyValue[1]));
        } catch (KDBException e) {
            //a problem occured with kdb.get(keySet, Key.create(MOUNT_SPACE));
            e.printStackTrace();
        }
        return null;
    }
}

@@ -420,24 +420,71 @@
 g%5B%5D args) %7B%0A
+        System.out.println(%22Example started%22);%0A
         Map%3C
@@ -542,24 +542,158 @@
 Settings();%0A
+        System.out.println(%22Result:%22);%0A        System.out.println(stringStringMap);%0A        System.out.println(%22Example terminated%22);%0A
         //do
@@ -1471,24 +1471,160 @@
 g%5B%5D keys) %7B%0A
+        System.out.println(%22Reading following keys:%22);%0A        for (String key : keys) %7B%0A            System.out.println(key);%0A        %7D%0A
         //cr

Add console printouts