Class ContextVariableTypes
- java.lang.Object
-
- com.microsoft.semantickernel.contextvariables.ContextVariableTypes
-
public class ContextVariableTypes extends Object
A collection of context variable types, with converters to convert objects to the types.
-
-
Constructor Summary
Constructors Constructor Description ContextVariableTypes()Create a new collection of context variable types.ContextVariableTypes(ContextVariableTypes contextVariableTypes)Create a new collection of context variable types.ContextVariableTypes(List<ContextVariableTypeConverter<?>> converters)Create a new collection of context variable types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddGlobalConverter(ContextVariableTypeConverter<?> converter)Add a converter to the global collection of context variable type converters.<T> ContextVariable<T>contextVariableOf(T value)Create a context variable of the given value.static <T> Tconvert(Object s, Class<T> clazz)Convert the given object to the given class, if possible.static ContextVariableTypesgetGlobalTypes()Get the globally available collectors, which is the default collection of context variable types and those that have been added withaddGlobalConverter(ContextVariableTypeConverter).static <T> ContextVariableType<T>getGlobalVariableTypeForClass(Class<T> aClass)Get the global context variable type for the given class.<T> ContextVariableType<T>getVariableTypeForClass(Class<T> aClass)Get the context variable type for the given class.<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.<T> voidputConverter(ContextVariableTypeConverter<T> contextVariableTypeConverter)Add a converter to thisContextVariableTypesinstance.voidputConverters(ContextVariableTypes contextVariableTypes)Add all the converters from the given collection to this collection.
-
-
-
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
-
getGlobalTypes
public static ContextVariableTypes getGlobalTypes()
Get the globally available collectors, which is the default collection of context variable types and those that have been added withaddGlobalConverter(ContextVariableTypeConverter).- Returns:
- The collection of globally available converters.
-
addGlobalConverter
public static void addGlobalConverter(ContextVariableTypeConverter<?> converter)
Add a converter to the global collection of context variable type converters.- Parameters:
converter- The converter to add.- See Also:
getGlobalVariableTypeForClass(Class)
-
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 convertclazz- the class of the type to convert to- Returns:
- the converted object, or
nullif the object cannot be converted
-
putConverter
public <T> void putConverter(ContextVariableTypeConverter<T> contextVariableTypeConverter)
Add a converter to thisContextVariableTypesinstance.- 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.
-
-