Package org.h2.value

Class ValueNumeric

All Implemented Interfaces:
HasSQL, Typed

public final class ValueNumeric extends ValueBigDecimalBase
Implementation of the NUMERIC data type.
  • Field Details

    • ZERO

      public static final ValueNumeric ZERO
      The value 'zero'.
    • ONE

      public static final ValueNumeric ONE
      The value 'one'.
    • DEFAULT_SCALE

      public static final int DEFAULT_SCALE
      The default scale for a NUMERIC value.
      See Also:
    • MAXIMUM_SCALE

      public static final int MAXIMUM_SCALE
      The maximum scale.
      See Also:
  • Constructor Details

    • ValueNumeric

      private ValueNumeric(BigDecimal value)
  • Method Details

    • getString

      public String getString()
      Description copied from class: Value
      Get the value as a string.
      Specified by:
      getString in class Value
      Returns:
      the string
    • getSQL

      public StringBuilder getSQL(StringBuilder builder, int sqlFlags)
      Description copied from interface: HasSQL
      Appends the SQL statement of this object to the specified builder.
      Parameters:
      builder - string builder
      sqlFlags - formatting flags
      Returns:
      the specified string builder
    • getType

      public TypeInfo getType()
      Description copied from interface: Typed
      Returns the data type.
      Specified by:
      getType in interface Typed
      Specified by:
      getType in class Value
      Returns:
      the data type
    • getValueType

      public int getValueType()
      Description copied from class: Value
      Get the value type.
      Specified by:
      getValueType in class Value
      Returns:
      the value type
    • add

      public Value add(Value v)
      Description copied from class: Value
      Add a value and return the result.
      Overrides:
      add in class Value
      Parameters:
      v - the value to add
      Returns:
      the result
    • subtract

      public Value subtract(Value v)
      Description copied from class: Value
      Subtract a value and return the result.
      Overrides:
      subtract in class Value
      Parameters:
      v - the value to subtract
      Returns:
      the result
    • negate

      public Value negate()
      Description copied from class: Value
      Return -value if this value support arithmetic operations.
      Overrides:
      negate in class Value
      Returns:
      the negative
    • multiply

      public Value multiply(Value v)
      Description copied from class: Value
      Multiply with a value and return the result.
      Overrides:
      multiply in class Value
      Parameters:
      v - the value to multiply with
      Returns:
      the result
    • divide

      public Value divide(Value v, TypeInfo quotientType)
      Description copied from class: Value
      Divide by a value and return the result.
      Overrides:
      divide in class Value
      Parameters:
      v - the divisor
      quotientType - the type of quotient (used only to read precision and scale when applicable)
      Returns:
      the result
    • modulus

      public Value modulus(Value v)
      Description copied from class: Value
      Take the modulus with a value and return the result.
      Overrides:
      modulus in class Value
      Parameters:
      v - the value to take the modulus with
      Returns:
      the result
    • compareTypeSafe

      public int compareTypeSafe(Value o, CompareMode mode, CastDataProvider provider)
      Description copied from class: Value
      Compare this value against another value given that the values are of the same data type.
      Specified by:
      compareTypeSafe in class Value
      Parameters:
      o - the other value
      mode - the compare mode
      provider - the cast information provider
      Returns:
      0 if both values are equal, -1 if the other value is smaller, and 1 otherwise
    • getSignum

      public int getSignum()
      Overrides:
      getSignum in class Value
    • getBigDecimal

      public BigDecimal getBigDecimal()
      Overrides:
      getBigDecimal in class Value
    • getFloat

      public float getFloat()
      Description copied from class: Value
      Returns this value as a Java float value.
      Overrides:
      getFloat in class Value
      Returns:
      value
    • getDouble

      public double getDouble()
      Description copied from class: Value
      Returns this value as a Java double value.
      Overrides:
      getDouble in class Value
      Returns:
      value
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class Value
    • equals

      public boolean equals(Object other)
      Description copied from class: Value
      Check if the two values have the same hash code. No data conversion is made; this method returns false if the other object is not of the same class. For some values, compareTo may return 0 even if equals return false. Example: ValueDecimal 0.0 and 0.00.
      Specified by:
      equals in class Value
      Parameters:
      other - the other value
      Returns:
      true if they are equal
    • getMemory

      public int getMemory()
      Description copied from class: Value
      Get the memory used by this object.
      Overrides:
      getMemory in class Value
      Returns:
      the memory used in bytes
    • get

      public static ValueNumeric get(BigDecimal dec)
      Get or create a NUMERIC value for the given big decimal.
      Parameters:
      dec - the big decimal
      Returns:
      the value
    • getAnyScale

      public static ValueNumeric getAnyScale(BigDecimal dec)
      Get or create a NUMERIC value for the given big decimal with possibly negative scale. If scale is negative, it is normalized to 0.
      Parameters:
      dec - the big decimal
      Returns:
      the value
    • get

      public static ValueNumeric get(BigInteger bigInteger)
      Get or create a NUMERIC value for the given big integer.
      Parameters:
      bigInteger - the big integer
      Returns:
      the value
    • setScale

      public static BigDecimal setScale(BigDecimal bd, int scale)
      Set the scale of a BigDecimal value.
      Parameters:
      bd - the BigDecimal value
      scale - the new scale
      Returns:
      the scaled value