Package openbook.util

Class PropertyHelper


  • public class PropertyHelper
    extends java.lang.Object
    A set of static utility functions to read properties from file, manage properties with multi-part keys, array style properties etc.
    Author:
    Pinaki Poddar
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertyHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canFind​(java.lang.String resource)
      Affirm if the given resource is available either as a resource in the current thread's context classpath or as a file.
      static java.util.Map<java.lang.String,​java.lang.Object> filter​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String name, boolean prefix, boolean includeArrays)
      Filter the properties by the given name.
      static java.util.Map<java.lang.String,​java.util.List<java.lang.Object>> filterArrayKeys​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String name, boolean prefix)
      Select only those property keys which ends with an array marker such as openjpa.DataCache[1].
      static double getDouble​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key, double def)  
      static int getInteger​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key, int def)  
      static java.util.Map<java.lang.String,​java.lang.String> getMap​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key)  
      static java.util.Map<java.lang.String,​java.lang.String> getMap​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key, java.util.Map<java.lang.String,​java.lang.String> def)  
      static java.lang.String getPrefix​(java.lang.String s)  
      static java.util.Map<java.lang.String,​java.lang.Object> getSection​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String section)
      Get the portion of the given map whose key has the given section at prefix.
      static java.util.Map<java.lang.String,​java.lang.Object> getSection​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String section, boolean retain)
      Get the portion of the given map whose key has the given section at prefix.
      static java.lang.String getString​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key, java.lang.String def)  
      static java.util.List<java.lang.String> getStringList​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key)  
      static java.util.List<java.lang.String> getStringList​(java.util.Map<java.lang.String,​java.lang.Object> props, java.lang.String key, java.util.List<java.lang.String> def)  
      static java.util.Set<java.lang.String> getSubsectionKeys​(java.util.Set<java.lang.String> keys, java.lang.String section)  
      static java.util.Map<java.lang.String,​java.lang.Object> load​(java.lang.String resource)
      Load properties from the given name resource.
      static java.util.Map<java.lang.String,​java.lang.Object> overwriteWithSystemProperties​(java.util.Map<java.lang.String,​java.lang.Object> original)
      Overwrites any key-value pair in the given map for which a System property is available
      static java.util.Map<java.lang.String,​java.lang.Object> toMap​(java.util.Properties p)  
      • Methods inherited from class java.lang.Object

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

      • PropertyHelper

        public PropertyHelper()
    • Method Detail

      • filter

        public static java.util.Map<java.lang.String,​java.lang.Object> filter​(java.util.Map<java.lang.String,​java.lang.Object> props,
                                                                                    java.lang.String name,
                                                                                    boolean prefix,
                                                                                    boolean includeArrays)
        Filter the properties by the given name.
        Parameters:
        name - a part of the key
        prefix - if true, property key must begin with the given name. Otherwise, the key merely contains the name to qualify.
        Returns:
        key-value pairs that match.
      • filterArrayKeys

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.Object>> filterArrayKeys​(java.util.Map<java.lang.String,​java.lang.Object> props,
                                                                                                             java.lang.String name,
                                                                                                             boolean prefix)
        Select only those property keys which ends with an array marker such as openjpa.DataCache[1]. The multiple values of the property is inserted into the resultant map as a List of object against the original key.
        For example, if the original map had three key-value pairs as
      • openjpa.DataCache[1]=true
      • openjpa.DataCache[2]=false
      • openjpa.DataCache[3]=default
        Then that will result into a single entry in the resultant Map under the key openjpa.DataCache with a value as a List of three elements namely {true, false, default}. The array index values are not significant other than they must all be different for the same base key.
Parameters:
name - part of the property key
prefix - does the name must appear as a prefix?
Returns:
key-value pairs that match.