Code Monkey home page Code Monkey logo

config-magic's Introduction

Example

Create an interface for your config object:

public interface MyConfig
{
    @Config("foo")
    String getFoo();

    @Config("blah")
    int getBlah();

    @Config("what")
    @Default("none")
    String getWhat();
}

Set the properties that we mapped with @Config above (or simply call System.getProperties()):

Properties props = new Properties();
props.setProperty("foo", "hello");
props.setProperty("blah", "123");

Then create the config object from the properties:

ConfigurationObjectFactory factory = new ConfigurationObjectFactory(props);
MyConfig conf = factory.build(MyConfig.class);

Default values

Using @Default() can set arbitrary default values. To set null as the default value, use the @DefaultNullannotation.

Advanced usage

    @Config({"what1", "what2"})
    @Default("none")
    String getWhat();

will look at what1 first, then at what2 and finally fall back to the default.

Type support

Config-magic supports these types:

  • Primitive types: boolean, byte, short, integer, long, float, double.
  • Enums. Note that config-magic by default ignores the case for enum values.
  • java.lang.String.
  • java.net.URI.
  • java.lang.Class and simple wildcard extensions (java.lang.Class<?>, java.lang.Class<? extends Foo> - config-magic will type check that the type passed as a property conforms to the wildcard type), but not more complex wildcard or parameterized types (e.g. java.lang.Class<? super Bar> or java.lang.Class<? extends List<? super Bar>>).
  • org.skipe.config.TimeSpan: constructed from short textual representation like "5d" (or alias "5 days"); units supported are:
  • ms (alias 'milliseconds')
  • s ('seconds')
  • m ('minutes')
  • h ('hours')
  • d ('days')
  • Any instantiable class that has a public constructor with a single Object parameter. This is useful for instance for joda-time's DateTime objects.
  • Any instantiable class that has a public constructor with a single String parameter. This is useful for instance for java.lang.File.
  • Any class that has a static valueOf method with a single String parameter and the class as its return type.

Maven dependency

To use config-magic in Maven projects:

<dependency>
    <groupId>org.skife.config</groupId>
    <artifactId>config-magic</artifactId>
    <version>0.11</version>
</dependency>

Mailing List

We have a mailing list for development and users.

config-magic's People

Contributors

brianm avatar cowtowncoder avatar divyekapoor avatar electrum avatar hgschmie avatar stevenschlansker avatar tomdz 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.