public class PropertiesBuilder extends Object implements FactoryBean<Properties>
Properties
.Properties
,
FactoryBean
OBJECT_TYPE_ATTRIBUTE
Constructor and Description |
---|
PropertiesBuilder()
Constructs an instance of the
PropertiesBuilder class. |
PropertiesBuilder(Properties defaults)
Constructs an instance of the
PropertiesBuilder class initialized with the default Properties . |
PropertiesBuilder(PropertiesBuilder builder)
Constructs an instance of the
PropertiesBuilder class initialized with the given
PropertiesBuilder providing the default Properties for this builder. |
Modifier and Type | Method and Description |
---|---|
PropertiesBuilder |
add(Properties properties)
Null-safe method to add all the
Properties to this builder. |
PropertiesBuilder |
add(PropertiesBuilder builder)
Null-safe method to add all the
Properties from the provided PropertiesBuilder to this builder. |
Properties |
build()
Builds the
Properties object from this builder. |
static PropertiesBuilder |
create()
Factory method to create a default
PropertiesBuilder instance. |
static PropertiesBuilder |
from(InputStream in)
Constructs and initializes a
PropertiesBuilder containing all properties
from the given InputStream . |
static PropertiesBuilder |
from(Properties properties)
Factory method to create an instance of
PropertiesBuilder initialized with the given Properties . |
static PropertiesBuilder |
from(Reader reader)
Constructs and initializes a
PropertiesBuilder containing all properties
from the given Reader . |
static PropertiesBuilder |
fromXml(InputStream xml)
Constructs and initializes a
PropertiesBuilder containing all properties
from the given InputStream in XML format. |
Properties |
getObject() |
Class<?> |
getObjectType() |
boolean |
isSingleton() |
protected boolean |
isValuable(String value)
Determine whether the given
String value is a valid Properties value. |
PropertiesBuilder |
setProperty(String name,
Object value)
Sets a property with given name to the specified value.
|
PropertiesBuilder |
setProperty(String name,
Object[] values)
Sets the named property to the given array of object values.
|
PropertiesBuilder |
setProperty(String name,
String value)
Sets a property with the given name to the specified
String value. |
<T> PropertiesBuilder |
setPropertyIfNotDefault(String name,
Object value,
T defaultValue)
Sets the named property to the given value if the defaultValue is not null
and value is not equal to defaultValue.
|
PropertiesBuilder |
unsetProperty(String name)
Un-sets the named property.
|
public PropertiesBuilder()
PropertiesBuilder
class.public PropertiesBuilder(Properties defaults)
PropertiesBuilder
class initialized with the default Properties
.defaults
- Properties
used as the defaults.NullPointerException
- if the Properties
reference is null.Properties
public PropertiesBuilder(PropertiesBuilder builder)
PropertiesBuilder
class initialized with the given
PropertiesBuilder
providing the default Properties
for this builder.builder
- PropertiesBuilder
providing the default Properties
for this builder.NullPointerException
- if the PropertiesBuilder
reference is null.PropertiesBuilder(Properties)
public static PropertiesBuilder create()
PropertiesBuilder
instance.PropertiesBuilder
class with not Properties
.PropertiesBuilder()
public static PropertiesBuilder from(Properties properties)
PropertiesBuilder
initialized with the given Properties
.properties
- Properties
used as the default properties of the constructed PropertiesBuilder
.PropertiesBuilder
initialized with the given Properties
.Properties
,
PropertiesBuilder(Properties)
public static PropertiesBuilder from(InputStream in)
PropertiesBuilder
containing all properties
from the given InputStream
.in
- InputStream
source containing properties to use as the defaults for the constructed builder.PropertiesBuilder
initialized with properties from the given InputStream
.IllegalArgumentException
- if the InputStream
cannot be read.InputStream
,
Properties.load(InputStream)
public static PropertiesBuilder from(Reader reader)
PropertiesBuilder
containing all properties
from the given Reader
.reader
- Reader
source containing properties to use as the defaults for the constructed builder.PropertiesBuilder
initialized with properties from the given Reader
.IllegalArgumentException
- if the Reader
cannot be read.Reader
,
Properties.load(Reader)
public static PropertiesBuilder fromXml(InputStream xml)
PropertiesBuilder
containing all properties
from the given InputStream
in XML format.xml
- InputStream
source containing properties in XML format to use as defaults
for the constructed builder.PropertiesBuilder
initialized with properties from the given XML InputStream
.IllegalArgumentException
- if the XML InputStream
cannot be read.InputStream
,
Properties.loadFromXML(InputStream)
public Properties getObject() throws Exception
getObject
in interface FactoryBean<Properties>
Exception
public Class<?> getObjectType()
getObjectType
in interface FactoryBean<Properties>
public boolean isSingleton()
isSingleton
in interface FactoryBean<Properties>
public PropertiesBuilder add(Properties properties)
Properties
to this builder. This operation effectively overwrites
any properties already set with the same name from the source.properties
- Properties
to add to this builder.PropertiesBuilder
.Properties
public PropertiesBuilder add(PropertiesBuilder builder)
Properties
from the provided PropertiesBuilder
to this builder.
This operation effectively overwrites any properties already set with the same name from the source.builder
- source of the Properties
to add to this builder.PropertiesBuilder
.PropertiesBuilder
public PropertiesBuilder setProperty(String name, Object value)
name
- the name of the property to set.value
- the value to set the property to.PropertiesBuilder
.setProperty(String, String)
public PropertiesBuilder setProperty(String name, Object[] values)
name
- name of the property to set.values
- array of object values used as the property's value.PropertiesBuilder
StringUtils.arrayToCommaDelimitedString(Object[])
,
setProperty(String, String)
public PropertiesBuilder setProperty(String name, String value)
String
value. The property is only set
if the value is not null, an empty String
or not equal to the String
literal
null, ignoring case.name
- the name of the property to set.value
- the value to set the property to.PropertiesBuilder
.IllegalArgumentException
- if the property name is not specified.Properties.setProperty(String, String)
public <T> PropertiesBuilder setPropertyIfNotDefault(String name, Object value, T defaultValue)
T
- Class type of the property value.name
- name of the property to set.value
- value to set for the property.defaultValue
- default value of the property to compare with the given value
when determining whether to set the property.PropertiesBuilder
.setProperty(String, Object)
public PropertiesBuilder unsetProperty(String name)
String
.name
- name of the property to unset.PropertiesBuilder
.IllegalArgumentException
- if the property name is not specified.protected boolean isValuable(String value)
String
value is a valid Properties
value. A property value is
considered valid if it is not null, not empty and not equal to (case-insensitive) String
literal
null.value
- String
value for the property being set.String
value is a valid Properties
value.public Properties build()
Properties
object from this builder.Properties
object built by this builder.Properties
Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.