Class ContextVariableTypes


  • public class ContextVariableTypes
    extends Object
    A collection of context variable types, with converters to convert objects to the types.
    • Constructor Detail

      • ContextVariableTypes

        public ContextVariableTypes​(List<ContextVariableTypeConverter<?>> converters)
        Create a new collection of context variable types.
        Parameters:
        converters - The converters to use to convert objects to the types.
      • ContextVariableTypes

        public ContextVariableTypes()
        Create a new collection of context variable types.
      • ContextVariableTypes

        public ContextVariableTypes​(ContextVariableTypes contextVariableTypes)
        Create a new collection of context variable types.
        Parameters:
        contextVariableTypes - The collection of context variable types to copy.
    • Method Detail

      • getGlobalVariableTypeForClass

        public static <T> ContextVariableType<T> getGlobalVariableTypeForClass​(Class<T> aClass)
        Get the global context variable type for the given class.
        Type Parameters:
        T - The type of the context variable.
        Parameters:
        aClass - The class to get the context variable type for.
        Returns:
        The context variable type for the given class.
        See Also:
        addGlobalConverter(ContextVariableTypeConverter)
      • convert

        @Nullable
        public static <T> T convert​(@Nullable
                                    Object s,
                                    Class<T> clazz)
        Convert the given object to the given class, if possible.
        Type Parameters:
        T - the type to convert to
        Parameters:
        s - the object to convert
        clazz - the class of the type to convert to
        Returns:
        the converted object, or null if the object cannot be converted
      • putConverter

        public <T> void putConverter​(ContextVariableTypeConverter<T> contextVariableTypeConverter)
        Add a converter to this ContextVariableTypes instance.
        Type Parameters:
        T - The type of the context variable.
        Parameters:
        contextVariableTypeConverter - the converter to add.
      • getVariableTypeForClass

        public <T> ContextVariableType<T> getVariableTypeForClass​(Class<T> aClass)
        Get the context variable type for the given class.
        Type Parameters:
        T - The type of the context variable.
        Parameters:
        aClass - The class to get the context variable type for.
        Returns:
        The context variable type for the given class
        Throws:
        SKException - if the type cannot be found.
      • getVariableTypeForSuperClass

        public <T> ContextVariableType<T> getVariableTypeForSuperClass​(Class<T> aClass)
        Get the context variable type for the given class or for a type that is assignable from the given class. its super class.
        Type Parameters:
        T - The type of the context variable.
        Parameters:
        aClass - The class to get the context variable type for.
        Returns:
        The context variable type for the given class.
        Throws:
        SKException - if the type cannot be found.
      • putConverters

        public void putConverters​(ContextVariableTypes contextVariableTypes)
        Add all the converters from the given collection to this collection.
        Parameters:
        contextVariableTypes - The collection of converters to add.
      • contextVariableOf

        public <T> ContextVariable<T> contextVariableOf​(T value)
        Create a context variable of the given value.
        Type Parameters:
        T - The type of the context variable.
        Parameters:
        value - The value to create a context variable of.
        Returns:
        The context variable of the given value.