Class SimpleConfiguration

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    FluoConfiguration

    public class SimpleConfiguration
    extends Object
    implements Serializable
    A simple configuration wrapper for Apache Commons configuration. The implementation supports reading and writing properties style config and interpolation.

    This simple wrapper was created to keep 3rd party APIs out of the Fluo API.

    Since:
    1.0.0
    See Also:
    Serialized Form
    • Constructor Detail

      • SimpleConfiguration

        public SimpleConfiguration()
      • SimpleConfiguration

        public SimpleConfiguration​(File propertiesFile)
        Read a properties style config from given file.
      • SimpleConfiguration

        public SimpleConfiguration​(InputStream in)
        Read a properties style config from given input stream.
      • SimpleConfiguration

        public SimpleConfiguration​(SimpleConfiguration other)
        Copy constructor.
      • SimpleConfiguration

        public SimpleConfiguration​(Map<String,​String> map)
    • Method Detail

      • clear

        public void clear()
      • clearProperty

        public void clearProperty​(String key)
      • containsKey

        public boolean containsKey​(String key)
      • getBoolean

        public boolean getBoolean​(String key)
      • getBoolean

        public boolean getBoolean​(String key,
                                  boolean defaultValue)
      • getInt

        public int getInt​(String key)
      • getInt

        public int getInt​(String key,
                          int defaultValue)
      • getLong

        public long getLong​(String key)
      • getLong

        public long getLong​(String key,
                            long defaultValue)
      • getRawString

        public String getRawString​(String key)
        Returns:
        raw property without interpolation or null if not set.
      • load

        public void load​(InputStream in)
        Loads configuration from InputStream. Later loads have lower priority.
        Parameters:
        in - InputStream to load from
        Since:
        1.2.0
      • load

        public void load​(File file)
        Loads configuration from File. Later loads have lower priority.
        Parameters:
        file - File to load from
        Since:
        1.2.0
      • save

        public void save​(File file)
      • setProperty

        public void setProperty​(String key,
                                Boolean value)
      • setProperty

        public void setProperty​(String key,
                                Integer value)
      • setProperty

        public void setProperty​(String key,
                                Long value)
      • setProperty

        public void setProperty​(String key,
                                String value)
      • setProperties

        public void setProperties​(String key,
                                  String... values)
        Since:
        2.0.0
      • getProperties

        public String[] getProperties​(String key)
        Since:
        2.0.0
      • subset

        public SimpleConfiguration subset​(String prefix)
        Returns a subset of config that start with given prefix. The prefix will not be present in keys of the returned config. Any changes made to the returned config will be made to this and visa versa.
      • orElse

        public SimpleConfiguration orElse​(SimpleConfiguration fallback)
        Parameters:
        fallback - SimpleConfiguration to join together
        Returns:
        a new simple configuration that contains all of the current properties from this plus the properties from fallback that are not present in this.
        Since:
        1.2.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toMap

        public Map<String,​String> toMap()
        Returns:
        An immutable copy of this configurations as a map. Changes to this after toMap() is called will not be reflected in the map.