public class Configuration
extends java.lang.Object
implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
Configurations are specified by resources. A resource contains a set of
name/value pairs as key-value data. Each resource is named by either a
String
or by a Path
. If named by a String
,
then the classpath is examined for a file with that name. If named by a
Path
, then the local filesystem is examined directly, without
referring to the classpath.
Unless explicitly turned off, Librec by default specifies two resources, loaded in-order from the classpath:
Modifier and Type | Class and Description |
---|---|
static class |
Configuration.Resource |
Constructor and Description |
---|
Configuration() |
Modifier and Type | Method and Description |
---|---|
static void |
addDefaultResource(java.lang.String name)
Add a default resource.
|
void |
addResource(Configuration.Resource resource) |
java.lang.String |
get(java.lang.String name) |
java.lang.String |
get(java.lang.String name,
java.lang.String defaultValue) |
boolean |
getBoolean(java.lang.String name) |
boolean |
getBoolean(java.lang.String name,
boolean defaultValue) |
java.lang.Class<?> |
getClassByName(java.lang.String name)
Load a class by name.
|
java.lang.Class<?> |
getClassByName(java.lang.String name,
java.lang.String defaultName)
Load a class by name.
|
java.lang.Double |
getDouble(java.lang.String name) |
java.lang.Double |
getDouble(java.lang.String name,
java.lang.Double defaultValue) |
java.lang.Float |
getFloat(java.lang.String name) |
java.lang.Float |
getFloat(java.lang.String name,
java.lang.Float defaultValue) |
java.lang.Integer |
getInt(java.lang.String name) |
java.lang.Integer |
getInt(java.lang.String name,
java.lang.Integer defaultValue) |
int[] |
getInts(java.lang.String name)
Get the value of the
name property as a set of
comma-delimited int values. |
java.lang.Long |
getLong(java.lang.String name) |
java.lang.Long |
getLong(java.lang.String name,
java.lang.Long defaultValue) |
java.net.URL |
getResource(java.lang.String name) |
java.lang.String[] |
getStrings(java.lang.String name)
Get the comma delimited values of the
name property as an
array of String s. |
java.lang.String[] |
getTrimmedStrings(java.lang.String name)
Get the comma delimited values of the
name property as an
array of String s, trimmed of the leading and trailing
whitespace. |
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
iterator()
Get an
Iterator to go through the list of String
key-value pairs in the configuration. |
void |
set(java.lang.String name,
java.lang.String value)
Set the
value of the name property. |
void |
setBoolean(java.lang.String name,
boolean value)
Set the value of the
name property to a boolean . |
void |
setDouble(java.lang.String name,
double value)
Set the value of the
name property to a double . |
void |
setFloat(java.lang.String name,
float value)
Set the value of the
name property to a float . |
void |
setInt(java.lang.String name,
int value)
Set the value of the
name property to an int . |
void |
setInts(java.lang.String name,
int[] values)
Set the array of int values for the
name property as as
comma delimited values. |
void |
setLong(java.lang.String name,
long value)
Set the value of the
name property to an long . |
void |
setStrings(java.lang.String name,
java.lang.String... values)
Set the array of string values for the
name property as as
comma delimited values. |
public static void addDefaultResource(java.lang.String name)
name
- file name. File should be present in the classpath.public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> iterator()
Iterator
to go through the list of String
key-value pairs in the configuration.iterator
in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
public void addResource(Configuration.Resource resource)
public void set(java.lang.String name, java.lang.String value)
value
of the name
property.name
- property name.value
- property value.public java.lang.String get(java.lang.String name)
public void setStrings(java.lang.String name, java.lang.String... values)
name
property as as
comma delimited values.name
- property name.values
- The valuespublic java.lang.String[] getStrings(java.lang.String name)
name
property as an
array of String
s. If no such property is specified then
null
is returned.name
- property name.String
s, or
null
.public java.lang.Float getFloat(java.lang.String name, java.lang.Float defaultValue)
public void setFloat(java.lang.String name, float value)
name
property to a float
.name
- property name.value
- property value.public java.lang.Float getFloat(java.lang.String name)
public void setDouble(java.lang.String name, double value)
name
property to a double
.name
- property name.value
- property value.public java.lang.Double getDouble(java.lang.String name, java.lang.Double defaultValue)
public java.lang.Double getDouble(java.lang.String name)
public java.lang.String get(java.lang.String name, java.lang.String defaultValue)
public void setLong(java.lang.String name, long value)
name
property to an long
.name
- property name.value
- int
value of the property.public java.lang.Long getLong(java.lang.String name, java.lang.Long defaultValue)
public java.lang.Long getLong(java.lang.String name)
public void setInt(java.lang.String name, int value)
name
property to an int
.name
- property name.value
- int
value of the property.public java.lang.Integer getInt(java.lang.String name, java.lang.Integer defaultValue)
public java.lang.Integer getInt(java.lang.String name)
public void setInts(java.lang.String name, int[] values)
name
property as as
comma delimited values.name
- property name.values
- The valuespublic int[] getInts(java.lang.String name)
name
property as a set of
comma-delimited int
values.
If no such property exists, an empty array is returned.
name
- property nameint
valuespublic java.lang.String[] getTrimmedStrings(java.lang.String name)
name
property as an
array of String
s, trimmed of the leading and trailing
whitespace. If no such property is specified then an empty array is
returned.name
- property name.String
s, or
empty array.public void setBoolean(java.lang.String name, boolean value)
name
property to a boolean
.name
- property name.value
- boolean
value of the property.public boolean getBoolean(java.lang.String name)
public boolean getBoolean(java.lang.String name, boolean defaultValue)
public java.net.URL getResource(java.lang.String name)
public java.lang.Class<?> getClassByName(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the class name.java.lang.ClassNotFoundException
- if the class is not found.public java.lang.Class<?> getClassByName(java.lang.String name, java.lang.String defaultName) throws java.lang.ClassNotFoundException
name
- the class name.defaultName
- the default class.java.lang.ClassNotFoundException
- if the class is not found.Copyright © 2017. All Rights Reserved.