Class PropertiesBuilder

java.lang.Object
com.complexible.common.base.PropertiesBuilder

public final class PropertiesBuilder extends Object

Simple builder class for creating instances of Properties

Since:
0.3
Version:
2.2.1
Author:
Michael Grove
  • Method Details

    • create

      public static PropertiesBuilder create()
      Create a new PropertiesBuilder
      Returns:
      a new builder
    • create

      public static PropertiesBuilder create(Properties theProps)
      Create a new PropertiesBuilder
      Parameters:
      theProps - create a new builder starting from the provided set of properties. A copy of these properties are made, the original remains unaltered by the builder.
      Returns:
      a new builder
    • create

      public static PropertiesBuilder create(Path theSource)
      Create a new PropertiesBuilder
      Parameters:
      theSource - create a new builder starting from the provided properties file.
      Returns:
      a new builder
    • create

      public static Properties create(String... optionPairs)
    • get

      public String get(String theKey)
      Get the specified property from this builder.
      Parameters:
      theKey - the key
      Returns:
      the value or null if not set
    • set

      public PropertiesBuilder set(String theKey, String theValue)
      Set the specified property key-value pair
      Parameters:
      theKey - the key
      theValue - the value
      Returns:
      this builder
    • remove

      public PropertiesBuilder remove(String theKey)
      Remove the specified property
      Parameters:
      theKey - the key
      Returns:
      this builder
    • setTrue

      public PropertiesBuilder setTrue(String theKey)
    • setFalse

      public PropertiesBuilder setFalse(String theKey)
    • withPrefix

      public PropertiesBuilder.PrefixedPropertiesBuilder withPrefix(String thePrefix)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • build

      public Properties build()
      Return the created Properties instance
      Returns:
      the properties
    • propertiesToString

      public static String propertiesToString(Properties properties)
    • propertiesToString

      public static String propertiesToString(Properties properties, boolean includeTimestamp)
    • propertiesFromString

      public static Properties propertiesFromString(String theContents)
      The inverse of propertiesToString(Properties).

      Reads with a Reader, to match the one propertiesToString writes with. Encoding the string as UTF-8 and handing it to Properties.load(java.io.InputStream), which decodes ISO-8859-1, mangled every character outside of ASCII, so a data source option carrying the contents of a file came back garbled everywhere it was read. Deterministically: the node the data source was added on holds the options the client sent and never reads them back, so it alone had the content intact, and only until it restarted.

      Values are still trimmed, EnhancedProperties being what they are read into, and equally trimmed on their way in, so what a round trip returns is what the writer holds.

    • propertiesFromFile

      public static Properties propertiesFromFile(Path theSource)