Package util
Class Util
- java.lang.Object
-
- util.Util
-
public final class Util extends Object
Collection of general static methods used across packages- Author:
- Christoph Schimeczek, Martin Klein, Marc Deissenroth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Util.MessagePair<X extends PointInTime,Y extends PointInTime>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
calcMedian(double... data)
Calculates median of given data usingDescriptiveStatistics
static void
ensureValidRange(double minValue, double maxValue)
Ensures that given minValue is smaller than or equal to given maxValuestatic ArrayList<Double>
linearInterpolation(double minValue, double maxValue, int steps)
Returns a newly created List of doubles, interpolating between given minimum and maximumstatic <X extends PointInTime,Y extends PointInTime>
HashMap<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 givenMessage
s for those that contain any of the two given types and extracts (removes) them from the given list.static <T extends de.dlr.gitlab.fame.communication.message.DataItem>
TremoveFirstMessageWithDataItem(Class<T> payload, List<de.dlr.gitlab.fame.communication.message.Message> messages)
Searches given list of messages for the given type of DataItem.
-
-
-
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 listmaxValue
- maximum value, if steps > 1 also included in the returned list, requires maxValue > minValuesteps
- 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 maxValuemaxValue
- 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 usingDescriptiveStatistics
- 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 formessages
- 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 PointInTime> HashMap<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 givenMessage
s for those that contain any of the two given types and extracts (removes) them from the given list. Then, matches the extracted messages toUtil.MessagePair
s with sameTimeStamp
.- Type Parameters:
X
- first type of PointInTime itemsY
- second type of PointInTime items- Parameters:
messages
- list of messages to be searched for those containing firstType or secondTypefirstType
- of PointInTime items to be extractedsecondType
- of PointInTime items to be extracted- Returns:
- Map of
Util.MessagePair
s indexed byTimeStamp
- Throws:
IllegalArgumentException
- ifTimeStamp
s 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
-
-