binding/java: HelloElektra - minor reformatting
import org.libelektra.*;
import org.libelektra.plugin.Echo;
-/** Simple hello world to see how Elektra can be used in Java. */
+/**
+ * Simple hello world to see how Elektra can be used in Java.
+ */
public class HelloElektra {
public static void main(String[] args) {
@@ -96,6 +98,43 @@ public class HelloElektra {
exampleUpdateMetaKey();
}
+ private static void exampleSetMetaKeys() {
+ // Example 9: Set and get meta keys
+ System.out.println("Example 9");
+ Key key = Key.create("user:/key/with/meta");
+ key.setMeta("example", "anExampleValue");
+ var returnedMeta = key.getMeta("example").orElseThrow(AssertionError::new);
+ System.out.println("Value of meta key 'example': " + returnedMeta.getString());
+ System.out.println();
+ }
+
+ private static void exampleSetArrayMetaKey() {
+ // Example 10: Create an array using meta keys
+ System.out.println("Example 10");
+ Key array = Key.create("user:/array");
+ // Create an array with length 2
+ array.setMeta("array", "#1");
+
+ Key firstEntry = Key.create("user:/array/#0/test");
+ firstEntry.setString("first");
+
+ Key secondEntry = Key.create("user:/array/#1/test");
+ secondEntry.setString("second");
+
+ KeySet ks = KeySet.create(array, firstEntry, secondEntry);
+
+ ks.forEach(
+ key -> {
+ System.out.print(key + " = " + key.getString());
+
+ System.out.print(" | Meta: ");
+ for (ReadableKey metaKey : key) {
+ System.out.print(metaKey + " = " + metaKey.getString());
+ }
+ System.out.println();
+ });
+ }
+
private static void exampleCheckKeyAvailableInKDB() {
// Example 11: Check whether the keys are already available in the key database
System.out.println("Example 11");
@@ -146,43 +185,6 @@ public class HelloElektra {
System.out.println();
}
- private static void exampleSetMetaKeys() {
- // Example 9: Set and get meta keys
- System.out.println("Example 9");
- Key key = Key.create("user:/key/with/meta");
- key.setMeta("example", "anExampleValue");
- var returnedMeta = key.getMeta("example").orElseThrow(AssertionError::new);
- System.out.println("Value of meta key 'example': " + returnedMeta.getString());
- System.out.println();
- }
-
- private static void exampleSetArrayMetaKey() {
- // Example 10: Create an array using meta keys
- System.out.println("Example 10");
- Key array = Key.create("user:/array");
- // Create an array with length 2
- array.setMeta("array", "#1");
-
- Key firstEntry = Key.create("user:/array/#0/test");
- firstEntry.setString("first");
-
- Key secondEntry = Key.create("user:/array/#1/test");
- secondEntry.setString("second");
-
- KeySet ks = KeySet.create(array, firstEntry, secondEntry);
-
- ks.forEach(
- key -> {
- System.out.print(key + " = " + key.getString());
-
- System.out.print(" | Meta: ");
- for (ReadableKey metaKey : key) {
- System.out.print(metaKey + " = " + metaKey.getString());
- }
- System.out.println();
- });
- }
-
private static void exampleUpdateMetaKey() {
// Example 12: Update meta data on a key
System.out.println("Example 12");
