Class PropertiesBuilder
java.lang.Object
org.springframework.data.gemfire.util.PropertiesBuilder
- All Implemented Interfaces:
org.springframework.beans.factory.FactoryBean<Properties>
public class PropertiesBuilder
extends Object
implements org.springframework.beans.factory.FactoryBean<Properties>
Builder for
Properties
.- Since:
- 1.9.0
- See Also:
-
Properties
FactoryBean
-
Field Summary
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
ConstructorDescriptionConstructs a new instance ofPropertiesBuilder
.PropertiesBuilder
(Properties defaults) Constructs a new instance ofPropertiesBuilder
initialized with the defaultProperties
.PropertiesBuilder
(PropertiesBuilder builder) Constructs a new instance ofPropertiesBuilder
initialized with the givenPropertiesBuilder
providing the defaultProperties
for this builder. -
Method Summary
Modifier and TypeMethodDescriptionadd
(Properties properties) Null-safe method to add all theProperties
to this builder.add
(PropertiesBuilder builder) Null-safe method to add all theProperties
from the providedPropertiesBuilder
to this builder.build()
Builds theProperties
object from this builder.static PropertiesBuilder
create()
Factory method used to create a defaultPropertiesBuilder
instance.static PropertiesBuilder
from
(InputStream in) Constructs a new instance ofPropertiesBuilder
initialized with all properties from the givenInputStream
.static PropertiesBuilder
Constructs a new isntance ofPropertiesBuilder
initialized with all properties from the givenReader
.static PropertiesBuilder
from
(Properties properties) Factory method used to create an instance ofPropertiesBuilder
initialized with the givenProperties
.static PropertiesBuilder
fromXml
(InputStream xml) Constructs a new instance ofPropertiesBuilder
initialized with all properties from the givenInputStream
in XML format.Class<?>
boolean
protected boolean
isValuable
(String value) Determine whether the givenString
value is a validProperties
value.setProperty
(String name, Object value) Sets a property with given name to the specified value.setProperty
(String name, Object[] values) Sets the named property to the given array of object values.setProperty
(String name, String value) Sets a property with the given name to the specifiedString
value.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.unsetProperty
(String name) Un-sets the named property.
-
Constructor Details
-
PropertiesBuilder
public PropertiesBuilder()Constructs a new instance ofPropertiesBuilder
. -
PropertiesBuilder
Constructs a new instance ofPropertiesBuilder
initialized with the defaultProperties
.- Parameters:
defaults
-Properties
used as the defaults.- Throws:
NullPointerException
- if theProperties
reference is null.- See Also:
-
PropertiesBuilder
Constructs a new instance ofPropertiesBuilder
initialized with the givenPropertiesBuilder
providing the defaultProperties
for this builder.- Parameters:
builder
-PropertiesBuilder
providing the defaultProperties
for this builder.- Throws:
NullPointerException
- if thePropertiesBuilder
reference is null.- See Also:
-
-
Method Details
-
create
Factory method used to create a defaultPropertiesBuilder
instance.- Returns:
- an instance of the
PropertiesBuilder
class with notProperties
. - See Also:
-
from
Factory method used to create an instance ofPropertiesBuilder
initialized with the givenProperties
.- Parameters:
properties
-Properties
used as the default properties of the constructedPropertiesBuilder
.- Returns:
- an instance of
PropertiesBuilder
initialized with the givenProperties
. - See Also:
-
from
Constructs a new instance ofPropertiesBuilder
initialized with all properties from the givenInputStream
.- Parameters:
in
-InputStream
source containing properties to use as the defaults for the constructed builder.- Returns:
- a
PropertiesBuilder
initialized with properties from the givenInputStream
. - Throws:
IllegalArgumentException
- if theInputStream
cannot be read.- See Also:
-
from
Constructs a new isntance ofPropertiesBuilder
initialized with all properties from the givenReader
.- Parameters:
reader
-Reader
source containing properties to use as the defaults for the constructed builder.- Returns:
- a
PropertiesBuilder
initialized with properties from the givenReader
. - Throws:
IllegalArgumentException
- if theReader
cannot be read.- See Also:
-
fromXml
Constructs a new instance ofPropertiesBuilder
initialized with all properties from the givenInputStream
in XML format.- Parameters:
xml
-InputStream
source containing properties in XML format to use as defaults for the constructed builder.- Returns:
- a
PropertiesBuilder
initialized with properties from the given XMLInputStream
. - Throws:
IllegalArgumentException
- if the XMLInputStream
cannot be read.- See Also:
-
getObject
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<Properties>
- Throws:
Exception
-
getObjectType
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<Properties>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<Properties>
-
add
Null-safe method to add all theProperties
to this builder. This operation effectively overwrites any properties already set with the same name from the source.- Parameters:
properties
-Properties
to add to this builder.- Returns:
- a reference to this
PropertiesBuilder
. - See Also:
-
add
Null-safe method to add all theProperties
from the providedPropertiesBuilder
to this builder. This operation effectively overwrites any properties already set with the same name from the source.- Parameters:
builder
- source of theProperties
to add to this builder.- Returns:
- a reference to this
PropertiesBuilder
. - See Also:
-
setProperty
Sets a property with given name to the specified value. The property is only set if the value is not null.- Parameters:
name
- the name of the property to set.value
- the value to set the property to.- Returns:
- a reference to this
PropertiesBuilder
. - See Also:
-
setProperty
Sets the named property to the given array of object values. The property is only set if the array of object value is not null or empty.- Parameters:
name
- name of the property to set.values
- array of object values used as the property's value.- Returns:
- a reference to this
PropertiesBuilder
- See Also:
-
StringUtils.arrayToCommaDelimitedString(Object[])
setProperty(String, String)
-
setProperty
Sets a property with the given name to the specifiedString
value. The property is only set if the value is not null, an emptyString
or not equal to theString
literal null, ignoring case.- Parameters:
name
- the name of the property to set.value
- the value to set the property to.- Returns:
- a reference to this
PropertiesBuilder
. - Throws:
IllegalArgumentException
- if the property name is not specified.- See Also:
-
setPropertyIfNotDefault
@NonNull public <T> PropertiesBuilder setPropertyIfNotDefault(@NonNull 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.- Type Parameters:
T
- Class type of the property value.- Parameters:
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.- Returns:
- a reference to this
PropertiesBuilder
. - See Also:
-
unsetProperty
Un-sets the named property. This method sets the given named property to an emptyString
.- Parameters:
name
- name of the property to unset.- Returns:
- a reference to this
PropertiesBuilder
. - Throws:
IllegalArgumentException
- if the property name is not specified.
-
isValuable
Determine whether the givenString
value is a validProperties
value. A property value is considered valid if it is not null, not empty and not equal to (case-insensitive)String
literal null.- Parameters:
value
-String
value for the property being set.- Returns:
- a boolean value indicating whether the given
String
value is a validProperties
value.
-
build
Builds theProperties
object from this builder.- Returns:
- the
Properties
object built by this builder. - See Also:
-