Package ru.objectsfill.service
Class ElementCreationService
java.lang.Object
ru.objectsfill.service.ElementCreationService
Service responsible for generating individual values or object instances based on field type.
Maintains two type registries:
containerBoxType— handlers for primitive/wrapper types (String, Integer, etc.)containerObjectType— handlers for complex object types (Enum, custom types)
createInstance(java.lang.Class<T>, ru.objectsfill.object_param.Fill).-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPackage path scanned at runtime for user-defined container implementations generated by the annotation processor. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new service instance and initializes the type registries by scanning for user-defined container implementations and adding default mappings. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcreateInstance(Class<T> vClass, Fill fill) Creates a new instance of the provided class type using reflection.<T> Stream<T>fillCollectionStream(Field field, Fill fill) Fills a collection stream based on the provided field and Fill object.static <T> Optional<T>findClassInContainer(Class<?> fieldType, Map<Class<?>, T> container) Finds the value associated with the provided field type in the given container map.generateSingleValue(Class<?> fieldType, Fill fill) Generates a single value based on the provided field type and Fill object.
-
Field Details
-
DEFAULT_LOCAL_CLASS_CREATION_PATH
Package path scanned at runtime for user-defined container implementations generated by the annotation processor.- See Also:
-
-
Constructor Details
-
ElementCreationService
public ElementCreationService()Constructs a new service instance and initializes the type registries by scanning for user-defined container implementations and adding default mappings.
-
-
Method Details
-
generateSingleValue
Generates a single value based on the provided field type and Fill object. First, it attempts to find a BoxTypeFill implementation for the field type in the containerBoxType. If found, it delegates the generation to that implementation. If not found, it attempts to find an ObjectTypeFill implementation for the field type in the containerObjectType. If found, it delegates the generation to that implementation. If no suitable implementation is found, it creates a new instance of the field type using createInstance() method.- Parameters:
fieldType- The type of the field for which the value is being generated.fill- The Fill object containing the necessary information for generation.- Returns:
- The generated single value.
-
fillCollectionStream
Fills a collection stream based on the provided field and Fill object. Extracts the generic collection type from the field's ParameterizedType and attempts to generate a collection stream based on that type using generateCollectionByClassType() method.- Type Parameters:
T- The type of elements in the collection.- Parameters:
field- The field for which the collection stream is being filled.fill- The Fill object containing the necessary information for generation.- Returns:
- A stream of collection elements.
-
findClassInContainer
Finds the value associated with the provided field type in the given container map. It first attempts to find an exact match for the field type in the map. If found, it returns the corresponding value. If not found, it searches for a key in the map that is assignable from the field type. If found, it returns the value associated with that key.- Type Parameters:
T- The type of value to retrieve.- Parameters:
fieldType- The type of the field for which a value is being searched.container- The container map in which to search for the value.- Returns:
- An optional containing the value if found, or empty if not found.
-
createInstance
Creates a new instance of the provided class type using reflection. The created instance is assigned a Fill object with decreased depth, and the fill() method is called to populate the fields of the instance.- Type Parameters:
T- The type of the instance being created.- Parameters:
vClass- The class type of the instance being created.fill- The Fill object containing the necessary information for generation.- Returns:
- The created instance, or null if an error occurred during instantiation.
-