Package com.storedobject.iot
Interface ConsumptionCalculator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A functional interface for calculating consumption values over a specified time period.
The calculation can be customized using various factory methods.
- Author:
- Syam
-
Method Summary
Modifier and TypeMethodDescriptionComputes a value based on the specified resource, unit identifier, and time range.static ConsumptionCalculator
Creates a ConsumptionCalculator instance to compute the difference in values of a specific variable for a given data class between the specified time range.static ConsumptionCalculator
Creates a ConsumptionCalculator instance that computes consumption based on state changes of the specified variable within the provided data class.static ConsumptionCalculator
Creates a ConsumptionCalculator instance with a specified multiplier to adjust the computed value.
-
Method Details
-
compute
Computes a value based on the specified resource, unit identifier, and time range. The calculation logic can be implemented using the specific details provided.- Parameters:
resource
- the resource identifier used in the computationunitId
- the unique identifier for the unit on which computation is performedfrom
- the starting timestamp for the computation periodto
- the ending timestamp for the computation period- Returns:
- a Double representing the calculated value, or null if the computation fails or is not applicable
-
create
Creates a ConsumptionCalculator instance to compute the difference in values of a specific variable for a given data class between the specified time range.- Parameters:
dataClass
- the class type of the data from which values are retrievedvariable
- the name of the variable to compute the difference for- Returns:
- a ConsumptionCalculator instance configured for the specified data class and variable
-
create
static ConsumptionCalculator create(Class<? extends Data> dataClass, String variable, double multiplier) Creates a ConsumptionCalculator instance with a specified multiplier to adjust the computed value. The created calculator computes the difference of a given variable for the specified data class, then multiplies the result by the provided multiplier.- Parameters:
dataClass
- the class type extending Data, representing the data source for the computationvariable
- the name of the variable to be used in the computationmultiplier
- the factor by which the computed difference is multiplied- Returns:
- a ConsumptionCalculator instance configured with the specified parameters
-
create
static ConsumptionCalculator create(Class<? extends Data> dataClass, String variable, boolean toTrue, double multiplier) Creates a ConsumptionCalculator instance that computes consumption based on state changes of the specified variable within the provided data class. The calculation can be customized using the boolean condition and multiplier.- Parameters:
dataClass
- the class type of the data being used for computationvariable
- the name of the variable used for state change computationtoTrue
- the condition for computing state changes; if true, only changes to "true" are consideredmultiplier
- the value by which the computed state changes will be multiplied- Returns:
- a ConsumptionCalculator instance that computes values based on state changes in the data
-