Class FunctionType

java.lang.Object
nz.org.riskscape.engine.types.FunctionType
All Implemented Interfaces:
Type

public class FunctionType extends Object implements Type

Type information for a first-class function being stored in a tuple (as an UntypedFunction)

Does not support any type io or coercion operations

  • Field Details

    • WILD

      public static final FunctionType WILD

      Wildcard style function type object, typically used with RealizableFunctions to say that some kind of FunctionType will be accepted, or in type problems to report a broad mismatch, e.g. we wanted a function type, but you gave us a list

    • VISITOR_META_RETURNS

      public static final Object VISITOR_META_RETURNS
  • Constructor Details

    • FunctionType

      public FunctionType(List<Type> argumentTypes, Type returnType)

      Construct a FunctionType with the given function signature of argumentTypes and returnType. This should mean that any covariant arguments can be safely applied to a function that has this type, and that returned values will be covariant to the return type.

  • Method Details

    • fromFunction

      public static FunctionType fromFunction(RiskscapeFunction function)
    • coerce

      public Object coerce(Object value) throws CoercionException
      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
      Throws:
      CoercionException - if the given object can not be converted to something represented by 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
    • asStruct

      public Struct asStruct()
      Specified by:
      asStruct in interface Type
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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
    • visit

      public <T, U> U visit(TypeVisitor<T,U> tv, T data)
      Description copied from interface: Type

      Type specific visiting logic. Types must decide whether they are atomic or compound and call the relevant method on TypeVisitor. It's up to each compound type to decide how they want to structure their children, e.g. order, metadata, and what's considered a child or not.

      Specified by:
      visit in interface Type
    • getArgumentTypes

      public List<Type> getArgumentTypes()
    • getReturnType

      public Type getReturnType()