Class ContextVariableTypeConverter<T>

    • Constructor Detail

      • ContextVariableTypeConverter

        public ContextVariableTypeConverter​(Class<T> clazz,
                                            Function<Object,​T> fromObject,
                                            Function<T,​String> toPromptString,
                                            Function<String,​T> fromPromptString)
        Create a new context variable type converter.
        Parameters:
        clazz - the class of the type
        fromObject - a function to convert an object to the type
        toPromptString - a function to convert the type to a prompt string
        fromPromptString - a function to convert a prompt string to the type
      • ContextVariableTypeConverter

        public ContextVariableTypeConverter​(Class<T> clazz,
                                            Function<Object,​T> fromObject,
                                            Function<T,​String> toPromptString,
                                            Function<String,​T> fromPromptString,
                                            List<ContextVariableTypeConverter.Converter<T,​?>> toObjects)
        Create a new context variable type converter.
        Parameters:
        clazz - the class of the type
        fromObject - a function to convert an object to the type
        toPromptString - a function to convert the type to a prompt string
        fromPromptString - a function to convert a prompt string to the type
        toObjects - a list of converters to convert the type to other types
    • Method Detail

      • toObject

        @Nullable
        public <U> U toObject​(@Nullable
                              Object t,
                              Class<U> clazz)
        Use this converter to convert the object to the type of the context variable.
        Type Parameters:
        U - the type to convert to
        Parameters:
        t - the object to convert
        clazz - the class of the type to convert to
        Returns:
        the converted object
      • fromObject

        @Nullable
        public T fromObject​(@Nullable
                            Object s)
        Convert the object to the type of the context variable using the fromObject function provided to the constructor.
        Parameters:
        s - the object to convert
        Returns:
        the converted object
      • toPromptString

        public String toPromptString​(@Nullable
                                     T t)
        Convert the type to a prompt string using the toPromptString function provided to the constructor.
        Parameters:
        t - the type to convert
        Returns:
        the prompt string
      • fromPromptString

        @Nullable
        public T fromPromptString​(@Nullable
                                  String t)
        Convert the prompt string to the type using the fromPromptString function provided to the constructor.
        Parameters:
        t - the prompt string to convert
        Returns:
        the type
      • getType

        public Class<T> getType()
        Get the class of the type.
        Returns:
        the class of the type