Git Product home page Git Product logo

night-config's Introduction

Night Config

Maven Central Javadocs Build Status

Introduction

NightConfig is a powerful yet easy-to-use java configuration library, written in Java 8.

It supports the following formats:

How to use

  • Please read the extensive wiki.
  • You can also try the runnable examples (see below).

Glimpse

// Simple builder:
FileConfig conf = FileConfig.of("the/file/config.toml");

// Advanced builder, default resource, autosave and much more (-> cf the wiki)
CommentedFileConfig config = CommentedFileConfig.builder("myConfig.toml").defaultResource("defaultConfig.toml").autosave().build();
config.load(); // This actually reads the config

String name = config.get("username"); // Generic return type!
List<String> names = config.get("users_list"); // Generic return type!
long id = config.getLong("account.id"); // Compound path: key "id" in subconfig "account"
int points = config.getIntOrElse("account.score", defaultScore); // Default value

config.set("account.score", points*2);

String comment = config.getComment("user");
// NightConfig saves the config's comments (for TOML and HOCON)

// config.save(); not needed here thanks to autosave()
config.close(); // Close the FileConfig once you're done with it :)

Running the examples

Each file in examples/src/main/java has a main function and shows how to use NightConfig for many different use cases.

To run an example:

  1. Clone this repository.
  2. cd to it
  3. Run ./gradlew examples:run -PmainClass=${CLASS} by replacing ${CLASS} with the example of your choice.

For example, to run FileConfigExample.java:

./gradlew examples:run -PmainClass=FileConfigExample

The file be compiled automatically, and the given main class will be executed.

Project building

NightConfig is built with Gradle. The project is divided in several modules, the "core" module plus one module per supported configuration format. Please read the wiki for more information.

The releases are available on Maven Central and JitPack.

Android

⚠️ The _android modules are deprecated and will be removed in a future version. ⚠️

Why? Because the maintainance burden of these modules is not worth it, given that almost no smartphone uses these very old versions of Android.

Older versions of Android don't provide the packages java.util.function and java.nio.file, which NightConfig heavily uses. If you encounter issues on android you can use the special version that I've made for you by adding _android to the modules' names.

night-config's People

Contributors

theelectronwill avatar tterrag1098 avatar technicianlp avatar mani1232 avatar cadiboo avatar mnlipp avatar vectrixdevelops 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.