Skip to content
Permalink
Browse files

Style: Reformat Java code with `clang-format`

  • Loading branch information
sanssecours committed Nov 11, 2019
1 parent 5e37ee5 commit 09f2fdc2e33cf0ea0d20251f64c9485ccd7931c3
Showing with 1,747 additions and 1,474 deletions.
  1. +68 −60 examples/external/java/read-keys-example/src/main/java/org/libelektra/app/App.java
  2. +40 −33 src/bindings/jna/HelloElektra.java
  3. +68 −68 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/Elektra.java
  4. +28 −20 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/KDB.java
  5. +261 −184 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/Key.java
  6. +18 −16 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/KeyNameIterator.java
  7. +124 −89 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/KeySet.java
  8. +17 −14 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/KeySetIterator.java
  9. +7 −8 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/Plugin.java
  10. +40 −29 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/PluginLoader.java
  11. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/ConflictingStateException.java
  12. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/InstallationException.java
  13. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/InterfaceException.java
  14. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/InternalException.java
  15. +58 −42 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/KDBException.java
  16. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/LogicalException.java
  17. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/OutOfMemoryException.java
  18. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/PermanentException.java
  19. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/PluginMisbehaviorException.java
  20. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/ResourceException.java
  21. +7 −4 ...bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/SemanticValidationException.java
  22. +7 −4 ...indings/jna/libelektra4j/src/main/java/org/libelektra/exception/SyntacticValidationException.java
  23. +7 −4 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/ValidationException.java
  24. +48 −29 ...ndings/jna/libelektra4j/src/main/java/org/libelektra/exception/mapper/ExceptionMapperService.java
  25. +24 −16 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/exception/model/WarningEntry.java
  26. +41 −39 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/plugin/Echo.java
  27. +64 −53 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/plugin/NativePlugin.java
  28. +48 −39 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/plugin/PropertiesStorage.java
  29. +17 −17 src/bindings/jna/libelektra4j/src/main/java/org/libelektra/plugin/Return.java
  30. +5 −5 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/AllTests.java
  31. +112 −97 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/ExceptionMapperIT.java
  32. +12 −11 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/ExceptionMapperTest.java
  33. +49 −49 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/KDBExceptionTest.java
  34. +36 −31 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/KDBTest.java
  35. +196 −195 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/KeySetTest.java
  36. +200 −200 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/KeyTest.java
  37. +48 −48 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/PluginLoaderIT.java
  38. +34 −34 src/bindings/jna/libelektra4j/src/test/java/org/libelektra/exception/model/WarningEntryTest.java
@@ -9,68 +9,76 @@
import java.util.Map;
import java.util.stream.Collectors;

class App{
class App
{

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

public static void main(String[] args) {
System.out.println("Example started");
Map<String, String> stringStringMap = loadConfigurationSettings();
System.out.println("Result:");
System.out.println(stringStringMap);
System.out.println("Example terminated");
//do whatever you need with the value starting from here
}
public static void main (String[] args)
{
System.out.println ("Example started");
Map<String, String> stringStringMap = loadConfigurationSettings ();
System.out.println ("Result:");
System.out.println (stringStringMap);
System.out.println ("Example terminated");
// 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> 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) {
System.out.println("Reading following keys:");
for (String key : keys) {
System.out.println(key);
}
//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;
}
private static Map<String, String> readKeys (String[] keys)
{
System.out.println ("Reading following keys:");
for (String key : keys)
{
System.out.println (key);
}
// 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;
}
}
@@ -2,47 +2,54 @@
import org.libelektra.plugin.Echo;

/** Simple hello world example how Elektra could be wrapped to java. */
public class HelloElektra {
public class HelloElektra
{

public static void main(String[] args) {
final Key key = Key.create("user/hello_world", "Hello World");
System.out.println(key); // to get name
System.out.println(key.getString());
public static void main (String[] args)
{
final Key key = Key.create ("user/hello_world", "Hello World");
System.out.println (key); // to get name
System.out.println (key.getString ());

final KeySet ks = KeySet.create(10, Key.create("user/hello_world2", "Hello World2"), key, KeySet.KS_END);
final KeySet ks = KeySet.create (10, Key.create ("user/hello_world2", "Hello World2"), key, KeySet.KS_END);

for (Key k : ks) {
System.out.println("iter: " + k.getName() + " " + k.getString());
for (Key k : ks)
{
System.out.println ("iter: " + k.getName () + " " + k.getString ());
}
System.out.println(ks);

final KeySet ks2 = ks.dup();
ks2.copy(ks);
System.out.println(ks2.length());
ks2.append(ks);
ks2.append(key);

try (final KDB kdb = KDB.open(key)) {
kdb.get(ks, key);
final Key k = ks.lookup(key);
System.out.println(k.getString());
} catch (KDB.KDBException e) {
System.out.println(e);
System.out.println (ks);

final KeySet ks2 = ks.dup ();
ks2.copy (ks);
System.out.println (ks2.length ());
ks2.append (ks);
ks2.append (key);

try (final KDB kdb = KDB.open (key))
{
kdb.get (ks, key);
final Key k = ks.lookup (key);
System.out.println (k.getString ());
}
catch (KDB.KDBException e)
{
System.out.println (e);
}

final Echo dp = new Echo();
dp.open(ks, key);
dp.get(ks, key);
dp.close(key);
final Echo dp = new Echo ();
dp.open (ks, key);
dp.get (ks, key);
dp.close (key);

final Key b = Key.create("user/boolean", "true");
System.out.println(b.getBoolean());
b.setBoolean(false);
System.out.println(b.getBoolean());
final Key b = Key.create ("user/boolean", "true");
System.out.println (b.getBoolean ());
b.setBoolean (false);
System.out.println (b.getBoolean ());

final Key n = Key.create("user/weird\\/name///\\\\/is/\\no/_\\\\problem", Key.KEY_END);
for (String s : n) {
System.out.println("itername: " + s);
final Key n = Key.create ("user/weird\\/name///\\\\/is/\\no/_\\\\problem", Key.KEY_END);
for (String s : n)
{
System.out.println ("itername: " + s);
}
}
}

0 comments on commit 09f2fdc

Please sign in to comment.
You can’t perform that action at this time.