Code Monkey home page Code Monkey logo

jrconfig's Introduction

romangraefs Java Config library.

I intend to mostly use this library for personal projects, so documentation might be lacking in parts. If you have questions, feel free to hit me up on Twitter. That being said:

Usage

Java:

public class ConfigurableClass1 {
    public ConfigVariable<String> someConfigProp = Config.getString("someProp"); // Define a config property
        
    public ConfigurableClass1() {
        Config.use(FilePropertiesProvider.create("config.properties")); // Define a config source.
    }

    public void someMethod() {
        System.out.println(someConfigProp.get()); // Load data from the config.
        someConfigProp.set("New value");
    }
}

Kotlin:

val someConfigProp = Config.get<String>("someProp")
var someOtherOption by Config.get<String>("someOtherOption")


fun main() {
    Config.use(FilePropertiesProvider.create("config.properties"))
    println(someConfigProp.get())
    println(someOtherOption)
    someOtherOption = "lul"
}

Api breakdown

The API is split up into 3 parts:

  • Config variables.

These are what you interact with, for most of your code. You obtain an instance by either calling Config.get(someClazz, "propName") or you can use Config.get<SomeClass>("propName") in Kotlin. Some Common Types like String have shortcut methods like Config.getString("propName").

  • Variable Transformers.

These parse / serialize a string value obtained from a config source. There are some default implementations for some types (String and Integer as of right now), but you can manually create transformers by extending TransformerConfigVariable<T>.

  • Config providers.

You usually install one config provider at the very start of your main using Config.use(provider). Currently there is only one Provider, which is the FilePropertiesProvider which directly utilizes standard java properties. If you want to create your own provider, you can implement ConfigProvider

Installation

Gradle via Jitpack:

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

dependencies {
    implementation("com.github.romangraef", "jrconfig", "v1.2")
}

The version can be either a git shortref, or a tag.

Alternatively, a uberjar/fatjar/ shadow/shadedjar can be obtained from the releases.

jrconfig's People

Contributors

nea89o avatar

Watchers

James Cloos avatar  avatar

jrconfig's Issues

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.