Class PropertyUtils


  • public final class PropertyUtils
    extends Object
    A class to convert properties to strings and back.
    • Method Detail

      • splitPropertiesOnPipe

        public static Properties splitPropertiesOnPipe​(String toSplit)
        Construct a Properties object from a single string, converting '|' symbols to end of line characters for parsing.

        Example: "abc=def|car=bmw" gets converted to "abc" -> "def", and "car" -> "bmw"

        Parameters:
        toSplit - The string value to convert to properties, pipe separated
        Returns:
        the list of properties splitPropertiesOnDelimiter(java.lang.String, char)
      • splitPropertiesOnSemicolon

        public static Properties splitPropertiesOnSemicolon​(String toSplit)
        Construct a Properties object from a single string, converting ';' symbols to end of line characters for parsing.

        Example: "abc=def;car=bmw" gets converted to "abc" -> "def", and "car" -> "bmw"

        Parameters:
        toSplit - The string value to convert to properties, semicolon separated
        Returns:
        the list of properties splitPropertiesOnDelimiter(java.lang.String, char)
      • splitPropertiesOnDelimiter

        public static Properties splitPropertiesOnDelimiter​(String toSplit,
                                                            char delimiter)
        Construct a Properties object from a single string, by splitting it on a specified delimiter.

        Example: "abc=def;car=bmw" gets converted to "abc" -> "def", and "car" -> "bmw" where: delimiter = ;

        Parameters:
        toSplit - The string value to convert to properties
        delimiter - The delimiter of the string
        Returns:
        the list of properties
      • joinOnPipe

        public static String joinOnPipe​(Map<String,​String> toJoin)
        Convert properties to a string representation.
        Parameters:
        toJoin - A list of properties to convert
        Returns:
        the properties as a string, pipe delimited
      • joinOnSemicolon

        public static String joinOnSemicolon​(Map<String,​String> toJoin)
        Convert properties to a string representation.
        Parameters:
        toJoin - A list of properties to convert
        Returns:
        the properties as a string, pipe delimited
      • joinOnDelimiter

        public static String joinOnDelimiter​(Map<String,​String> toJoin,
                                             char delimiter)
        Convert properties to a string representation, based on the specified delimiter.
        Parameters:
        toJoin - object to serialize as a string
        delimiter - how to separate entries from each other
        Returns:
        the properties as a string, delimited by the above
      • setPropertyIfNotNull

        public static void setPropertyIfNotNull​(Properties properties,
                                                String property,
                                                Object value)
        Sets a property value if the property is not null.
        Parameters:
        properties - the properties object to store the property into
        property - the property to set
        value - the value to set
      • escapeBackSlashesIfNotNull

        public static String escapeBackSlashesIfNotNull​(String in)
        Escapes backslashes so that they can parse properly.
        Parameters:
        in - - string with backslashes
        Returns:
        string with backslashes escaped, or null, if passed null
      • toMap

        public static Map<String,​String> toMap​(Properties properties)
        Returns a Map<String, String> out of a Java Properties object.
        Parameters:
        properties - the properties object to convert
        Returns:
        Java Map corresponding to the Java Properties object.