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
      • matchMessagesByTime

        public static <X extends PointInTime,​Y extends PointInTimeHashMap<de.dlr.gitlab.fame.time.TimeStamp,​Util.MessagePair<X,​Y>> matchMessagesByTime​(ArrayList<de.dlr.gitlab.fame.communication.message.Message> messages,
                                                                                                                                                                           Class<X> firstType,
                                                                                                                                                                           Class<Y> secondType)
        Searches given Messages for those that contain any of the two given types and extracts (removes) them from the given list. Then, matches the extracted messages to Util.MessagePairs with same TimeStamp.
        Type Parameters:
        X - first type of PointInTime items
        Y - second type of PointInTime items
        Parameters:
        messages - list of messages to be searched for those containing firstType or secondType
        firstType - of PointInTime items to be extracted
        secondType - of PointInTime items to be extracted
        Returns:
        Map of Util.MessagePairs indexed by TimeStamp
        Throws:
        IllegalArgumentException - if TimeStamps are not unique among the messages of each type, if number of messages for both types are not equal, if times for both types do not exactly match