public class SettingsMapBuilder extends Object
// Get a new empty settings map
SettingsMap map = new SettingsMapImpl().build();
// Get a new filled SettingsMap
SettingsMap map = new SettingsMapBuilder().add("port", 80).add("host", "localhost").build()
// Get a SettingsMap from the content of a whole file directory
SettingsMap map = new SettingsMapBuilder().fromDirectory("/tmp/conf").build()
Constructor and Description |
---|
SettingsMapBuilder()
get a new
SettingsMapBuilder , ths is the only official way to
create from scratch a settings map. |
Modifier and Type | Method and Description |
---|---|
SettingsMapBuilder |
addNestedProperty(Object value,
String... keys)
Add an initial nested property.
|
SettingsMapBuilder |
addProperty(String key,
Object value)
Before getting your map, fill in some values.
|
ISettingsMap |
build()
Build and get your
ISettingsMap . |
protected static String |
convertYamlToJson(String yaml) |
static ISettingsMap |
from(byte[] content)
Simplify from()
|
SettingsMapBuilder |
fromBytes(byte[] content)
build your settings map from bytes
|
SettingsMapBuilder |
fromDirectory(String pathDir)
build your settings map from the content of a directory.
|
SettingsMapBuilder |
fromFile(File file) |
SettingsMapBuilder |
fromFile(Path path)
Return a builder for a yml, yaml json or hjson file.
|
SettingsMapBuilder |
fromFile(String path)
Return a builder for a simple json or hjson file.
|
SettingsMapBuilder |
fromString(String str)
build your settings map from a String
|
SettingsMapBuilder |
fromYaml(String str)
build your settings map from YAML as String
|
SettingsMapBuilder |
putAll(Map<? extends String,? extends Object> m)
Add an initial collection to the content of your list
|
SettingsMapBuilder |
setJsonDecoding(boolean b)
By default files read from zookeeper of from the local file system are automatically
decoded as json (if, of course, thier content is json compatible).
|
SettingsMapBuilder |
setName(String name)
Associate a name to you setting map.
|
public SettingsMapBuilder()
SettingsMapBuilder
, ths is the only official way to
create from scratch a settings map.public SettingsMapBuilder setName(String name)
name
- an arbitrary namepublic SettingsMapBuilder addProperty(String key, Object value)
key
- the property keyvalue
- the property valuepublic SettingsMapBuilder addNestedProperty(Object value, String... keys)
For example :
ISettingsMap map = new SettingsMapBuilder()
.addNestedProperty("kafka", "metricset", "type")
.addNestedProperty("broker", "metricset", "name")
.build();
value
- the value. Calling this with a null value has no effect; null is considered not compatible.keys
- the list of keyspublic ISettingsMap build()
ISettingsMap
.public SettingsMapBuilder fromString(String str)
str
- your json stringpublic SettingsMapBuilder fromBytes(byte[] content)
content
- your byte arraypublic SettingsMapBuilder fromFile(String path) throws IOException, ConfigurationException
path
- the absolute file pathIOException
- in case of problemConfigurationException
public SettingsMapBuilder fromFile(File file) throws IOException, ConfigurationException
IOException
ConfigurationException
protected static String convertYamlToJson(String yaml) throws com.fasterxml.jackson.databind.JsonMappingException, com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.databind.JsonMappingException
com.fasterxml.jackson.core.JsonProcessingException
public SettingsMapBuilder fromFile(Path path) throws ConfigurationException
path
- the map pathIllegalArgumentException
- if you provide a null pathIOException
- if the file cannot be openConfigurationException
- if the input file is not a correct yaml json or hjson filepublic SettingsMapBuilder fromDirectory(String pathDir) throws IOException
pathDir
- your directoryIOException
- if a problem reading the directory occuredpublic SettingsMapBuilder fromYaml(String str)
str
- your yaml stringpublic SettingsMapBuilder setJsonDecoding(boolean b)
Use this to request no decoding. You will then get FileHandle instead.
b
- true or false.public SettingsMapBuilder putAll(Map<? extends String,? extends Object> m)
m
- the initial map to addpublic static ISettingsMap from(byte[] content)
content
- to parseCopyright © 2014–2022. All rights reserved.