Package org.springframework.core.env
Class MutablePropertySources
java.lang.Object
org.springframework.core.env.MutablePropertySources
- All Implemented Interfaces:
Iterable<PropertySource<?>>
,PropertySources
The default implementation of the
PropertySources
interface.
Allows manipulation of contained property sources and provides a constructor
for copying an existing PropertySources
instance.
Where precedence is mentioned in methods such as addFirst(org.springframework.core.env.PropertySource<?>)
and addLast(org.springframework.core.env.PropertySource<?>)
, this is with regard to the order in which property sources
will be searched when resolving a given property with a PropertyResolver
.
- Since:
- 3.1
- Author:
- Chris Beams, Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newMutablePropertySources
object.MutablePropertySources
(PropertySources propertySources) Create a newMutablePropertySources
from the given propertySources object, preserving the original order of containedPropertySource
objects. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAfter
(String relativePropertySourceName, PropertySource<?> propertySource) Add the given property source object with precedence immediately lower than the named relative property source.void
addBefore
(String relativePropertySourceName, PropertySource<?> propertySource) Add the given property source object with precedence immediately higher than the named relative property source.void
addFirst
(PropertySource<?> propertySource) Add the given property source object with highest precedence.void
addLast
(PropertySource<?> propertySource) Add the given property source object with lowest precedence.protected void
assertLegalRelativeAddition
(String relativePropertySourceName, PropertySource<?> propertySource) Ensure that the given property source is not being added relative to itself.boolean
Return whether a property source with the given name is contained.Return the property source with the given name,null
if not found.iterator()
int
precedenceOf
(PropertySource<?> propertySource) Return the precedence of the given property source,-1
if not found.Remove and return the property source with the given name,null
if not found.protected void
removeIfPresent
(PropertySource<?> propertySource) Remove the given property source if it is present.void
replace
(String name, PropertySource<?> propertySource) Replace the property source with the given name with the given property source object.int
size()
Return the number ofPropertySource
objects contained.Stream<PropertySource<?>>
stream()
Return a sequentialStream
containing the property sources.toString()
-
Constructor Details
-
MutablePropertySources
public MutablePropertySources()Create a newMutablePropertySources
object. -
MutablePropertySources
Create a newMutablePropertySources
from the given propertySources object, preserving the original order of containedPropertySource
objects.
-
-
Method Details
-
iterator
- Specified by:
iterator
in interfaceIterable<PropertySource<?>>
-
spliterator
- Specified by:
spliterator
in interfaceIterable<PropertySource<?>>
-
stream
Description copied from interface:PropertySources
Return a sequentialStream
containing the property sources.- Specified by:
stream
in interfacePropertySources
-
contains
Description copied from interface:PropertySources
Return whether a property source with the given name is contained.- Specified by:
contains
in interfacePropertySources
- Parameters:
name
- the name of the property source to find
-
get
Description copied from interface:PropertySources
Return the property source with the given name,null
if not found.- Specified by:
get
in interfacePropertySources
- Parameters:
name
- the name of the property source to find
-
addFirst
Add the given property source object with highest precedence. -
addLast
Add the given property source object with lowest precedence. -
addBefore
Add the given property source object with precedence immediately higher than the named relative property source. -
addAfter
Add the given property source object with precedence immediately lower than the named relative property source. -
precedenceOf
Return the precedence of the given property source,-1
if not found. -
remove
Remove and return the property source with the given name,null
if not found.- Parameters:
name
- the name of the property source to find and remove
-
replace
Replace the property source with the given name with the given property source object.- Parameters:
name
- the name of the property source to find and replacepropertySource
- the replacement property source- Throws:
IllegalArgumentException
- if no property source with the given name is present- See Also:
-
size
public int size()Return the number ofPropertySource
objects contained. -
toString
-
assertLegalRelativeAddition
protected void assertLegalRelativeAddition(String relativePropertySourceName, PropertySource<?> propertySource) Ensure that the given property source is not being added relative to itself. -
removeIfPresent
Remove the given property source if it is present.
-