public class PropertyUtil extends Object
Properties
object, which may have a system
of inherited defaults. When a Map
and a Properties
object or two Properties
objects must be combined in a
"fused" configuration, it may be necessary to "flatten" a Properties
object such that all inherited properties are placed
within a simple Map
. This reduces the problem to fusing
two maps, which may be done using Map.putAll( Map other
)
.
Under some circumstances, it may be desirable to report a conflict
which would otherwise be silently ignored by Map.putAll( Map
other )
. A helper method has been provided to report such
conflicts rather than letting one Map
override another.
Constructor and Description |
---|
PropertyUtil() |
Modifier and Type | Method and Description |
---|---|
static Properties |
convert(Map configParams) |
static Properties |
flatCopy(Properties props)
Return a flatten copy of the specified
Properties . |
static Map |
flatten(Properties properties)
Return a Map that provides a flattened view of a Properties
object.
|
static Properties |
fuse(Map defaults,
Map override)
Fuses two configurations and ignores any conflicts.
|
static Properties |
fuse(Map defaults,
Map override,
boolean ignoreConflicts)
Fuses two configurations and optionally reports any conflicts.
|
static void |
list(String msg,
Properties properties,
PrintStream ps)
Lists all entries defined either directly by a
Properties
object or at any level within its defaults hierarchy. |
public static Properties flatCopy(Properties props)
Properties
. The
returned object does not share any structure with the source
object, but it does share key and value references. Since keys
and values are String
s for a Properties
instance
this SHOULD NOT be a problem. The behavior is equivilent to:
Properties tmp = new Properties(); tmp.putAll( flatten( props ) );
props
- The properties to be flattened and copied.public static Map flatten(Properties properties)
For each level of the Properties object, visit all keys and then resolve each key against the top-level Properties object placing the result into the output Map. The order of visitation of the Properties levels does not matter since the value of the key is always defined against the top-level Properties object which handles any defaults correctly.
a) Example overwrites any shared keys in p1 with the definitions for those keys in p2. Properties p1 = ...; Properties p2 = ...; p1.putAll( flatten( p2 ) ); b) Examples in which a Map and a Properties object are fused. Map m1 = ...; Properties p1 = ....; // Override m1 with p1. m1.putAll( flatten( p1 ) ); vs. // Override p1 with m1. p1.putAll( m1 );
public static void list(String msg, Properties properties, PrintStream ps)
Properties
object or at any level within its defaults hierarchy.public static Properties fuse(Map defaults, Map override)
defaults
- The default configuration.override
- Another configuration whose values will be
fused with the defaults. If this is a Properties
object then it is first flattened so that any
inherited property values will be fused.Properties
object. If defaults was a
Properties
object, then this is defaults and any
values from override have been added to defaults.
Otherwise a new Properties
object is created, the
entries from defaults are copied into that Properties
object, and any values from override are
copied onto that Properties
object.public static Properties fuse(Map defaults, Map override, boolean ignoreConflicts)
defaults
- The default configuration.override
- Another configuration whose values will be
fused with the defaults. If this is a Properties
object then it is first flattened so that any
inherited property values will be fused.ignoreConflicts
- When true an exception is not
reported if an entry from override would override an
entry in defaults.Properties
object. If defaults was a
Properties
object, then this is defaults and any
values from override have been added to defaults.
Otherwise a new Properties
object is created, the
entries from defaults are copied into that Properties
object, and any values from override are
copied onto that Properties
object.public static Properties convert(Map configParams)
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.