Class DoubleConfigKey


  • public abstract class DoubleConfigKey
    extends ConfigKey<java.lang.Double>
    Config key for double precision values. NaN and null are not distinguished.

    Static methods are provided to produce config keys with a variety of GUI options for specifying values.

    Since:
    22 Feb 2013
    Author:
    Mark Taylor
    • Constructor Detail

      • DoubleConfigKey

        protected DoubleConfigKey​(ConfigMeta meta,
                                  double dflt)
        Constructor.
        Parameters:
        meta - metadata
        dflt - default value
    • Method Detail

      • valueToString

        public java.lang.String valueToString​(java.lang.Double value)
        Description copied from class: ConfigKey
        Reports a value as a string. If at all possible the roundtripping should be possible, so stringToValue(valueToString(v)).equals(v). A null value, if permitted, should be represented as an empty string.
        Specified by:
        valueToString in class ConfigKey<java.lang.Double>
        Parameters:
        value - possible value associated with this key
        Returns:
        string representation
      • stringToValue

        public java.lang.Double stringToValue​(java.lang.String txt)
                                       throws ConfigException
        Description copied from class: ConfigKey
        Decodes a string value to the value type of this key. An empty string should be interpreted as a null value, but this may cause an exception if null is not a permissible value for this key.
        Specified by:
        stringToValue in class ConfigKey<java.lang.Double>
        Parameters:
        txt - string representation of value
        Returns:
        value
        Throws:
        ConfigException
      • createTextKey

        public static DoubleConfigKey createTextKey​(ConfigMeta meta)
        Constructs a key with a text field specifier and default NaN.
        Parameters:
        meta - metadata
        Returns:
        key
      • createTextKey

        public static DoubleConfigKey createTextKey​(ConfigMeta meta,
                                                    double dflt)
        Constructs a key with a text field specifier and an explicit default.
        Parameters:
        meta - metadata
        dflt - default value
        Returns:
        key
      • createToggleKey

        public static DoubleConfigKey createToggleKey​(ConfigMeta meta,
                                                      double fval,
                                                      double tval)
        Returns a key with a specifier that only provides a toggle between two values.
        Parameters:
        meta - metadata
        fval - value for toggle false (default)
        tval - value for toggle true
        Returns:
        key
      • createSliderKey

        public static DoubleConfigKey createSliderKey​(ConfigMeta meta,
                                                      double dflt,
                                                      double lo,
                                                      double hi,
                                                      boolean log)
        Returns a key with a linear or logarithmic slider for a specifier. Note the lower and upper bounds configure only the slider range, they do not enforce a range when the value is set from a string value.
        Parameters:
        meta - metadata
        dflt - default value
        lo - slider lower bound
        hi - slider upper bound
        log - true for logarithmic slider scale, false for linear
        Returns:
        key
      • createSliderKey

        public static DoubleConfigKey createSliderKey​(ConfigMeta meta,
                                                      double dflt,
                                                      double lo,
                                                      double hi,
                                                      boolean log,
                                                      boolean flip,
                                                      SliderSpecifier.TextOption txtOpt)
        Returns a key with a linear or logarithmic slider for a specifier, more options available. Note the lower and upper bounds configure only the slider range, they do not enforce a range when the value is set from a string value.
        Parameters:
        meta - metadata
        dflt - default value
        lo - slider lower bound
        hi - slider upper bound
        log - true for logarithmic slider scale, false for linear
        flip - true to make slider values increase right to left
        txtOpt - configures whether a text field should appear; null means NONE
        Returns:
        key
      • doubleToString

        public static java.lang.String doubleToString​(double dval)
        Returns a string representation of a double value.
        Parameters:
        dval - double value, may be NaN
        Returns:
        stringified value, may be the empty string but not null
      • stringToDouble

        public static double stringToDouble​(java.lang.String txt,
                                            ConfigKey<?> key)
                                     throws ConfigException
        Interprets the value of a string as a double precision number.
        Parameters:
        txt - string, may be null
        key - reference key, used for error reporting
        Returns:
        numeric value where possible, NaN for empty string
        Throws:
        ConfigException - for non-numeric strings