Skip to content
WillBAnders edited this page Sep 13, 2020 · 1 revision

Storm

Storm is a library for user-oriented configuration. Using Storm, developers can easily create type-safe systems for working with text-based configurations, especially for non-technical users.

  • Discord: Development discussion & support

For more introductory information, see the project README.

Getting Started

Installation

The current recommended way to depend on Storm is using JitPack, which can be done with Gradle as follows:

repositories {
    maven {
        url "https://jitpack.io"
    }
}

dependencies {
    implementation "com.github.flash-labs:FlashLibs:v0.1.0"
}

-SNAPSHOT can be instead instead of a version for the latest changes.

Loading Configs

As of v0.1.0, Storm does not do any work with files. Instead, you will have to read the contents of the file into a String first.

String input = new String(Files.readAllBytes(path));
try {
    Node node = Storm.deserialize(input);
} catch (ParseException e) {
    System.out.println(e.getDiagnostic());
}

Likewise, when reserializing the returned value is a String which can then be used as needed.

String output = Storm.reserialize(node);
Files.write(path, output.getBytes());

Using Nodes

The Node class is a navigable node hierarchy. The class is fully documented, so for brevity we're going to focus on two key points until a full wiki can be created.

  • Many methods are state dependent, so pay attention to the preconditions enforced when using a method.
  • Nodes are either defined with a value or undefined. It is possible to navigate to an undefined node, but it is not allowed to set a value to one - instead the attach() method must be used (likewise, detach() for converting a node to undefined).

Using Serializers

Storm provides a variety of serializers for getting data from a node. As above, there are a few key points to mention with serializers.

  • Serializers are strict and will not perform any type of conversion, even ones like integers to decimals (for that, use a UNION).
  • Deserialization is, in general, a lossy conversion - information about the representation of values can be lost, and therefore reserialization may not produce an identical value (though it will naturally be equivalent). Some serializers, like UNION, do not currently support reserialization as consequence.
  • NULLABLE and OPTIONAL are both tricky, since they cannot be used at the same time as an Optional of null is not allowed (Optional.ofNullable(null) produces Optional.empty(), which is also used for undefined values). As such, it is recommend to avoid designing configuration where a value can be both (in general, optional should be preferred over nullable).
Clone this wiki locally