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,
                                            ContextVariableTypeConverter.ToPromptStringFunction<T> 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​(ContextVariableTypes types,
                              @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
                                     ContextVariableTypes types,
                                     @Nullable
                                     T t)
        Convert the type to a prompt string using the toPromptString function provided to the constructor.
        Parameters:
        types - the context variable types, if null the global types are used
        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
      • builder

        public static <T> ContextVariableTypeConverter.Builder<T> builder​(Class<T> clazz)
        Create a new builder for a context variable type converter.
        Type Parameters:
        T - the type of the context variable
        Parameters:
        clazz - the class of the type
        Returns:
        the builder
      • escapeXmlString

        @Nullable
        public static String escapeXmlString​(@Nullable
                                             String value)
        To be used when toPromptString is called
        Parameters:
        value - the value to escape
        Returns:
        the escaped value