Class MathOperationsHelper

java.lang.Object
org.sentrysoftware.metricshub.engine.strategy.utils.MathOperationsHelper

public class MathOperationsHelper extends Object
The MathOperationsHelper class provides utility methods for performing basic mathematical operations, including subtraction, division, multiplication, rate calculation, and finding the minimum of two operands. The class includes methods to handle potential edge cases, such as division by zero or suspicious negative results. Logging statements are used to provide additional information in case of unexpected scenarios.
  • Constructor Details

    • MathOperationsHelper

      public MathOperationsHelper()
  • Method Details

    • subtract

      public static Double subtract(String metricName, Double minuend, Double subtrahend, String hostname)
      Performs a subtraction arithmetic operation.
      Parameters:
      metricName - The name of the metric.
      minuend - Minuend of the subtraction.
      subtrahend - Subtrahend of the subtraction.
      hostname - Current hostname used for logging only.
      Returns:
      The result of the subtraction operation, or null if any operand is null.
    • divide

      public static Double divide(String metricName, Double dividend, Double divisor, String hostname)
      Performs a division arithmetic operation.
      Parameters:
      metricName - The metric for the division operation.
      dividend - The dividend to use.
      divisor - The divisor to use.
      hostname - Current hostname used for logging only.
      Returns:
      The result of the division operation, or null if any operand is null or division by zero occurs.
    • multiply

      public static Double multiply(String metricName, Double multiplier, Double multiplicand, String hostname)
      Performs a multiplication arithmetic operation.
      Parameters:
      metricName - The name of the metric for the multiplication operation.
      multiplier - The multiplier to use.
      multiplicand - The multiplicand to use.
      hostname - Current hostname used for logging only.
      Returns:
      The result of the multiplication operation, or null if any operand is null.
    • rate

      public static Double rate(String metricName, Double value, Double previousValue, Double collectTime, Double previousCollectTime, String hostname)
      Computes a rate using the formula (value - previousValue) / (collectTime - previousCollectTime).
      Parameters:
      metricName - The metric name for rate calculation.
      value - The value from the current collect.
      previousValue - The value from the previous collect.
      collectTime - The time of the current collect.
      previousCollectTime - The time of the previous collect.
      hostname - Current hostname used for logging only.
      Returns:
      The computed rate, or null if any operand is null or division by zero occurs.
    • min

      public static Double min(Double operandOne, Double operandTwo)
      Computes the minimum between two Double operands. If one of the operands is null, returns the other operand.
      Parameters:
      operandOne - The first operand.
      operandTwo - The second operand.
      Returns:
      The minimum value between the operands, or the non-null operand if the other is null.