Class PropertiesUtils

  • All Implemented Interfaces:
    Utils

    public abstract class PropertiesUtils
    extends java.lang.Object
    implements Utils
    The utilities class for Properties
    Since:
    1.0.0
    Author:
    Mercy
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​java.lang.Object> flatProperties​(java.util.Map<java.lang.String,​java.lang.Object> properties)
      Flattens a nested map of properties into a single-level map.
      protected static void flatProperties​(java.util.Map<java.lang.String,​java.lang.Object> properties, java.lang.String propertyNamePrefix, java.util.Map<java.lang.String,​java.lang.Object> flattenProperties)
      Recursively flattens the given properties map into a single-level map.
      static java.util.Properties newProperties()
      Creates a new empty Properties instance.
      static java.util.Properties newProperties​(java.util.Properties defaults)
      Creates a new Properties instance with the specified defaults.
      • Methods inherited from class java.lang.Object

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

      • flatProperties

        @Nonnull
        @Immutable
        public static java.util.Map<java.lang.String,​java.lang.Object> flatProperties​(java.util.Map<java.lang.String,​java.lang.Object> properties)
        Flattens a nested map of properties into a single-level map.

        If the input map is empty or null, the same map instance is returned.

        For example, given the following input:

        
         {
           "a": "1",
           "b": {
             "c": "2",
             "d": {
               "e": "3"
             }
           }
         }
         
        The resulting flattened map would be:
        
         {
           "a": "1",
           "b.c": "2",
           "b.d.e": "3"
         }
         
        Parameters:
        properties - The map containing potentially nested properties to be flattened.
        Returns:
        A new unmodifiable map with all properties flattened to a single level.
      • flatProperties

        protected static void flatProperties​(java.util.Map<java.lang.String,​java.lang.Object> properties,
                                             java.lang.String propertyNamePrefix,
                                             java.util.Map<java.lang.String,​java.lang.Object> flattenProperties)
        Recursively flattens the given properties map into a single-level map.
        Parameters:
        properties - The map containing properties to be flattened.
        propertyNamePrefix - The prefix for property names used during flattening.
        flattenProperties - The target map where flattened properties are stored.
      • newProperties

        @Nonnull
        public static java.util.Properties newProperties()
        Creates a new empty Properties instance.

        This method provides a convenient way to create an empty properties object.

        Example Usage

        
             Properties props = PropertiesUtils.newProperties();
             System.out.println(props.isEmpty()); // Output: true
        
             props.setProperty("key", "value");
             System.out.println(props); // Output: {key=value}
         
        Returns:
        a new, empty Properties
      • newProperties

        @Nonnull
        public static java.util.Properties newProperties​(java.util.Properties defaults)
        Creates a new Properties instance with the specified defaults.

        This method provides a convenient way to create a properties object with default properties.

        Example Usage

        
             Properties defaults = new Properties();
             defaults.setProperty("default.key", "default.value");
             Properties props = PropertiesUtils.newProperties(defaults);
             System.out.println(props.getProperty("default.key")); // Output: default.value
         
        Parameters:
        defaults - the default properties
        Returns:
        a new Properties with the specified defaults