Class Utility
- java.lang.Object
-
- org.palladiosimulator.edp2.distancemetrics.util.Utility
-
public class Utility extends Object
This utility class contains functions that are needed by the distance metric algorithms.
-
-
Field Summary
Fields Modifier and Type Field Description static double
DELTA
The delta value, that should be used for calculations with numerical values, e.g.
-
Constructor Summary
Constructors Constructor Description Utility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
compareEquals(double v1, double v2)
Compares two values if they are equal in respect of a delta value to avoid issues with floating point inaccuracy.static double
euclid(double v1, double v2)
Calculates the euclidean distance of two values.static org.jscience.physics.amount.Amount<? extends javax.measure.quantity.Quantity>
euclid(org.jscience.physics.amount.Amount<?> amount, org.jscience.physics.amount.Amount<?> amount2)
Calculates the euclidean distance of two values.static javax.measure.unit.Unit<javax.measure.quantity.Quantity>
getBaseTimeUnit(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Returns the time unit of a TupleMeasurement stream.static javax.measure.unit.Unit<javax.measure.quantity.Quantity>
getBaseValueUnit(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Returns the value unit of a TupleMeasurement stream.static void
legalStreamComparison(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> s1, IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> s2)
Checks, if streams contain the same metric and throws an IllegalArgumentException, if it's not the case.static double
linearInterpolation(double[] x, double[] y, double xi)
x usually contains the time values and y usually contains the measured values which were measured at the time which is stored in x.static void
parametersAllowed(int numOfElements1, int numOfElements2)
This implementation uses a Java 2D array for computation which can only fit Integer.MAX_VALUE which also limits the number of elements to Integer.MAX_VALUE for each measurement.static <U extends javax.measure.quantity.Quantity>
org.jscience.physics.amount.Amount<U>quantityToAmount(javax.measure.Measure<?,U> measure)
Converts Measure unit to an Amount unit.static org.jscience.physics.amount.Amount<?>[]
streamToArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to an array of type Amount>.static double[]
streamToDoubleArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to a double array and converts the values with the base unit of the stream.static org.palladiosimulator.measurementframework.TupleMeasurement[]
streamToTupleArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to an array of type TupleMeasurement.static TupleWrapper[]
streamToTupleWrapperArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to an array of type TupleWrapper.
-
-
-
Field Detail
-
DELTA
public static final double DELTA
The delta value, that should be used for calculations with numerical values, e.g. comparison of two doubles.- See Also:
- Constant Field Values
-
-
Method Detail
-
legalStreamComparison
public static void legalStreamComparison(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> s1, IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> s2)
Checks, if streams contain the same metric and throws an IllegalArgumentException, if it's not the case.- Parameters:
s1
- First stream of the metric, that should be compared.s2
- Second stream of the metric, that should be compared.
-
getBaseTimeUnit
public static javax.measure.unit.Unit<javax.measure.quantity.Quantity> getBaseTimeUnit(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Returns the time unit of a TupleMeasurement stream.- Parameters:
stream
- The stream the unit should be taken from.- Returns:
- Returns the unit taken from the metric description of the stream.
-
getBaseValueUnit
public static javax.measure.unit.Unit<javax.measure.quantity.Quantity> getBaseValueUnit(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Returns the value unit of a TupleMeasurement stream.- Parameters:
stream
- The stream the unit should be taken from.- Returns:
- Returns the unit taken from the metric description of the stream.
-
compareEquals
public static boolean compareEquals(double v1, double v2)
Compares two values if they are equal in respect of a delta value to avoid issues with floating point inaccuracy.- Parameters:
v1
- First value to compare.v2
- Second value to compare.- Returns:
- True, if absolute difference is smaller or equal the delta value. False otherwise.
-
quantityToAmount
public static <U extends javax.measure.quantity.Quantity> org.jscience.physics.amount.Amount<U> quantityToAmount(javax.measure.Measure<?,U> measure)
Converts Measure unit to an Amount unit.- Type Parameters:
U
- Type of unit (extends Quantity).- Parameters:
measure
- The Measure to be translated into an Amount value.- Returns:
- Returns a converted Amount unit.
-
euclid
public static double euclid(double v1, double v2)
Calculates the euclidean distance of two values.- Parameters:
v1
- First value to calculate the euclidean distance of.v2
- Second value to calculate the euclidean distance of.- Returns:
- The euclidean distance of the two given values.
-
euclid
public static org.jscience.physics.amount.Amount<? extends javax.measure.quantity.Quantity> euclid(org.jscience.physics.amount.Amount<?> amount, org.jscience.physics.amount.Amount<?> amount2)
Calculates the euclidean distance of two values.- Parameters:
amount
- First value to calculate the euclidean distance of.amount2
- Second value to calculate the euclidean distance of.- Returns:
- The euclidean distance of the two given values.
-
streamToArray
public static org.jscience.physics.amount.Amount<?>[] streamToArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to an array of type Amount>.- Parameters:
stream
- The stream to be translated into an array.- Returns:
- Returns the elements of the stream as an array.
-
streamToTupleWrapperArray
public static TupleWrapper[] streamToTupleWrapperArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to an array of type TupleWrapper.- Parameters:
stream
- The stream to be translated into an array.- Returns:
- Returns the elements of the stream as an array.
-
streamToDoubleArray
public static double[] streamToDoubleArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to a double array and converts the values with the base unit of the stream.- Parameters:
stream
- The stream to be translated into an array.- Returns:
- Returns the measured values of the stream as an array. Time values will be dismissed.
-
streamToTupleArray
public static org.palladiosimulator.measurementframework.TupleMeasurement[] streamToTupleArray(IDataStream<org.palladiosimulator.measurementframework.TupleMeasurement> stream)
Converts the given stream to an array of type TupleMeasurement.- Parameters:
stream
- The stream to be translated into an array.- Returns:
- Returns the elements of the stream as an array of TupleMeasurement elements.
-
parametersAllowed
public static void parametersAllowed(int numOfElements1, int numOfElements2)
This implementation uses a Java 2D array for computation which can only fit Integer.MAX_VALUE which also limits the number of elements to Integer.MAX_VALUE for each measurement.- Parameters:
numOfElements1
- Number of elements of the first measurement.numOfElements2
- Number of elements of the second measurement.
-
linearInterpolation
public static double linearInterpolation(double[] x, double[] y, double xi)
x usually contains the time values and y usually contains the measured values which were measured at the time which is stored in x. e.g. at time x[0] the value y[0] was measured.- Parameters:
x
- Values on the x-axis.y
- The corresponding f(x)=y values.xi
- Usually the time value of the current OTHER measurement, at which the interpolation should be applied.- Returns:
- Returns the interpolated value at the position xi.
-
-