Class MutablePropertySources

java.lang.Object
org.springframework.core.env.MutablePropertySources
All Implemented Interfaces:
Iterable<PropertySource<?>>, PropertySources

public class MutablePropertySources extends Object implements 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(PropertySource) and addLast(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 Details

    • MutablePropertySources

      public MutablePropertySources()
      Create a new MutablePropertySources object.
    • MutablePropertySources

      public MutablePropertySources(PropertySources propertySources)
      Create a new MutablePropertySources from the given propertySources object, preserving the original order of contained PropertySource objects.
  • Method Details

    • iterator

      public Iterator<PropertySource<?>> iterator()
      Specified by:
      iterator in interface Iterable<PropertySource<?>>
    • spliterator

      public Spliterator<PropertySource<?>> spliterator()
      Specified by:
      spliterator in interface Iterable<PropertySource<?>>
    • stream

      public Stream<PropertySource<?>> stream()
      Description copied from interface: PropertySources
      Return a sequential Stream containing the property sources.
      Specified by:
      stream in interface PropertySources
    • contains

      public boolean contains(String name)
      Description copied from interface: PropertySources
      Return whether a property source with the given name is contained.
      Specified by:
      contains in interface PropertySources
      Parameters:
      name - the name of the property source to find
    • get

      public @Nullable PropertySource<?> get(String name)
      Description copied from interface: PropertySources
      Return the property source with the given name, null if not found.
      Specified by:
      get in interface PropertySources
      Parameters:
      name - the name of the property source to find
    • addFirst

      public void addFirst(PropertySource<?> propertySource)
      Add the given property source object with the highest precedence.
    • addLast

      public void addLast(PropertySource<?> propertySource)
      Add the given property source object with the lowest precedence.
    • addBefore

      public void addBefore(String relativePropertySourceName, PropertySource<?> propertySource)
      Add the given property source object with precedence immediately higher than the named relative property source.
    • addAfter

      public void addAfter(String relativePropertySourceName, PropertySource<?> propertySource)
      Add the given property source object with precedence immediately lower than the named relative property source.
    • precedenceOf

      public int precedenceOf(PropertySource<?> propertySource)
      Return the precedence of the given property source, -1 if not found.
    • remove

      public @Nullable PropertySource<?> remove(String name)
      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

      public void replace(String name, PropertySource<?> propertySource)
      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 replace
      propertySource - 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 of PropertySource objects contained.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • assertLegalRelativeAddition

      protected void assertLegalRelativeAddition(String relativePropertySourceName, PropertySource<?> propertySource)
      Ensure that the given property source is not being added relative to itself.
    • removeIfPresent

      protected void removeIfPresent(PropertySource<?> propertySource)
      Remove the given property source if it is present.