Class ValidationUtils

java.lang.Object
edu.ie3.datamodel.utils.validation.ValidationUtils
Direct Known Subclasses:
ConnectorValidationUtils, GraphicValidationUtils, GridContainerValidationUtils, MeasurementUnitValidationUtils, NodeValidationUtils, SystemParticipantValidationUtils, ThermalUnitValidationUtils

public class ValidationUtils extends Object
Basic Sanity validation tools for entities
  • Constructor Details

    • ValidationUtils

      protected ValidationUtils()
      Private Constructor as this class is not meant to be instantiated
  • Method Details

    • checkNotImplementedException

      protected static NotImplementedException checkNotImplementedException(Object obj)
      Creates a new NotImplementedException, 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

      public static void check(Object obj)
      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

      protected static void checkNonNull(Object obj, String expectedDescription)
      Checks, if the given object is null. If so, an InvalidEntityException is thrown.
      Parameters:
      obj - Object to check
      expectedDescription - 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 synoptic UnsafeEntityException
      Parameters:
      quantities - Array of quantities to check
      entity - 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 synoptic UnsafeEntityException
      Parameters:
      quantities - Array of quantities to check
      entity - 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 check
      entity - 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 synoptic UnsafeEntityException
      Parameters:
      quantities - Array of quantities to check
      entity - Unique entity holding the malformed quantities
      predicate - Predicate to detect the malformed quantities
      msg - Message prefix to use for the exception message: [msg]: [malformedQuantities]
    • distinctByKey

      public static <T> Predicate<T> distinctByKey(Function<? super T,?> keyExtractor)
      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

      protected static Optional<String> 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.
      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