org.modeshape.common.math

## Class DurationOperations

- java.lang.Object
- - org.modeshape.common.math.DurationOperations

- All Implemented Interfaces:
    Comparator<Duration>, MathOperations<Duration>

      @Immutable
      public class DurationOperations
      extends Object
      implements MathOperations<Duration>, Comparator<Duration>

  The `math operations` for `Duration`s.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DurationOperations()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Duration` | `add(Duration value1, Duration value2)` Add the two operands and return the sum.
    `BigDecimal` | `asBigDecimal(Duration value)` Create a `BigDecimal` representation of the supplied value.
    `int` | `compare(Duration value1, Duration value2)` Compare the two operands and return an integer that describes whether the first value is larger, smaller or the same as the second value.
    `Duration` | `create(double value)` Convert the double representation into the natural object representation.
    `Duration` | `create(int value)` Convert the integer representation into the natural object representation.
    `Duration` | `create(long value)` Convert the long representation into the natural object representation.
    `Duration` | `createZeroValue()` Create the object form of the "zero value".
    `double` | `divide(Duration value1, Duration value2)` Divide the first operand by the second, and return the result.
    `double` | `doubleValue(Duration value)` Convert the value to a double.
    `float` | `floatValue(Duration value)` Convert the value to a float.
    `Duration` | `fromBigDecimal(BigDecimal value)` Convert the `BigDecimal` representation into the natural object representation.
    `Comparator<Duration>` | `getComparator()` Return a `Comparator` for this `operand class`.
    `int` | `getExponentInScientificNotation(Duration value)` Get the exponent if the number were written in exponential form.
    `Class<Duration>` | `getOperandClass()` Return the class that these operations operate upon.
    `Duration` | `increment(Duration value)` Increment the supplied operand by 1.
    `int` | `intValue(Duration value)` Convert the value to an integer.
    `Duration` | `keepSignificantFigures(Duration value, int numSigFigs)`
    `long` | `longValue(Duration value)` Convert the value to a long integer.
    `Duration` | `maximum(Duration value1, Duration value2)` Compare the two operands and return the one that is larger.
    `Duration` | `minimum(Duration value1, Duration value2)` Compare the two operands and return the one that is smaller.
    `Duration` | `multiply(Duration value1, Duration value2)` Multiply the two operands and return the product.
    `Duration` | `negate(Duration value)` Negate the supplied operand.
    `Duration` | `random(Duration minimum, Duration maximum, Random rng)` Generate a random instance within the specified range.
    `Duration` | `roundDown(Duration durationValue, int decimalShift)` Round down the supplied value to the desired scale.
    `Duration` | `roundUp(Duration durationValue, int decimalShift)` Round up the supplied value to the desired scale.
    `short` | `shortValue(Duration value)` Convert the value to a short.
    `double` | `sqrt(Duration value)` Return the square root of the supplied operand.
    `Duration` | `subtract(Duration value1, Duration value2)` Subtract the second operand from the first, and return the difference.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `equals`

- - ### Constructor Detail

    - #### DurationOperations

          public DurationOperations()

  - ### Method Detail

    - #### getOperandClass

          public Class<Duration> getOperandClass()

      Description copied from interface: `MathOperations`
      Return the class that these operations operate upon.
      Specified by:
        `getOperandClass` in interface `MathOperations<Duration>`
      Returns:
        the class

    - #### add

          public Duration add(Duration value1,
                     Duration value2)

      Description copied from interface: `MathOperations`
      Add the two operands and return the sum. The `zero value` is used in place of any operand that is null.
      Specified by:
        `add` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        the sum of the two operands.

    - #### subtract

          public Duration subtract(Duration value1,
                          Duration value2)

      Description copied from interface: `MathOperations`
      Subtract the second operand from the first, and return the difference. The `zero value` is used in place of any operand that is null.
      Specified by:
        `subtract` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        the difference between the two operands.

    - #### multiply

          public Duration multiply(Duration value1,
                          Duration value2)

      Description copied from interface: `MathOperations`
      Multiply the two operands and return the product. The `zero value` is used in place of any operand that is null.
      Specified by:
        `multiply` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        the product of the two operands.

    - #### divide

          public double divide(Duration value1,
                      Duration value2)

      Description copied from interface: `MathOperations`
      Divide the first operand by the second, and return the result. The `zero value` is used in place of any operand that is null.
      Specified by:
        `divide` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        the result of the division

    - #### negate

          public Duration negate(Duration value)

      Description copied from interface: `MathOperations`
      Negate the supplied operand. The `zero value` is used in place of any operand that is null.
      Specified by:
        `negate` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value that is to be negated
      Returns:
        the result of the negation

    - #### increment

          public Duration increment(Duration value)

      Description copied from interface: `MathOperations`
      Increment the supplied operand by 1. (Note, the exact meaning of "1" is dependent upon the particular `operand class`. The `zero value` is used in place of any operand that is null.
      Specified by:
        `increment` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value that is to be incremented
      Returns:
        the incremented value

    - #### maximum

          public Duration maximum(Duration value1,
                         Duration value2)

      Description copied from interface: `MathOperations`
      Compare the two operands and return the one that is larger. A null value is considered smaller than non-null values (including 0).
      Specified by:
        `maximum` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        the larger of the two operands

    - #### minimum

          public Duration minimum(Duration value1,
                         Duration value2)

      Description copied from interface: `MathOperations`
      Compare the two operands and return the one that is smaller. A null value is considered larger than non-null values (including 0).
      Specified by:
        `minimum` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        the smaller of the two operands

    - #### compare

          public int compare(Duration value1,
                    Duration value2)

      Description copied from interface: `MathOperations`
      Compare the two operands and return an integer that describes whether the first value is larger, smaller or the same as the second value. The semantics are identical to those of `Comparable`. The `zero value` is used in place of any operand that is null.
      Specified by:
        `compare` in interface `Comparator<Duration>`
      Specified by:
        `compare` in interface `MathOperations<Duration>`
      Parameters:
        `value1` - the first operand
        `value2` - the second operand
      Returns:
        -1 if the first value is smaller than the second, 1 if the first value is larger than the second, or 0 if they are equal.

    - #### asBigDecimal

          public BigDecimal asBigDecimal(Duration value)

      Description copied from interface: `MathOperations`
      Create a `BigDecimal` representation of the supplied value.
      Specified by:
        `asBigDecimal` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value that is to be converted to a BigDecimal
      Returns:
        the BigDecimal representation, or null if `value` is null

    - #### fromBigDecimal

          public Duration fromBigDecimal(BigDecimal value)

      Description copied from interface: `MathOperations`
      Convert the `BigDecimal` representation into the natural object representation. This may result in loss of some data (e.g., converting a decimal to an integer results in the loss of the fractional part of the number).
      Specified by:
        `fromBigDecimal` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the BigDecimal value
      Returns:
        the natural representation, or null if `value` is null

    - #### createZeroValue

          public Duration createZeroValue()

      Description copied from interface: `MathOperations`
      Create the object form of the "zero value". This is often used to create an uninitialized object.
      Specified by:
        `createZeroValue` in interface `MathOperations<Duration>`
      Returns:
        the object that represents zero.

    - #### create

          public Duration create(int value)

      Description copied from interface: `MathOperations`
      Convert the integer representation into the natural object representation.
      Specified by:
        `create` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the integer value
      Returns:
        the object representation of the integer

    - #### create

          public Duration create(long value)

      Description copied from interface: `MathOperations`
      Convert the long representation into the natural object representation.
      Specified by:
        `create` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the long value
      Returns:
        the object representation of the long integer

    - #### create

          public Duration create(double value)

      Description copied from interface: `MathOperations`
      Convert the double representation into the natural object representation.
      Specified by:
        `create` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the double value
      Returns:
        the object representation of the floating point number

    - #### sqrt

          public double sqrt(Duration value)

      Description copied from interface: `MathOperations`
      Return the square root of the supplied operand.
      Specified by:
        `sqrt` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value whose root is to be found; may not be null or 0
      Returns:
        the square root of the value

    - #### getComparator

          public Comparator<Duration> getComparator()

      Description copied from interface: `MathOperations`
      Return a `Comparator` for this `operand class`. The implementation is free to return the same comparator instance from multiple invocations of this method.
      Specified by:
        `getComparator` in interface `MathOperations<Duration>`
      Returns:
        a comparator

    - #### random

          public Duration random(Duration minimum,
                        Duration maximum,
                        Random rng)

      Description copied from interface: `MathOperations`
      Generate a random instance within the specified range.
      Specified by:
        `random` in interface `MathOperations<Duration>`
      Parameters:
        `minimum` - the minimum value, or null if the `zero-value` should be used for the minimum
        `maximum` - the maximum value, or null if the `zero-value` should be used for the maximum
        `rng` - the random number generator to use
      Returns:
        an instance of the `operand class` placed within the desired range using a random distribution, or null if this class does not support generating random instances

    - #### doubleValue

          public double doubleValue(Duration value)

      Description copied from interface: `MathOperations`
      Convert the value to a double. This may result in a loss of information depending upon the `operand class`.
      Specified by:
        `doubleValue` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value
      Returns:
        the representation as a double

    - #### floatValue

          public float floatValue(Duration value)

      Description copied from interface: `MathOperations`
      Convert the value to a float. This may result in a loss of information depending upon the `operand class`.
      Specified by:
        `floatValue` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value
      Returns:
        the representation as a float

    - #### intValue

          public int intValue(Duration value)

      Description copied from interface: `MathOperations`
      Convert the value to an integer. This may result in a loss of information depending upon the `operand class`.
      Specified by:
        `intValue` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value
      Returns:
        the representation as an integer

    - #### longValue

          public long longValue(Duration value)

      Description copied from interface: `MathOperations`
      Convert the value to a long integer. This may result in a loss of information depending upon the `operand class`.
      Specified by:
        `longValue` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value
      Returns:
        the representation as a long

    - #### shortValue

          public short shortValue(Duration value)

      Description copied from interface: `MathOperations`
      Convert the value to a short. This may result in a loss of information depending upon the `operand class`.
      Specified by:
        `shortValue` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value
      Returns:
        the representation as a short

    - #### getExponentInScientificNotation

          public int getExponentInScientificNotation(Duration value)

      Description copied from interface: `MathOperations`
      Get the exponent if the number were written in exponential form.
      Specified by:
        `getExponentInScientificNotation` in interface `MathOperations<Duration>`
      Parameters:
        `value` - the value
      Returns:
        the scale

    - #### roundUp

          public Duration roundUp(Duration durationValue,
                         int decimalShift)

      Description copied from interface: `MathOperations`
      Round up the supplied value to the desired scale. This process works (conceptually) by shifting the decimal point of the value by `decimalShift` places, rounding, and then shifting the decimal point of the rounded value by `-decimalShift`

      For example, consider the number 10.000354. This can be rounded to 10.0004 by calling this method and supplying the value and an "exponentToKeep" value of -4.

      Specified by:
        `roundUp` in interface `MathOperations<Duration>`
      Parameters:
        `durationValue` - the value to be rounded
        `decimalShift` - the number of places the decimal point should be shifted before rounding
      Returns:
        the rounded value

    - #### roundDown

          public Duration roundDown(Duration durationValue,
                           int decimalShift)

      Description copied from interface: `MathOperations`
      Round down the supplied value to the desired scale. This process works (conceptually) by shifting the decimal point of the value by `decimalShift` places, rounding, and then shifting the decimal point of the rounded value by `-decimalShift`

      For example, consider the number 10.000354. This can be rounded to 10.0003 by calling this method and supplying the value and an "exponentToKeep" value of -4.

      Specified by:
        `roundDown` in interface `MathOperations<Duration>`
      Parameters:
        `durationValue` - the value to be rounded
        `decimalShift` - the number of places the decimal point should be shifted before rounding
      Returns:
        the rounded value

    - #### keepSignificantFigures

          public Duration keepSignificantFigures(Duration value,
                                        int numSigFigs)

      Specified by:
        `keepSignificantFigures` in interface `MathOperations<Duration>`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.