Class FloatQuestion


  • public abstract class FloatQuestion
    extends Question
    A question to which the response is an floating point number.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected float[] suggestions
      Suggested values for this question.
      protected float value
      The current response for this question.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected FloatQuestion​(Interview interview, java.lang.String tag)
      Create a question with a nominated tag.
      protected FloatQuestion​(Interview interview, java.lang.String tag, float min, float max, float resolution)
      Create a question with a nominated tag.
    • Field Detail

      • value

        protected float value
        The current response for this question. This field should be treated as read-only. Use setValue to change the value.
      • suggestions

        protected float[] suggestions
        Suggested values for this question.
    • Constructor Detail

      • FloatQuestion

        protected FloatQuestion​(Interview interview,
                                java.lang.String tag)
        Create a question with a nominated tag.
        Parameters:
        interview - The interview containing this question.
        tag - A unique tag to identify this specific question.
      • FloatQuestion

        protected FloatQuestion​(Interview interview,
                                java.lang.String tag,
                                float min,
                                float max,
                                float resolution)
        Create a question with a nominated tag.
        Parameters:
        interview - The interview containing this question.
        tag - A unique tag to identify this specific question.
        min - The inclusive lower bound for responses to this question
        max - The inclusive upper bound for responses to this question
        resolution - The resolution for responses to this question.
        Throws:
        java.lang.IllegalArgumentException - if min is greater than or equal to max.
    • Method Detail

      • setBounds

        protected void setBounds​(float min,
                                 float max)
        Set the bounds for the response to this question.
        Parameters:
        min - The inclusive lower bound for responses to this question
        max - The inclusive upper bound for responses to this question
        Throws:
        java.lang.IllegalArgumentException - if min is greater than or equal to max.
      • getLowerBound

        public float getLowerBound()
        Get the inclusive lower bound for responses to this question.
        Returns:
        the lower bound
      • getUpperBound

        public float getUpperBound()
        Get the inclusive lower bound for responses to this question.
        Returns:
        the upper bound
      • isValid

        public boolean isValid()
        Deprecated.
        see #isValueValid
        Check if the value is set and within bounds.
        Returns:
        true if a value has been set for this question and is within the specified bounds
        See Also:
        clear()
      • setResolution

        public void setResolution​(float resolution)
        Set the resolution for responses to this question. Responses may be rounded to the nearest multiple of the resolution.
        Parameters:
        resolution - the resolution for responses to this question
        See Also:
        getResolution(), setValue(java.lang.String)
      • getResolution

        public float getResolution()
        Get the resolution for responses to this question. Responses may be rounded to the nearest multiple of the resolution.
        Returns:
        the resolution for responses to this question
        See Also:
        setResolution(float), setValue(java.lang.String)
      • getSuggestions

        public float[] getSuggestions()
        Get the suggested responses to this question, or null if none.
        Returns:
        The suggestions.
        See Also:
        setSuggestions(float[])
      • setSuggestions

        public void setSuggestions​(float[] newSuggestions)
        Set the set of suggested responses.
        Parameters:
        newSuggestions - The values to be set, or null if none
        See Also:
        getSuggestions()
      • getDefaultValue

        public float getDefaultValue()
        Get the default response for this question.
        Returns:
        the default response for this question.
        See Also:
        setDefaultValue(float)
      • setDefaultValue

        public void setDefaultValue​(float v)
        Set the default response for this question, used by the clear method.
        Parameters:
        v - the default response for this question.
        See Also:
        getDefaultValue()
      • getValue

        public float getValue()
        Get the current (default or latest) response to this question.
        Returns:
        The current value.
        See Also:
        setValue(java.lang.String)
      • getValueOnPath

        public float getValueOnPath()
                             throws Interview.NotOnPathFault
        Verify this question is on the current path, and if it is, return the current value.
        Returns:
        the current value of this question
        Throws:
        Interview.NotOnPathFault - if this question is not on the current path
        See Also:
        getValue()
      • getStringValue

        public java.lang.String getStringValue()
        Description copied from class: Question
        Get the response to this question as a string.
        Specified by:
        getStringValue in class Question
        Returns:
        a string representing the current response to this question, or null.
        See Also:
        Question.setValue(String)
      • setValue

        public void setValue​(java.lang.String s)
                      throws Interview.Fault
        Set the response to this question to the value represented by a string-valued argument. Argument is decoded against current locale.
        Specified by:
        setValue in class Question
        Parameters:
        s - A string containing the numeric value to be set. The number should be in the range of valid values defined for this question; if it is not, the value will be retained, but isValueValid() will return false.
        Throws:
        Interview.Fault - This exception is just retained for backwards compatibility; it should never actually be thrown.
        See Also:
        getValue(), getValue(), setValue(String, Locale)
      • setValue

        public void setValue​(java.lang.String s,
                             java.util.Locale l)
                      throws Interview.Fault
        Set the response to this question to the value represented by a string-valued argument, given in certain locale.
        Parameters:
        s - A string containing the numeric value to be set. The number should be in the range of valid values defined for this question; if it is not, the value will be retained, but isValueValid() will return false.
        l - A locale that should be used to decode numeric value from given string parameter
        Throws:
        Interview.Fault - This exception is just retained for backwards compatibility; it should never actually be thrown.
        See Also:
        getValue(), getValue(), setValue(String, Locale)
      • setValue

        public void setValue​(float newValue)
        Set the current value.
        Parameters:
        newValue - The value to be set. It should be in the range of valid values defined for this question.
        See Also:
        getValue()
      • isValueValid

        public boolean isValueValid()
        Description copied from class: Question
        Check if the question currently has a valid response.
        Specified by:
        isValueValid in class Question
        Returns:
        true if the question currently has a valid response, and false otherwise.
      • isValueAlwaysValid

        public boolean isValueAlwaysValid()
        Description copied from class: Question
        Check if the question always has a valid response. This may be true, for example, for a choice question with a default response.
        Specified by:
        isValueAlwaysValid in class Question
        Returns:
        true if the question always has a valid response, and false otherwise.
      • setLabelHints

        protected void setLabelHints​(float start,
                                     float increment)
        Set hints for the rendering system for the values that might be labelled.
        Parameters:
        start - The lowest value to be labelled
        increment - The increment for successive labels
      • getLabelStartHint

        public float getLabelStartHint()
        Get a hint for the rendering system for the lowest value that might be labelled.
        Returns:
        The lowest value that might be labelled.
      • getLabelIncrementHint

        public float getLabelIncrementHint()
        Get a hint for the rendering system for the increment between labels.
        Returns:
        The increment between values that might be labelled.
      • clear

        public void clear()
        Clear any response to this question, resetting the value back to its initial state.
        Specified by:
        clear in class Question
      • load

        protected void load​(java.util.Map data)
        Load the value for this question from a dictionary, using the tag as the key.
        Specified by:
        load in class Question
        Parameters:
        data - The map from which to load the value for this question.
      • save

        protected void save​(java.util.Map data)
        Save the value for this question in a dictionary, using the tag as the key.
        Specified by:
        save in class Question
        Parameters:
        data - The map in which to save the value for this question.