Class PropertySource<T>

    • Nested Class Summary

      Nested Classes 
      Modifier and TypeClassDescription
      static class PropertySource.StubPropertySource
      PropertySource to be used as a placeholder in cases where an actual property source cannot be eagerly initialized at application context creation time.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      PropertySource​(String name)
      Create a new PropertySource with the given name and with a new Object instance as the underlying source.
      PropertySource​(String name, T source)
      Create a new PropertySource with the given name and source object.
    • Constructor Detail

      • PropertySource

        public PropertySource​(String name,
                              T source)
        Create a new PropertySource with the given name and source object.
        Parameters:
        name - the associated name
        source - the source object
      • PropertySource

        public PropertySource​(String name)
        Create a new PropertySource with the given name and with a new Object instance as the underlying source.

        Often useful in testing scenarios when creating anonymous implementations that never query an actual source but rather return hard-coded values.

    • Method Detail

      • getName

        public String getName()
        Return the name of this PropertySource.
      • getSource

        public T getSource()
        Return the underlying source object for this PropertySource.
      • containsProperty

        public boolean containsProperty​(String name)
        Return whether this PropertySource contains the given name.

        This implementation simply checks for a null return value from getProperty(String). Subclasses may wish to implement a more efficient algorithm if possible.

        Parameters:
        name - the property name to find
      • equals

        public boolean equals​(@Nullable
                              Object other)
        This PropertySource object is equal to the given object if:
        • they are the same instance
        • the name properties for both objects are equal

        No properties other than name are evaluated.

        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Return a hash code derived from the name property of this PropertySource object.
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Produce concise output (type and name) if the current log level does not include debug. If debug is enabled, produce verbose output including the hash code of the PropertySource instance and every name/value property pair.

        This variable verbosity is useful as a property source such as system properties or environment variables may contain an arbitrary number of property pairs, potentially leading to difficult to read exception and log messages.

        Overrides:
        toString in class Object
        See Also:
        Log.isDebugEnabled()
      • named

        public static PropertySource<?> named​(String name)
        Return a PropertySource implementation intended for collection comparison purposes only.

        Primarily for internal use, but given a collection of PropertySource objects, may be used as follows:

         List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
         sources.add(new MapPropertySource("sourceA", mapA));
         sources.add(new MapPropertySource("sourceB", mapB));
         assert sources.contains(PropertySource.named("sourceA"));
         assert sources.contains(PropertySource.named("sourceB"));
         assert !sources.contains(PropertySource.named("sourceC"));
         
        The returned PropertySource will throw UnsupportedOperationException if any methods other than equals(Object), hashCode(), and toString() are called.
        Parameters:
        name - the name of the comparison PropertySource to be created and returned.