All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.synerset.hvacengine.common.Validators Maven / Gradle / Ivy

Go to download

HVAC|Engine is a comprehensive library for calculating moist air properties, including crucial thermodynamic processes such as heating, dry cooling, real cooling with condensate discharge, mixing single or multiple air streams, and more. Immutable, thread-safe, very accurate.

There is a newer version: 1.2.0
Show newest version
package com.synerset.hvacengine.common;

import com.synerset.hvacengine.common.exceptions.InvalidArgumentException;
import com.synerset.hvacengine.common.exceptions.MissingArgumentException;
import com.synerset.unitility.unitsystem.PhysicalQuantity;
import com.synerset.unitility.unitsystem.Unit;
import com.synerset.unitility.unitsystem.thermodynamic.Pressure;
import com.synerset.unitility.unitsystem.thermodynamic.Temperature;

import java.util.Collection;
import java.util.Objects;

public final class Validators {

    private Validators() {
    }

    public static void requireNotNull(Object object) {
        if (Objects.isNull(object)) {
            throw new MissingArgumentException("Argument cannot be null.");
        }
    }

    public static void requireNotEmpty(Collection collection) {
        if (Objects.isNull(collection) || collection.isEmpty()) {
            throw new MissingArgumentException("Collection cannot be null and not empty.");
        }
    }

    public static  void requireAboveLowerBound(PhysicalQuantity quantityToCheck, PhysicalQuantity lowerBoundLimit) {
        if (quantityToCheck.isEqualOrLowerThan(lowerBoundLimit)) {
            throw new InvalidArgumentException(String.format("Lower bound limit exceeded: Quantity: %s, Limit: %s", quantityToCheck, lowerBoundLimit));
        }
    }

    public static  void requireBelowUpperBound(PhysicalQuantity quantityToCheck, PhysicalQuantity upperBoundLimit) {
        if (quantityToCheck.isEqualOrGreaterThan(upperBoundLimit)) {
            throw new InvalidArgumentException(String.format("Upper bound limit exceeded: Quantity: %s, Limit: %s", quantityToCheck, upperBoundLimit));
        }
    }

    public static  void requireBetweenBounds(PhysicalQuantity quantityToCheck, PhysicalQuantity lowerBoundLimit, PhysicalQuantity upperBoundLimit) {
        requireAboveLowerBound(quantityToCheck, lowerBoundLimit);
        requireBelowUpperBound(quantityToCheck, upperBoundLimit);
    }

    public static  void requireAboveLowerBoundInclusive(PhysicalQuantity quantityToCheck, PhysicalQuantity lowerBoundLimit) {
        if (quantityToCheck.isLowerThan(lowerBoundLimit)) {
            throw new InvalidArgumentException(String.format("Lower bound limit reached or exceeded: Quantity: %s, Limit: %s", quantityToCheck, lowerBoundLimit));
        }
    }

    public static  void requireBelowUpperBoundInclusive(PhysicalQuantity quantityToCheck, PhysicalQuantity upperBoundLimit) {
        if (quantityToCheck.isGreaterThan(upperBoundLimit)) {
            throw new InvalidArgumentException(String.format("Upper bound limit reached or exceeded: Quantity: %s, Limit: %s", quantityToCheck, upperBoundLimit));
        }
    }

    public static  void requireBetweenBoundsInclusive(PhysicalQuantity quantityToCheck, PhysicalQuantity lowerBoundLimit, PhysicalQuantity upperBoundLimit) {
        requireAboveLowerBoundInclusive(quantityToCheck, lowerBoundLimit);
        requireBelowUpperBoundInclusive(quantityToCheck, upperBoundLimit);
    }

    public static void requireValidSaturationPressure(Pressure saturationPressure, Pressure humidAirAbsolutePressure, Temperature temperature) {
        if (saturationPressure.isEqualOrGreaterThan(humidAirAbsolutePressure)) {
            throw new InvalidArgumentException(
                    String.format("Water vapour saturation pressure exceeds humid air absolute pressure. Calculations are not possible. " +
                                    " Psat=%s, Pabs=%s, Temp=%s",
                            saturationPressure, humidAirAbsolutePressure, temperature));
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy