Class Decimal

java.lang.Object
nz.org.riskscape.engine.types.SimpleType
nz.org.riskscape.engine.types.Decimal
All Implemented Interfaces:
TypeIO, TypeIOConstructor, Rangeable, Type, TypeConstructor

public class Decimal extends SimpleType implements Rangeable

Permissive Decimal type that will convert any Number in to a BigDecimal via Number.doubleValue(). It will also attempt to convert a String to an integer, using BigDecimal(String). Nulls are not allowed.

  • Field Details

    • TWO

      public static final BigDecimal TWO

      A constant value of two. Useful, and doesn't exist as a static member of BigDecimal already.

  • Constructor Details

    • Decimal

      public Decimal()
  • Method Details

    • coerce

      public Object coerce(Object value)
      Description copied from interface: Type

      Attempt to convert the given value in to one represented by this type.

      Specified by:
      coerce in interface Type
      Parameters:
      value - The value to coerce
      Returns:
      A value that conforms to this type
    • internalType

      public Class<?> internalType()
      Description copied from interface: Type

      The underlying java class used to represent this type.

      Specified by:
      internalType in interface Type
    • estimateSize

      public int estimateSize(Object entry)
      Description copied from interface: Type

      Estimate the number of bytes used to serialize the given value to an output stream.

      Specified by:
      estimateSize in interface Type
      Parameters:
      entry - the value of this type to measure. Must be of Type.internalType() or a ClassCastException is going to happen
      Returns:
      the estimated number of bytes, or zero if no estimation was possible.
    • toBytes

      public void toBytes(DataOutputStream os, Object toWrite) throws IOException
      Specified by:
      toBytes in interface Type
      Throws:
      IOException
    • fromBytes

      public Object fromBytes(DataInputStream in) throws IOException
      Specified by:
      fromBytes in interface Type
      Throws:
      IOException
    • read

      public Object read(ByteBuffer buffer)
      Description copied from interface: TypeIO

      Read a value from the given byte buffer

      Specified by:
      read in interface TypeIO
    • write

      public void write(ByteBuffer buffer, Object toWrite)
      Description copied from interface: TypeIO

      Write a value out to the given byte buffer

      Specified by:
      write in interface TypeIO