Coder Social home page Coder Social logo

noonieconfigs's Introduction

NoonieConfigs

NoonieConfigs is a simple library to manage configurations. It does this by using concrete classes to represent configuration files. NoonieConfigs also uses a unique system, which helps the user set and update to valid values.

NoonieConfigs offers:

  1. Automatic updates for configs. (If a configuration class is updated, the configuration saved in the storage will also update.)
  2. Automatic fallback value replacement. (If a configuration was loaded, and the values are illegal, fallback values can replace those illegal values.)

Set Up

To set up a basic configuration environment, a service must be instantiated:

public class MyJavaPlugin {

    public static void main(String[] args) throws Exception {
        Path pathToConfigFolder = Path.of(/*Your path here.*/);
        ConfigService<Object> configService = DefaultConfigServices
                .createJsonConfigService(pathToConfigFolder);
        configService.initialize();
    }

}

To set up a configuration class, make sure the class is annotated with @Config, like so:

@Config(name = "MyConfig")
public class MyConfig {
    
    private final String food = "Pizza";
    private final int favoriteInteger = 100;
    
}

Note: In the configuration class it is recommended to set up default values which can be used as fallback values.

Save a Configuration

To save a configuration, all that needs to be done is:

configService.save(myConfig);

Load a Configuration

To load a configuration from storage, it requires a little few more steps:

Firstly, the configuration must exist already.
Secondly, the configuration must be a valid representation of the class.
Note: To enforce the second step, load the configuration with a fallback object.

MyConfig myConfig;
if (configService.isSaved(MyConfig.class)) {
    myConfig = configService.loadWithFallback(new MyConfig());
} else {
    myConfig = new MyConfig();
}

noonieconfigs's People

Contributors

skinnynoonie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.