Class PropertiesPropertySource

  • All Implemented Interfaces:
    PropertySource
    Direct Known Subclasses:
    PropertyFilePropertySource

    public class PropertiesPropertySource
    extends java.lang.Object
    implements PropertySource
    PropertySource backed by a Properties instance. Normalized property names follow a scheme like this: Log4jContextSelector would normalize to log4j2.contextSelector.
    Since:
    2.10.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int DEFAULT_PRIORITY  
      private static java.lang.String PREFIX  
      private int priority  
      private java.util.Properties properties  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsProperty​(java.lang.String key)
      For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.
      void forEach​(BiConsumer<java.lang.String,​java.lang.String> action)
      Iterates over all properties and performs an action for each key/value pair.
      java.lang.CharSequence getNormalForm​(java.lang.Iterable<? extends java.lang.CharSequence> tokens)
      Converts a list of property name tokens into a normal form.
      int getPriority()
      Returns the order in which this PropertySource has priority.
      java.lang.String getProperty​(java.lang.String key)
      For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.
      java.util.Collection<java.lang.String> getPropertyNames()
      Returns the list of all property names.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • properties

        private final java.util.Properties properties
      • priority

        private final int priority
    • Constructor Detail

      • PropertiesPropertySource

        public PropertiesPropertySource​(java.util.Properties properties)
      • PropertiesPropertySource

        public PropertiesPropertySource​(java.util.Properties properties,
                                        int priority)
    • Method Detail

      • getPriority

        public int getPriority()
        Description copied from interface: PropertySource
        Returns the order in which this PropertySource has priority. A higher value means that the source will be searched later and can be overridden by other property sources.
        Specified by:
        getPriority in interface PropertySource
        Returns:
        priority value
      • forEach

        public void forEach​(BiConsumer<java.lang.String,​java.lang.String> action)
        Description copied from interface: PropertySource
        Iterates over all properties and performs an action for each key/value pair.
        Specified by:
        forEach in interface PropertySource
        Parameters:
        action - action to perform on each key/value pair
      • getNormalForm

        public java.lang.CharSequence getNormalForm​(java.lang.Iterable<? extends java.lang.CharSequence> tokens)
        Description copied from interface: PropertySource
        Converts a list of property name tokens into a normal form. For example, a list of tokens such as "foo", "bar", "baz", might be normalized into the property name "log4j2.fooBarBaz".
        Specified by:
        getNormalForm in interface PropertySource
        Parameters:
        tokens - list of property name tokens
        Returns:
        a normalized property name using the given tokens
      • getPropertyNames

        public java.util.Collection<java.lang.String> getPropertyNames()
        Description copied from interface: PropertySource
        Returns the list of all property names.
        Specified by:
        getPropertyNames in interface PropertySource
        Returns:
        list of property names
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Description copied from interface: PropertySource
        For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.
        Specified by:
        getProperty in interface PropertySource
        Parameters:
        key - The key to search for.
        Returns:
        The value or null;
      • containsProperty

        public boolean containsProperty​(java.lang.String key)
        Description copied from interface: PropertySource
        For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.
        Specified by:
        containsProperty in interface PropertySource
        Parameters:
        key - The key to search for.
        Returns:
        The value or null;