Class ValidationUtils
java.lang.Object
edu.ie3.datamodel.utils.validation.ValidationUtils
- Direct Known Subclasses:
ConnectorValidationUtils,GraphicValidationUtils,GridContainerValidationUtils,MeasurementUnitValidationUtils,NodeValidationUtils,SystemParticipantValidationUtils,ThermalUnitValidationUtils
Basic Sanity validation tools for entities
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPrivate Constructor as this class is not meant to be instantiated -
Method Summary
Modifier and TypeMethodDescriptionstatic voidThis is a "distribution" method, that forwards the check request to specific implementations to fulfill the checking task, based on the class of the given object.checkForDuplicateUuids(Set<UniqueEntity> entities) Checks if the provided set of unique entities only contains elements with distinct UUIDs and either returns a string with duplicated UUIDs or an empty optional otherwise.protected static voidcheckNonNull(Object obj, String expectedDescription) Checks, if the given object is null.protected static NotImplementedExceptionCreates a newNotImplementedException, if there is no check available for the class of the given objectprotected static voiddetectMalformedQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity, Predicate<javax.measure.Quantity<?>> predicate, String msg) Goes through the provided quantities and reports those, that do fulfill the given predicate via synopticUnsafeEntityExceptionprotected static voiddetectNegativeQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity) Goes through the provided quantities and reports those, that have negative value via synopticUnsafeEntityExceptionprotected static voiddetectPositiveQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity) Goes through the provided quantities and reports those, that have positive value viaprotected static voiddetectZeroOrNegativeQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity) Goes through the provided quantities and reports those, that are zero or have negative value via synopticUnsafeEntityExceptionstatic <T> Predicate<T>distinctByKey(Function<? super T, ?> keyExtractor) Predicate that can be used to filter elements based on a given Function
-
Constructor Details
-
ValidationUtils
protected ValidationUtils()Private Constructor as this class is not meant to be instantiated
-
-
Method Details
-
checkNotImplementedException
Creates a newNotImplementedException, if there is no check available for the class of the given object- Parameters:
obj- Object, that cannot be checked- Returns:
- Exception with predefined error string
-
check
This is a "distribution" method, that forwards the check request to specific implementations to fulfill the checking task, based on the class of the given object.- Parameters:
obj- Object to check- Throws:
NotImplementedException- if an unknown class is handed in
-
checkNonNull
Checks, if the given object is null. If so, anInvalidEntityExceptionis thrown.- Parameters:
obj- Object to checkexpectedDescription- Further description, of what has been expected.
-
detectNegativeQuantities
protected static void detectNegativeQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity) Goes through the provided quantities and reports those, that have negative value via synopticUnsafeEntityException- Parameters:
quantities- Array of quantities to checkentity- Unique entity holding the malformed quantities
-
detectZeroOrNegativeQuantities
protected static void detectZeroOrNegativeQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity) Goes through the provided quantities and reports those, that are zero or have negative value via synopticUnsafeEntityException- Parameters:
quantities- Array of quantities to checkentity- Unique entity holding the malformed quantities
-
detectPositiveQuantities
protected static void detectPositiveQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity) Goes through the provided quantities and reports those, that have positive value via- Parameters:
quantities- Array of quantities to checkentity- Unique entity holding the malformed quantities
-
detectMalformedQuantities
protected static void detectMalformedQuantities(javax.measure.Quantity<?>[] quantities, UniqueEntity entity, Predicate<javax.measure.Quantity<?>> predicate, String msg) Goes through the provided quantities and reports those, that do fulfill the given predicate via synopticUnsafeEntityException- Parameters:
quantities- Array of quantities to checkentity- Unique entity holding the malformed quantitiespredicate- Predicate to detect the malformed quantitiesmsg- Message prefix to use for the exception message: [msg]: [malformedQuantities]
-
distinctByKey
Predicate that can be used to filter elements based on a given Function- Type Parameters:
T- the type of the returning predicate- Parameters:
keyExtractor- the function that should be used for the filter operations- Returns:
- the filter predicate that filters based on the provided function
-
checkForDuplicateUuids
Checks if the provided set of unique entities only contains elements with distinct UUIDs and either returns a string with duplicated UUIDs or an empty optional otherwise.- Parameters:
entities- the entities that should be checkd for UUID uniqueness- Returns:
- either a string wrapped in an optional with duplicate UUIDs or an empty optional
-