public class Props
extends java.lang.Object
implements java.lang.Cloneable
Basic parsing rules:
Sections rules:
Profiles rules:
Macro rules:
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
activeProfiles |
protected java.lang.String |
activeProfilesProp |
protected PropsData |
data |
protected boolean |
initialized |
protected PropsParser |
parser |
Modifier | Constructor and Description |
---|---|
|
Props()
Creates new props.
|
protected |
Props(PropsParser parser) |
Modifier and Type | Method and Description |
---|---|
void |
addInnerMap(java.lang.String prefix,
java.util.Map<?,?> map)
Adds child map to the props on given prefix.
|
void |
addInnerMap(java.lang.String prefix,
java.util.Map<?,?> map,
java.lang.String profile)
Adds child map to the props on given prefix.
|
protected Props |
clone()
Clones props by creating new instance and copying current configuration.
|
int |
countTotalProperties()
Counts the total number of properties, including all profiles.
|
static Props |
create()
Statis ctor.
|
PropsEntries |
entries()
|
void |
extractProps(java.util.Map target)
Extracts props belonging to active profiles.
|
void |
extractProps(java.util.Map target,
java.lang.String... profiles)
Extract props of given profiles.
|
void |
extractSubProps(java.util.Map target,
java.lang.String... wildcardPatterns)
Extracts subset of properties that matches given wildcards.
|
void |
extractSubProps(java.util.Map target,
java.lang.String[] profiles,
java.lang.String[] wildcardPatterns)
Extracts subset of properties that matches given wildcards.
|
java.lang.String[] |
getActiveProfiles()
Returns active profiles or
null if none defined. |
java.lang.String[] |
getAllProfiles()
Returns all profiles names.
|
java.lang.String |
getBaseValue(java.lang.String key)
Returns
string value of base property. |
java.lang.Boolean |
getBooleanValue(java.lang.String key)
Returns boolean value of given property or
null if property not found. |
java.lang.Boolean |
getBooleanValue(java.lang.String key,
java.lang.Boolean defaultValue)
Returns boolean value or default one if property not defined.
|
java.lang.Boolean |
getBooleanValue(java.lang.String key,
java.lang.Boolean defaultValue,
java.lang.String... profiles) |
java.lang.Boolean |
getBooleanValue(java.lang.String key,
java.lang.String... profiles) |
java.lang.Double |
getDoubleValue(java.lang.String key)
Returns double value of given property or
null if property not found. |
java.lang.Double |
getDoubleValue(java.lang.String key,
java.lang.Double defaultValue)
Returns double value or default one if property not defined.
|
java.lang.Double |
getDoubleValue(java.lang.String key,
java.lang.Double defaultValue,
java.lang.String... profiles) |
java.lang.Double |
getDoubleValue(java.lang.String key,
java.lang.String... profiles) |
java.lang.Integer |
getIntegerValue(java.lang.String key)
Returns integer value of given property or
null if property not found. |
java.lang.Integer |
getIntegerValue(java.lang.String key,
java.lang.Integer defaultValue)
Returns integer value or default one if property not defined.
|
java.lang.Integer |
getIntegerValue(java.lang.String key,
java.lang.Integer defaultValue,
java.lang.String... profiles) |
java.lang.Integer |
getIntegerValue(java.lang.String key,
java.lang.String... profiles) |
java.lang.Long |
getLongValue(java.lang.String key)
Returns long value of given property or
null if property not found. |
java.lang.Long |
getLongValue(java.lang.String key,
java.lang.Long defaultValue)
Returns long value or default one if property not defined.
|
java.lang.Long |
getLongValue(java.lang.String key,
java.lang.Long defaultValue,
java.lang.String... profiles) |
java.lang.Long |
getLongValue(java.lang.String key,
java.lang.String... profiles) |
java.lang.String[] |
getProfilesFor(java.lang.String propKeyNameWildcard)
Returns all the profiles that define certain prop's key name.
|
java.lang.String |
getValue(java.lang.String key)
Returns value of property, using active profiles, or
null if property not found. |
java.lang.String |
getValue(java.lang.String key,
java.lang.String... profiles)
Returns
string value of given profiles. |
java.lang.String |
getValueOrDefault(java.lang.String key,
java.lang.String defaultValue)
Returns value of property, using active profiles or default value if not found.
|
protected void |
initialize()
Initializes props.
|
java.util.Map<java.lang.String,java.lang.Object> |
innerMap(java.lang.String prefix)
Returns inner map from the props with given prefix.
|
java.util.Iterator<PropsEntry> |
iterator()
Returns iterator for active profiles.
|
Props |
load(java.io.File file)
Loads props from the file.
|
Props |
load(java.io.File file,
java.lang.String encoding)
Loads properties from the file in provided encoding.
|
Props |
load(java.io.InputStream in)
Loads properties from input stream.
|
Props |
load(java.io.InputStream in,
java.lang.String encoding)
Loads properties from input stream and provided encoding.
|
Props |
load(java.util.Map<?,?> p)
Loads base properties from the provided java properties.
|
Props |
load(java.util.Map<?,?> map,
java.lang.String prefix)
Loads base properties from java Map using provided prefix.
|
Props |
load(java.lang.String data)
Loads props from the string.
|
Props |
loadEnvironment(java.lang.String prefix)
Loads environment properties with given prefix.
|
Props |
loadFromClasspath(java.lang.String... patterns)
Loads props and properties from the classpath.
|
Props |
loadSystemProperties(java.lang.String prefix)
Loads system properties with given prefix.
|
protected void |
parse(java.lang.String data)
Parses input string and loads provided properties map.
|
protected void |
resolveActiveProfiles()
Resolves active profiles from special property.
|
Props |
setActiveProfiles(java.lang.String... activeProfiles)
Sets new active profiles and overrides existing ones.
|
Props |
setAppendDuplicateProps(boolean appendDuplicateProps)
Appends duplicate props.
|
Props |
setEscapeNewLineValue(java.lang.String escapeNewLineValue)
Specifies the new line string when EOL is escaped.
|
Props |
setIgnoreMissingMacros(boolean ignoreMissingMacros)
Ignore missing macros by replacing them with an empty string.
|
Props |
setIgnorePrefixWhitespacesOnNewLine(boolean ignorePrefixWhitespacesOnNewLine)
Defines if the prefix whitespaces should be ignored when value is split into the lines.
|
Props |
setMultilineValues(boolean multilineValues)
Enables multiline values.
|
Props |
setSkipEmptyProps(boolean skipEmptyProps)
Skips empty properties as they don't exist.
|
void |
setValue(java.lang.String key,
java.lang.String value)
Sets default value.
|
void |
setValue(java.lang.String key,
java.lang.String value,
java.lang.String profile)
Sets value on some profile.
|
Props |
setValueTrimLeft(boolean valueTrimLeft)
Specifies should the values be trimmed from the left.
|
Props |
setValueTrimRight(boolean valueTrimRight)
Specifies should the values be trimmed from the right.
|
protected final PropsParser parser
protected final PropsData data
protected java.lang.String activeProfilesProp
protected java.lang.String[] activeProfiles
protected volatile boolean initialized
public Props()
protected Props(PropsParser parser)
public static Props create()
protected Props clone()
clone
in class java.lang.Object
public java.lang.String[] getActiveProfiles()
null
if none defined.public Props setActiveProfiles(java.lang.String... activeProfiles)
null
, no active profile will be set.
Note that if some props are loaded after
this method call, they might override active profiles
by using special property for active profiles (@profiles
).
public Props setEscapeNewLineValue(java.lang.String escapeNewLineValue)
public Props setValueTrimLeft(boolean valueTrimLeft)
true
.public Props setValueTrimRight(boolean valueTrimRight)
true
.public Props setIgnorePrefixWhitespacesOnNewLine(boolean ignorePrefixWhitespacesOnNewLine)
public Props setSkipEmptyProps(boolean skipEmptyProps)
public Props setAppendDuplicateProps(boolean appendDuplicateProps)
public Props setIgnoreMissingMacros(boolean ignoreMissingMacros)
public Props setMultilineValues(boolean multilineValues)
protected void parse(java.lang.String data)
public Props load(java.lang.String data)
public Props load(java.io.File file) throws java.io.IOException
java.io.IOException
public Props load(java.io.File file, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public Props load(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public Props load(java.io.InputStream in, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public Props load(java.util.Map<?,?> p)
public Props load(java.util.Map<?,?> map, java.lang.String prefix)
public Props loadSystemProperties(java.lang.String prefix)
null
it will not be ignored.public Props loadEnvironment(java.lang.String prefix)
null
it will not be used.public Props loadFromClasspath(java.lang.String... patterns)
public int countTotalProperties()
public java.lang.String getBaseValue(java.lang.String key)
string
value of base property.
Returns null
if property doesn't exist.public java.lang.String getValue(java.lang.String key)
null
if property not found.public java.lang.String getValueOrDefault(java.lang.String key, java.lang.String defaultValue)
public java.lang.Integer getIntegerValue(java.lang.String key)
null
if property not found.public java.lang.Integer getIntegerValue(java.lang.String key, java.lang.Integer defaultValue)
public java.lang.Long getLongValue(java.lang.String key)
null
if property not found.public java.lang.Long getLongValue(java.lang.String key, java.lang.Long defaultValue)
public java.lang.Double getDoubleValue(java.lang.String key)
null
if property not found.public java.lang.Double getDoubleValue(java.lang.String key, java.lang.Double defaultValue)
public java.lang.Boolean getBooleanValue(java.lang.String key)
null
if property not found.public java.lang.Boolean getBooleanValue(java.lang.String key, java.lang.Boolean defaultValue)
public java.lang.String getValue(java.lang.String key, java.lang.String... profiles)
string
value of given profiles. If key is not
found under listed profiles, base properties will be searched.
Returns null
if property doesn't exist.public java.lang.Integer getIntegerValue(java.lang.String key, java.lang.String... profiles)
public java.lang.Integer getIntegerValue(java.lang.String key, java.lang.Integer defaultValue, java.lang.String... profiles)
public java.lang.Long getLongValue(java.lang.String key, java.lang.String... profiles)
public java.lang.Long getLongValue(java.lang.String key, java.lang.Long defaultValue, java.lang.String... profiles)
public java.lang.Double getDoubleValue(java.lang.String key, java.lang.String... profiles)
public java.lang.Double getDoubleValue(java.lang.String key, java.lang.Double defaultValue, java.lang.String... profiles)
public java.lang.Boolean getBooleanValue(java.lang.String key, java.lang.String... profiles)
public java.lang.Boolean getBooleanValue(java.lang.String key, java.lang.Boolean defaultValue, java.lang.String... profiles)
public void setValue(java.lang.String key, java.lang.String value)
public void setValue(java.lang.String key, java.lang.String value, java.lang.String profile)
public void extractProps(java.util.Map target)
public void extractProps(java.util.Map target, java.lang.String... profiles)
public void extractSubProps(java.util.Map target, java.lang.String... wildcardPatterns)
public void extractSubProps(java.util.Map target, java.lang.String[] profiles, java.lang.String[] wildcardPatterns)
public java.util.Map<java.lang.String,java.lang.Object> innerMap(java.lang.String prefix)
public void addInnerMap(java.lang.String prefix, java.util.Map<?,?> map)
public void addInnerMap(java.lang.String prefix, java.util.Map<?,?> map, java.lang.String profile)
protected void initialize()
protected void resolveActiveProfiles()
public java.lang.String[] getAllProfiles()
public java.lang.String[] getProfilesFor(java.lang.String propKeyNameWildcard)
public PropsEntries entries()
public java.util.Iterator<PropsEntry> iterator()
Copyright © 2003-present Jodd Team