Package io.microsphere.collection
Class PropertiesUtils
- java.lang.Object
-
- io.microsphere.collection.PropertiesUtils
-
-
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 voidflatProperties(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.PropertiesnewProperties()Creates a new emptyPropertiesinstance.static java.util.PropertiesnewProperties(java.util.Properties defaults)Creates a newPropertiesinstance with the specified defaults.
-
-
-
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:
The resulting flattened map would be:{ "a": "1", "b": { "c": "2", "d": { "e": "3" } } }{ "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 emptyPropertiesinstance.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 newPropertiesinstance 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
Propertieswith the specified defaults
-
-