Package edu.ie3.datamodel.io.factory
Class Factory<C,D extends FactoryData,R>
java.lang.Object
edu.ie3.datamodel.io.factory.Factory<C,D,R>
- Type Parameters:
C
- Type of the intended target class.D
- Type of the "flat" information.R
- Type of the intended return type (might differ slightly from target class (cf.TimeBasedValueFactory
)).
- Direct Known Subclasses:
EntityFactory
,IdCoordinateFactory
,TimeBasedValueFactory
Abstract factory class, that is able to transfer specific "flat" information in to actual model
class instances.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract R
buildModel
(D data) Builds model with data from givenFactoryData
object.Expands a set of attributes with further attributes.Builds entity with data from given EntityData object after doing all kinds of checks on the dataReturns list of sets of attribute names that the entity requires to be built.protected static StringBuilder
getFieldsString
(Set<String>... fieldSets) Creates a new set of attribute names from given list of attributes.protected int
validateParameters
(D data, Set<String>... fieldSets) Validates the factory specific constructor parameters in two ways.
-
Field Details
-
log
public static final org.slf4j.Logger log
-
-
Constructor Details
-
Factory
-
-
Method Details
-
getSupportedClasses
-
get
Builds entity with data from given EntityData object after doing all kinds of checks on the data- Parameters:
data
- EntityData (or subclass) containing the data- Returns:
- An entity wrapped in Option if successful, an empty option otherwise
-
buildModel
Builds model with data from givenFactoryData
object. ThrowsFactoryException
if something goes wrong.- Parameters:
data
-FactoryData
(or subclass) containing the data- Returns:
- model created from data
- Throws:
FactoryException
- if the model cannot be build
-
getFields
Returns list of sets of attribute names that the entity requires to be built. At least one of these sets needs to be delivered for entity creation to be successful.- Parameters:
data
- EntityData (or subclass) containing the data- Returns:
- list of possible attribute sets
-
validateParameters
Validates the factory specific constructor parameters in two ways. 1) the biggest set of the provided field sets is compared against fields the class implements. If this test passes then we know for sure that the field names at least in the biggest constructor are equal to the provided factory strings 2) if 1) passes, the provided entity data (which is equal to the data e.g. read from the outside) is compared to all available constructor parameters provided by the fieldSets Array. If we find exactly one constructor, that matches the field names we can proceed. Otherwise a detailed exception message is thrown.- Parameters:
data
- the entity containing at least the entity class as well a mapping of the provided field name strings to its value (e.g. a headline of a csv to column values)fieldSets
- a set containing all available constructor combinations as field names- Returns:
- the index of the set in the fieldSets array that fits the provided entity data
-
getFieldsString
-
newSet
Creates a new set of attribute names from given list of attributes. This method should always be used when returning attribute sets, i.e. throughgetFields(FactoryData)
.- Parameters:
attributes
- attribute names- Returns:
- new set exactly containing attribute names
-
expandSet
Expands a set of attributes with further attributes. This method should always be used when returning attribute sets, i.e. through getting the needed fields. The set maintains a lexicographic order, that is case-insensitive.- Parameters:
attributeSet
- set of attributes to expandmore
- attribute names to expand given set with- Returns:
- new set exactly containing given attribute set plus additional attributes
-