Package hec.data

Class UsgsRounder

java.lang.Object
hec.data.UsgsRounder

public class UsgsRounder extends Object
Provides functionality of USGS rounding arrays (called rounding specifications in this package). The full description of using rounding arrays can be found in Section 3.5 (Data Rounding Convention) of the ADAPS Section of the National Water Information System User's Manual.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UsgsRounder(CharSequence roundingSpec)
    Public Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    format(double value)
    Formats a single value according to the rounding specification
    format(double[] values)
    Formats an array of values according to the rounding specification
     
    int
    Retrieves the maximum number of decimal places for the specification
    Retrieves the rounding specification
    int[]
    Retrieves the array of significant digits for the specification
    double
    round(double value)
    Rounds a single value according to the rounding specification
    double[]
    round(double[] values)
    Rounds an array of values according to the rounding specification
    double[]
    round(double[] values, boolean roundHalfEven)
    Rounds an array of values according to the rounding specification
    double
    round(double value, boolean roundHalfEven)
    Rounds a single value according to the rounding specification
    void
    setMaxDecimalPlaces(int maxDecimalPlaces)
    Sets the maximum number of decimal places for the specification.
    void
    Sets the rounding specification
    void
    setSignificantDigits(int[] significantDigits)
    Sets the array of significant digits for the specification.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • UsgsRounder

      public UsgsRounder(CharSequence roundingSpec) throws RoundingException
      Public Constructor
      Parameters:
      roundingSpec - The USGS-style rounding specification. This is a sting comprised of 10 digits.
      Throws:
      RoundingException
  • Method Details

    • getDefault

      public static UsgsRounder getDefault()
    • round

      public double round(double value) throws RoundingException
      Rounds a single value according to the rounding specification
      Parameters:
      value - The value to round
      Returns:
      The value, rounded according to the specification
      Throws:
      RoundingException
    • round

      public double round(double value, boolean roundHalfEven) throws RoundingException
      Rounds a single value according to the rounding specification
      Parameters:
      value - The value to round
      roundHalfEven - Specifies whether .5 should be rounded to nearest even integer (true) or rounded away from zero (false)
      Returns:
      The value, rounded according to the specification
      Throws:
      RoundingException
    • round

      public double[] round(double[] values) throws RoundingException
      Rounds an array of values according to the rounding specification
      Parameters:
      values - The values to round
      Returns:
      A copy of the input values, rounded according to the specification
      Throws:
      RoundingException
    • round

      public double[] round(double[] values, boolean roundHalfEven) throws RoundingException
      Rounds an array of values according to the rounding specification
      Parameters:
      values - The values to round
      roundHalfEven - Specifies whether .5 should be rounded to nearest even integer (true) or rounded away from zero (false)
      Returns:
      A copy of the input values, rounded according to the specification
      Throws:
      RoundingException
    • format

      public String format(double value) throws RoundingException
      Formats a single value according to the rounding specification
      Parameters:
      value - The value to format
      Returns:
      The value, formatted according to the specification
      Throws:
      RoundingException
    • format

      public String[] format(double[] values) throws RoundingException
      Formats an array of values according to the rounding specification
      Parameters:
      values - The values to format
      Returns:
      Representations of the input values, formatted according to the specification
      Throws:
      RoundingException
    • getSignificantDigits

      public int[] getSignificantDigits()
      Retrieves the array of significant digits for the specification
      Returns:
    • setSignificantDigits

      public void setSignificantDigits(int[] significantDigits) throws RoundingException
      Sets the array of significant digits for the specification.
      Parameters:
      significantDigits - The array of significant digits. Must be a nine element array with each element in the range 0..9.
      Throws:
      RoundingException
    • getMaxDecimalPlaces

      public int getMaxDecimalPlaces()
      Retrieves the maximum number of decimal places for the specification
      Returns:
      The maximum number of decimal places
    • setMaxDecimalPlaces

      public void setMaxDecimalPlaces(int maxDecimalPlaces) throws RoundingException
      Sets the maximum number of decimal places for the specification.
      Parameters:
      maxDecimalPlaces - The maximum number of decimal places. Must be in the range 0..9
      Throws:
      RoundingException
    • getRoundingSpec

      public String getRoundingSpec()
      Retrieves the rounding specification
      Returns:
      The rounding specification
    • setRoundingSpec

      public void setRoundingSpec(CharSequence roundingSpec) throws RoundingException
      Sets the rounding specification
      Parameters:
      roundingSpec - The USGS-style rounding specification. This is a sting comprised of 10 digits.
      Throws:
      RoundingException
    • toString

      public String toString()
      Overrides:
      toString in class Object