Package util

Class Util


  • public final class Util
    extends Object
    Collection of general static methods used across packages
    Author:
    Christoph Schimeczek, Martin Klein, Marc Deissenroth
    • Method Detail

      • linearInterpolation

        public static ArrayList<Double> linearInterpolation​(double minValue,
                                                            double maxValue,
                                                            int steps)
        Returns a newly created List of doubles, interpolating between given minimum and maximum
        Parameters:
        minValue - minimum value, if steps > 1 also included in the returned list
        maxValue - maximum value, if steps > 1 also included in the returned list, requires maxValue > minValue
        steps - integer number of interpolation steps [0..]
        Returns:
        a list of interpolated values; in case of
        • steps = 0: an empty list
        • steps = 1: average of minValue and maxValue
        • steps = 2: minValue and maxValue
        • steps > 2: minValue, maxValue + (steps - 2) intermediate values, splitting the interval in (steps - 1) equidistant segments
        Throws:
        IllegalArgumentException - if steps are negative or if minValue > maxValue
      • ensureValidRange

        public static void ensureValidRange​(double minValue,
                                            double maxValue)
        Ensures that given minValue is smaller than or equal to given maxValue
        Parameters:
        minValue - must be smaller than or equal to maxValue
        maxValue - must be larger than or equal to minValue
        Throws:
        IllegalArgumentException - in case minValue > maxValue
      • calcMedian

        public static double calcMedian​(double... data)
        Calculates median of given data using DescriptiveStatistics
        Parameters:
        data - to be analysed
        Returns:
        median of the given data or NaN if given data was null or empty
      • removeFirstMessageWithDataItem

        public static <T extends de.dlr.gitlab.fame.communication.message.DataItem> T removeFirstMessageWithDataItem​(Class<T> payload,
                                                                                                                     List<de.dlr.gitlab.fame.communication.message.Message> messages)
        Searches given list of messages for the given type of DataItem. If at least one such message is found: Removes first message with that payload from given list and returns the payload. Further messages with that payload still reside in the message list. If no message with matching payload is found: returns null.
        Type Parameters:
        T - type of searched and returned DataItem
        Parameters:
        payload - class type of DataItem to search for
        messages - list of messages to search; message with found data item is removed
        Returns:
        first matching DataItem found