Class OfUnit

java.lang.Object
nz.org.riskscape.engine.types.OfUnit
All Implemented Interfaces:
Type, WrappingType

public class OfUnit extends Object implements Type, WrappingType

Wraps a type adding some extra unit metadata, e.g. adding the word "metre" to a decimal

  • Constructor Details

    • OfUnit

      public OfUnit(String unit, Type underlying)
  • 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
    • getUnit

      public String getUnit()
    • getUnderlyingType

      public Type getUnderlyingType()
      Specified by:
      getUnderlyingType in interface WrappingType
      Returns:
      the type that we immediately wrap. Used by Type.getUnwrappedType() to descend through all wrapped Type to find the first unwrapped one.