Class Settings

  • Direct Known Subclasses:
    FileBasedSettings, PropertyBasedSettings

    public abstract class Settings
    extends Object
    Base easy-to-use settings implementation. The collection of (key, value) pairs. The keys values are case-sensitive.
    • Constructor Summary

      Constructors 
      Constructor Description
      Settings()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getBoolean​(String key)
      Returns a boolean value that corresponds to the given key.
      boolean getBoolean​(String key, boolean defaultValue)
      Returns a boolean value that corresponds to the given key.
      int getInteger​(String key)
      Returns an integer value that corresponds to the given key.
      int getInteger​(String key, int defaultValue)
      Returns an integer value that corresponds to the given key.
      long getLong​(String key)
      Returns a long value that corresponds to the given key.
      long getLong​(String key, long defaultValue)
      Returns a long value that corresponds to the given key.
      String getString​(String key)
      Returns a string value that corresponds to the given key.
      String getString​(String key, String defaultValue)
      Returns a string value that corresponds to the given key.
      boolean isDefined​(String key)
      Returns true if a corresponding value for the specified key is found, false otherwise.
      void setBoolean​(String key, boolean value)
      Sets the value corresponding to the given key.
      void setBoolean​(String key, boolean value, boolean flush)
      Sets the value corresponding to the given key.
      void setInteger​(String key, int value)
      Sets the value corresponding to the given key.
      void setInteger​(String key, int value, boolean flush)
      Sets the value corresponding to the given key.
      void setLong​(String key, long value)
      Sets the value corresponding to the given key.
      void setLong​(String key, long value, boolean flush)
      Sets the value corresponding to the given key.
      void setString​(String key, String value)
      Sets the value corresponding to the given key.
      void setString​(String key, String value, boolean flush)
      Sets the value corresponding to the given key.
    • Constructor Detail

      • Settings

        public Settings()
    • Method Detail

      • getBoolean

        public boolean getBoolean​(String key)
        Returns a boolean value that corresponds to the given key.
        Parameters:
        key - key
        Returns:
        a boolean value that corresponds to the given key
        Throws:
        IllegalArgumentException - if key is null or empty; also if value cannot be found for the specified key
      • getBoolean

        public boolean getBoolean​(String key,
                                  boolean defaultValue)
        Returns a boolean value that corresponds to the given key. If a value cannot be found then the specified default value is returned.
        Parameters:
        key - key
        defaultValue - default value
        Returns:
        a boolean value that corresponds to the given key
        Throws:
        IllegalArgumentException - if key is null or empty
      • setBoolean

        public void setBoolean​(String key,
                               boolean value)
                        throws IOException
        Sets the value corresponding to the given key.
        Parameters:
        key - key
        value - value
        Throws:
        IOException - if value storing failed
        IllegalArgumentException - if key is null or empty
      • setBoolean

        public void setBoolean​(String key,
                               boolean value,
                               boolean flush)
                        throws IOException
        Sets the value corresponding to the given key.
        Parameters:
        key - key
        value - value
        flush - whether to save to persistent storage immediately
        Throws:
        IOException - if value storing failed
        IllegalArgumentException - if key is null or empty
      • getString

        public String getString​(String key)
        Returns a string value that corresponds to the given key.
        Parameters:
        key - key
        Returns:
        corresponding value
        Throws:
        IllegalArgumentException - if key is null or empty; also if value cannot be found for the specified key
      • getString

        public String getString​(String key,
                                String defaultValue)
        Returns a string value that corresponds to the given key. If a value cannot be found then the specified default value is returned.
        Parameters:
        key - key
        defaultValue - default value
        Returns:
        string value that corresponds to the given key
        Throws:
        IllegalArgumentException - if key is null or empty
        NullPointerException - if defaultValue is null
      • setString

        public void setString​(String key,
                              String value,
                              boolean flush)
                       throws IOException
        Sets the value corresponding to the given key.
        Parameters:
        key - key
        value - value
        flush - whether to save to persistent storage immediately
        Throws:
        IOException - if value storing failed
        IllegalArgumentException - if key is null or empty
      • getInteger

        public int getInteger​(String key,
                              int defaultValue)
        Returns an integer value that corresponds to the given key. If a value cannot be found then the specified default value is returned.
        Parameters:
        key - key
        defaultValue - default value
        Returns:
        corresponding value
        Throws:
        IllegalArgumentException - if key is null or empty
        NumberFormatException - if value cannot be parsed to integer
      • getInteger

        public int getInteger​(String key)
        Returns an integer value that corresponds to the given key.
        Parameters:
        key - key
        Returns:
        corresponding value
        Throws:
        IllegalArgumentException - if key is null or empty; also if value cannot be found for the specified key
        NumberFormatException - if value cannot be parsed to integer
      • setInteger

        public void setInteger​(String key,
                               int value)
                        throws IOException
        Sets the value corresponding to the given key.
        Parameters:
        key - key
        value - value
        Throws:
        IOException - if value storing failed
        IllegalArgumentException - if key is null or empty
      • setInteger

        public void setInteger​(String key,
                               int value,
                               boolean flush)
                        throws IOException
        Sets the value corresponding to the given key.
        Parameters:
        key - key
        value - value
        flush - whether to save to persistent storage immediately
        Throws:
        IOException - if value storing failed
        IllegalArgumentException - if key is null or empty
      • getLong

        public long getLong​(String key,
                            long defaultValue)
        Returns a long value that corresponds to the given key. If a value cannot be found then the specified default value is returned.
        Parameters:
        key - key
        defaultValue - default value
        Returns:
        corresponding value
        Throws:
        IllegalArgumentException - if key is null or empty
        NumberFormatException - if value cannot be parsed to integer
      • getLong

        public long getLong​(String key)
        Returns a long value that corresponds to the given key.
        Parameters:
        key - key
        Returns:
        corresponding value
        Throws:
        IllegalArgumentException - if key is null or empty; also if value cannot be found for the specified key
        NumberFormatException - if value cannot be parsed to long
      • setLong

        public void setLong​(String key,
                            long value,
                            boolean flush)
                     throws IOException
        Sets the value corresponding to the given key.
        Parameters:
        key - key
        value - value
        flush - whether to save to persistent storage immediately
        Throws:
        IOException - if value storing failed
        IllegalArgumentException - if key is null or empty
      • isDefined

        public boolean isDefined​(String key)
        Returns true if a corresponding value for the specified key is found, false otherwise.
        Parameters:
        key - key
        Returns:
        whether a corresponding value for the specified key can be found
        Throws:
        IllegalArgumentException - if key is null or empty