All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.highmobility.autoapi.Usage Maven / Gradle / Ivy

/*
 * The MIT License
 * 
 * Copyright (c) 2014- High-Mobility GmbH (https://high-mobility.com)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.highmobility.autoapi;

import com.highmobility.autoapi.property.Property;
import com.highmobility.autoapi.value.DistanceOverTime;
import com.highmobility.autoapi.value.DrivingMode;
import com.highmobility.autoapi.value.DrivingModeActivationPeriod;
import com.highmobility.autoapi.value.DrivingModeEnergyConsumption;
import com.highmobility.autoapi.value.Grade;
import com.highmobility.autoapi.value.measurement.Duration;
import com.highmobility.autoapi.value.measurement.Energy;
import com.highmobility.autoapi.value.measurement.EnergyEfficiency;
import com.highmobility.autoapi.value.measurement.FuelEfficiency;
import com.highmobility.autoapi.value.measurement.Length;
import com.highmobility.autoapi.value.measurement.Speed;
import com.highmobility.autoapi.value.measurement.Volume;
import com.highmobility.value.Bytes;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.annotation.Nullable;

/**
 * The Usage capability
 */
public class Usage {
    public static final int IDENTIFIER = Identifier.USAGE;

    public static final byte PROPERTY_AVERAGE_WEEKLY_DISTANCE = 0x01;
    public static final byte PROPERTY_AVERAGE_WEEKLY_DISTANCE_LONG_RUN = 0x02;
    public static final byte PROPERTY_ACCELERATION_EVALUATION = 0x03;
    public static final byte PROPERTY_DRIVING_STYLE_EVALUATION = 0x04;
    public static final byte PROPERTY_DRIVING_MODES_ACTIVATION_PERIODS = 0x05;
    public static final byte PROPERTY_DRIVING_MODES_ENERGY_CONSUMPTIONS = 0x06;
    public static final byte PROPERTY_LAST_TRIP_ENERGY_CONSUMPTION = 0x07;
    public static final byte PROPERTY_LAST_TRIP_FUEL_CONSUMPTION = 0x08;
    public static final byte PROPERTY_MILEAGE_AFTER_LAST_TRIP = 0x09;
    public static final byte PROPERTY_LAST_TRIP_ELECTRIC_PORTION = 0x0a;
    public static final byte PROPERTY_LAST_TRIP_AVERAGE_ENERGY_RECUPERATION = 0x0b;
    public static final byte PROPERTY_LAST_TRIP_BATTERY_REMAINING = 0x0c;
    public static final byte PROPERTY_LAST_TRIP_DATE = 0x0d;
    public static final byte PROPERTY_AVERAGE_FUEL_CONSUMPTION = 0x0e;
    public static final byte PROPERTY_CURRENT_FUEL_CONSUMPTION = 0x0f;
    public static final byte PROPERTY_ODOMETER_AFTER_LAST_TRIP = 0x10;
    public static final byte PROPERTY_SAFETY_DRIVING_SCORE = 0x11;
    public static final byte PROPERTY_RAPID_ACCELERATION_GRADE = 0x12;
    public static final byte PROPERTY_RAPID_DECELERATION_GRADE = 0x13;
    public static final byte PROPERTY_LATE_NIGHT_GRADE = 0x14;
    public static final byte PROPERTY_DISTANCE_OVER_TIME = 0x15;
    public static final byte PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_START = 0x16;
    public static final byte PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_RESET = 0x17;
    public static final byte PROPERTY_ELECTRIC_DISTANCE_LAST_TRIP = 0x18;
    public static final byte PROPERTY_ELECTRIC_DISTANCE_SINCE_RESET = 0x19;
    public static final byte PROPERTY_ELECTRIC_DURATION_LAST_TRIP = 0x1a;
    public static final byte PROPERTY_ELECTRIC_DURATION_SINCE_RESET = 0x1b;
    public static final byte PROPERTY_FUEL_CONSUMPTION_RATE_LAST_TRIP = 0x1c;
    public static final byte PROPERTY_FUEL_CONSUMPTION_RATE_SINCE_RESET = 0x1d;
    public static final byte PROPERTY_AVERAGE_SPEED_LAST_TRIP = 0x1e;
    public static final byte PROPERTY_AVERAGE_SPEED_SINCE_RESET = 0x1f;
    public static final byte PROPERTY_FUEL_DISTANCE_LAST_TRIP = 0x20;
    public static final byte PROPERTY_FUEL_DISTANCE_SINCE_RESET = 0x21;
    public static final byte PROPERTY_DRIVING_DURATION_LAST_TRIP = 0x22;
    public static final byte PROPERTY_DRIVING_DURATION_SINCE_RESET = 0x23;
    public static final byte PROPERTY_ECO_SCORE_TOTAL = 0x24;
    public static final byte PROPERTY_ECO_SCORE_FREE_WHEEL = 0x25;
    public static final byte PROPERTY_ECO_SCORE_CONSTANT = 0x26;
    public static final byte PROPERTY_ECO_SCORE_BONUS_RANGE = 0x27;

    /**
     * Get Usage property availability information.
     */
    public static class GetUsageAvailability extends GetAvailabilityCommand {
        /**
         * Get every Usage property availability
         */
        public GetUsageAvailability() {
            super(IDENTIFIER);
        }
    
        /**
         * Get specific Usage property availabilities
         * 
         * @param propertyIdentifiers The property identifierBytes
         */
        public GetUsageAvailability(Bytes propertyIdentifiers) {
            super(IDENTIFIER, propertyIdentifiers);
        }
    
        /**
         * Get specific Usage property availabilities
         * 
         * @param propertyIdentifiers The property identifierBytes
         */
        public GetUsageAvailability(byte... propertyIdentifiers) {
            super(IDENTIFIER, new Bytes(propertyIdentifiers));
        }
    
        GetUsageAvailability(byte[] bytes, @SuppressWarnings("unused") boolean fromRaw) throws CommandParseException {
            super(bytes);
        }
    }

    /**
     * Get usage
     */
    public static class GetUsage extends GetCommand {
        /**
         * Get all Usage properties
         */
        public GetUsage() {
            super(State.class, IDENTIFIER);
        }
    
        /**
         * Get specific Usage properties
         * 
         * @param propertyIdentifiers The property identifiers
         */
        public GetUsage(Bytes propertyIdentifiers) {
            super(State.class, IDENTIFIER, propertyIdentifiers);
        }
    
        /**
         * Get specific Usage properties
         * 
         * @param propertyIdentifiers The property identifiers
         */
        public GetUsage(byte... propertyIdentifiers) {
            super(State.class, IDENTIFIER, new Bytes(propertyIdentifiers));
        }
    
        GetUsage(byte[] bytes, @SuppressWarnings("unused") boolean fromRaw) throws CommandParseException {
            super(State.class, bytes);
        }
    }
    
    /**
     * Get specific Usage properties
     * 
     * @deprecated use {@link GetUsage#GetUsage(byte...)} instead
     */
    @Deprecated
    public static class GetUsageProperties extends GetCommand {
        /**
         * @param propertyIdentifiers The property identifiers
         */
        public GetUsageProperties(Bytes propertyIdentifiers) {
            super(State.class, IDENTIFIER, propertyIdentifiers);
        }
    
        /**
         * @param propertyIdentifiers The property identifiers
         */
        public GetUsageProperties(byte... propertyIdentifiers) {
            super(State.class, IDENTIFIER, new Bytes(propertyIdentifiers));
        }
    
        GetUsageProperties(byte[] bytes, @SuppressWarnings("unused") boolean fromRaw) throws CommandParseException {
            super(State.class, bytes);
        }
    }

    /**
     * The usage state
     */
    public static class State extends SetCommand {
        Property averageWeeklyDistance = new Property<>(Length.class, PROPERTY_AVERAGE_WEEKLY_DISTANCE);
        Property averageWeeklyDistanceLongRun = new Property<>(Length.class, PROPERTY_AVERAGE_WEEKLY_DISTANCE_LONG_RUN);
        Property accelerationEvaluation = new Property<>(Double.class, PROPERTY_ACCELERATION_EVALUATION);
        Property drivingStyleEvaluation = new Property<>(Double.class, PROPERTY_DRIVING_STYLE_EVALUATION);
        List> drivingModesActivationPeriods;
        List> drivingModesEnergyConsumptions;
        Property lastTripEnergyConsumption = new Property<>(Energy.class, PROPERTY_LAST_TRIP_ENERGY_CONSUMPTION);
        Property lastTripFuelConsumption = new Property<>(Volume.class, PROPERTY_LAST_TRIP_FUEL_CONSUMPTION);
        Property mileageAfterLastTrip = new Property<>(Length.class, PROPERTY_MILEAGE_AFTER_LAST_TRIP);
        Property lastTripElectricPortion = new Property<>(Double.class, PROPERTY_LAST_TRIP_ELECTRIC_PORTION);
        Property lastTripAverageEnergyRecuperation = new Property<>(EnergyEfficiency.class, PROPERTY_LAST_TRIP_AVERAGE_ENERGY_RECUPERATION);
        Property lastTripBatteryRemaining = new Property<>(Double.class, PROPERTY_LAST_TRIP_BATTERY_REMAINING);
        Property lastTripDate = new Property<>(Calendar.class, PROPERTY_LAST_TRIP_DATE);
        Property averageFuelConsumption = new Property<>(FuelEfficiency.class, PROPERTY_AVERAGE_FUEL_CONSUMPTION);
        Property currentFuelConsumption = new Property<>(FuelEfficiency.class, PROPERTY_CURRENT_FUEL_CONSUMPTION);
        Property odometerAfterLastTrip = new Property<>(Length.class, PROPERTY_ODOMETER_AFTER_LAST_TRIP);
        Property safetyDrivingScore = new Property<>(Double.class, PROPERTY_SAFETY_DRIVING_SCORE);
        Property rapidAccelerationGrade = new Property<>(Grade.class, PROPERTY_RAPID_ACCELERATION_GRADE);
        Property rapidDecelerationGrade = new Property<>(Grade.class, PROPERTY_RAPID_DECELERATION_GRADE);
        Property lateNightGrade = new Property<>(Grade.class, PROPERTY_LATE_NIGHT_GRADE);
        Property distanceOverTime = new Property<>(DistanceOverTime.class, PROPERTY_DISTANCE_OVER_TIME);
        Property electricConsumptionRateSinceStart = new Property<>(EnergyEfficiency.class, PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_START);
        Property electricConsumptionRateSinceReset = new Property<>(EnergyEfficiency.class, PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_RESET);
        Property electricDistanceLastTrip = new Property<>(Length.class, PROPERTY_ELECTRIC_DISTANCE_LAST_TRIP);
        Property electricDistanceSinceReset = new Property<>(Length.class, PROPERTY_ELECTRIC_DISTANCE_SINCE_RESET);
        Property electricDurationLastTrip = new Property<>(Duration.class, PROPERTY_ELECTRIC_DURATION_LAST_TRIP);
        Property electricDurationSinceReset = new Property<>(Duration.class, PROPERTY_ELECTRIC_DURATION_SINCE_RESET);
        Property fuelConsumptionRateLastTrip = new Property<>(FuelEfficiency.class, PROPERTY_FUEL_CONSUMPTION_RATE_LAST_TRIP);
        Property fuelConsumptionRateSinceReset = new Property<>(FuelEfficiency.class, PROPERTY_FUEL_CONSUMPTION_RATE_SINCE_RESET);
        Property averageSpeedLastTrip = new Property<>(Speed.class, PROPERTY_AVERAGE_SPEED_LAST_TRIP);
        Property averageSpeedSinceReset = new Property<>(Speed.class, PROPERTY_AVERAGE_SPEED_SINCE_RESET);
        Property fuelDistanceLastTrip = new Property<>(Length.class, PROPERTY_FUEL_DISTANCE_LAST_TRIP);
        Property fuelDistanceSinceReset = new Property<>(Length.class, PROPERTY_FUEL_DISTANCE_SINCE_RESET);
        Property drivingDurationLastTrip = new Property<>(Duration.class, PROPERTY_DRIVING_DURATION_LAST_TRIP);
        Property drivingDurationSinceReset = new Property<>(Duration.class, PROPERTY_DRIVING_DURATION_SINCE_RESET);
        Property ecoScoreTotal = new Property<>(Double.class, PROPERTY_ECO_SCORE_TOTAL);
        Property ecoScoreFreeWheel = new Property<>(Double.class, PROPERTY_ECO_SCORE_FREE_WHEEL);
        Property ecoScoreConstant = new Property<>(Double.class, PROPERTY_ECO_SCORE_CONSTANT);
        Property ecoScoreBonusRange = new Property<>(Length.class, PROPERTY_ECO_SCORE_BONUS_RANGE);
    
        /**
         * @return Average weekly distance
         */
        public Property getAverageWeeklyDistance() {
            return averageWeeklyDistance;
        }
    
        /**
         * @return Average weekyl distance over long term
         */
        public Property getAverageWeeklyDistanceLongRun() {
            return averageWeeklyDistanceLongRun;
        }
    
        /**
         * @return Acceleration evaluation percentage
         */
        public Property getAccelerationEvaluation() {
            return accelerationEvaluation;
        }
    
        /**
         * @return Driving style evaluation percentage
         */
        public Property getDrivingStyleEvaluation() {
            return drivingStyleEvaluation;
        }
    
        /**
         * @return The driving modes activation periods
         */
        public List> getDrivingModesActivationPeriods() {
            return drivingModesActivationPeriods;
        }
    
        /**
         * @return The driving modes energy consumptions
         */
        public List> getDrivingModesEnergyConsumptions() {
            return drivingModesEnergyConsumptions;
        }
    
        /**
         * @return Energy consumption in the last trip
         */
        public Property getLastTripEnergyConsumption() {
            return lastTripEnergyConsumption;
        }
    
        /**
         * @return Fuel consumption in the last trip
         */
        public Property getLastTripFuelConsumption() {
            return lastTripFuelConsumption;
        }
    
        /**
         * @return Mileage after the last trip
         * @deprecated 'mileage' is an incorrect term for this. Replaced by {@link #getOdometerAfterLastTrip()}
         */
        @Deprecated
        public Property getMileageAfterLastTrip() {
            return mileageAfterLastTrip;
        }
    
        /**
         * @return Portion of the last trip used in electric mode
         */
        public Property getLastTripElectricPortion() {
            return lastTripElectricPortion;
        }
    
        /**
         * @return Energy recuperation rate for last trip
         */
        public Property getLastTripAverageEnergyRecuperation() {
            return lastTripAverageEnergyRecuperation;
        }
    
        /**
         * @return Battery % remaining after last trip
         */
        public Property getLastTripBatteryRemaining() {
            return lastTripBatteryRemaining;
        }
    
        /**
         * @return The last trip date
         */
        public Property getLastTripDate() {
            return lastTripDate;
        }
    
        /**
         * @return Average fuel consumption for current trip
         */
        public Property getAverageFuelConsumption() {
            return averageFuelConsumption;
        }
    
        /**
         * @return Current fuel consumption
         */
        public Property getCurrentFuelConsumption() {
            return currentFuelConsumption;
        }
    
        /**
         * @return Odometer after the last trip
         */
        public Property getOdometerAfterLastTrip() {
            return odometerAfterLastTrip;
        }
    
        /**
         * @return Safety driving score as percentage
         */
        public Property getSafetyDrivingScore() {
            return safetyDrivingScore;
        }
    
        /**
         * @return Grade given for rapid acceleration over time
         */
        public Property getRapidAccelerationGrade() {
            return rapidAccelerationGrade;
        }
    
        /**
         * @return Grade given for rapid deceleration over time
         */
        public Property getRapidDecelerationGrade() {
            return rapidDecelerationGrade;
        }
    
        /**
         * @return Grade given for late night driving over time
         */
        public Property getLateNightGrade() {
            return lateNightGrade;
        }
    
        /**
         * @return Distance driven over a given time period
         */
        public Property getDistanceOverTime() {
            return distanceOverTime;
        }
    
        /**
         * @return Electric energy consumption rate since the start of a trip
         */
        public Property getElectricConsumptionRateSinceStart() {
            return electricConsumptionRateSinceStart;
        }
    
        /**
         * @return Electric energy consumption rate since a reset
         */
        public Property getElectricConsumptionRateSinceReset() {
            return electricConsumptionRateSinceReset;
        }
    
        /**
         * @return Distance travelled with electricity in last trip
         */
        public Property getElectricDistanceLastTrip() {
            return electricDistanceLastTrip;
        }
    
        /**
         * @return Distance travelled with electricity since reset
         */
        public Property getElectricDistanceSinceReset() {
            return electricDistanceSinceReset;
        }
    
        /**
         * @return Duration of travelling using electricity during last trip
         */
        public Property getElectricDurationLastTrip() {
            return electricDurationLastTrip;
        }
    
        /**
         * @return Duration of travelling using electricity since reset
         */
        public Property getElectricDurationSinceReset() {
            return electricDurationSinceReset;
        }
    
        /**
         * @return Liquid fuel consumption rate during last trip
         */
        public Property getFuelConsumptionRateLastTrip() {
            return fuelConsumptionRateLastTrip;
        }
    
        /**
         * @return Liquid fuel consumption rate since reset
         */
        public Property getFuelConsumptionRateSinceReset() {
            return fuelConsumptionRateSinceReset;
        }
    
        /**
         * @return Average speed during last trip
         */
        public Property getAverageSpeedLastTrip() {
            return averageSpeedLastTrip;
        }
    
        /**
         * @return Average speed since reset
         */
        public Property getAverageSpeedSinceReset() {
            return averageSpeedSinceReset;
        }
    
        /**
         * @return Distance travelled with (liquid) fuel during last trip
         */
        public Property getFuelDistanceLastTrip() {
            return fuelDistanceLastTrip;
        }
    
        /**
         * @return Distance travelled with (liquid) fuel since reset
         */
        public Property getFuelDistanceSinceReset() {
            return fuelDistanceSinceReset;
        }
    
        /**
         * @return Duration of last trip
         */
        public Property getDrivingDurationLastTrip() {
            return drivingDurationLastTrip;
        }
    
        /**
         * @return Duration of travelling since reset
         */
        public Property getDrivingDurationSinceReset() {
            return drivingDurationSinceReset;
        }
    
        /**
         * @return Overall eco-score rating
         */
        public Property getEcoScoreTotal() {
            return ecoScoreTotal;
        }
    
        /**
         * @return Eco-score rating for free-wheeling
         */
        public Property getEcoScoreFreeWheel() {
            return ecoScoreFreeWheel;
        }
    
        /**
         * @return Eco-score rating constant
         */
        public Property getEcoScoreConstant() {
            return ecoScoreConstant;
        }
    
        /**
         * @return Eco-score bonus range
         */
        public Property getEcoScoreBonusRange() {
            return ecoScoreBonusRange;
        }
    
        /**
         * @param mode The driving mode.
         * @return The driving mode activation period for given mode.
         */
        @Nullable public Property getDrivingModeActivationPeriod(DrivingMode mode) {
            for (Property drivingModeActivationPeriod :
                    drivingModesActivationPeriods) {
                if (drivingModeActivationPeriod.getValue() != null && drivingModeActivationPeriod.getValue().getDrivingMode() == mode) {
                    return drivingModeActivationPeriod;
                }
            }
            return null;
        }
    
        /**
         * @param mode The driving mode.
         * @return The driving mode energy consumptionfor given mode.
         */
        @Nullable public Property getDrivingModeEnergyConsumption(DrivingMode mode) {
            for (Property drivingModeEnergyConsumption :
                    drivingModesEnergyConsumptions) {
                if (drivingModeEnergyConsumption.getValue() != null && drivingModeEnergyConsumption.getValue().getDrivingMode() == mode) {
                    return drivingModeEnergyConsumption;
                }
            }
            return null;
        }
    
        State(byte[] bytes) throws CommandParseException {
            super(bytes);
    
            final ArrayList> drivingModesActivationPeriodsBuilder = new ArrayList<>();
            final ArrayList> drivingModesEnergyConsumptionsBuilder = new ArrayList<>();
    
            while (propertyIterator.hasNext()) {
                propertyIterator.parseNext(p -> {
                    switch (p.getPropertyIdentifier()) {
                        case PROPERTY_AVERAGE_WEEKLY_DISTANCE: return averageWeeklyDistance.update(p);
                        case PROPERTY_AVERAGE_WEEKLY_DISTANCE_LONG_RUN: return averageWeeklyDistanceLongRun.update(p);
                        case PROPERTY_ACCELERATION_EVALUATION: return accelerationEvaluation.update(p);
                        case PROPERTY_DRIVING_STYLE_EVALUATION: return drivingStyleEvaluation.update(p);
                        case PROPERTY_DRIVING_MODES_ACTIVATION_PERIODS:
                            Property drivingModesActivationPeriod = new Property<>(DrivingModeActivationPeriod.class, p);
                            drivingModesActivationPeriodsBuilder.add(drivingModesActivationPeriod);
                            return drivingModesActivationPeriod;
                        case PROPERTY_DRIVING_MODES_ENERGY_CONSUMPTIONS:
                            Property drivingModeEnergyConsumption = new Property<>(DrivingModeEnergyConsumption.class, p);
                            drivingModesEnergyConsumptionsBuilder.add(drivingModeEnergyConsumption);
                            return drivingModeEnergyConsumption;
                        case PROPERTY_LAST_TRIP_ENERGY_CONSUMPTION: return lastTripEnergyConsumption.update(p);
                        case PROPERTY_LAST_TRIP_FUEL_CONSUMPTION: return lastTripFuelConsumption.update(p);
                        case PROPERTY_MILEAGE_AFTER_LAST_TRIP: return mileageAfterLastTrip.update(p);
                        case PROPERTY_LAST_TRIP_ELECTRIC_PORTION: return lastTripElectricPortion.update(p);
                        case PROPERTY_LAST_TRIP_AVERAGE_ENERGY_RECUPERATION: return lastTripAverageEnergyRecuperation.update(p);
                        case PROPERTY_LAST_TRIP_BATTERY_REMAINING: return lastTripBatteryRemaining.update(p);
                        case PROPERTY_LAST_TRIP_DATE: return lastTripDate.update(p);
                        case PROPERTY_AVERAGE_FUEL_CONSUMPTION: return averageFuelConsumption.update(p);
                        case PROPERTY_CURRENT_FUEL_CONSUMPTION: return currentFuelConsumption.update(p);
                        case PROPERTY_ODOMETER_AFTER_LAST_TRIP: return odometerAfterLastTrip.update(p);
                        case PROPERTY_SAFETY_DRIVING_SCORE: return safetyDrivingScore.update(p);
                        case PROPERTY_RAPID_ACCELERATION_GRADE: return rapidAccelerationGrade.update(p);
                        case PROPERTY_RAPID_DECELERATION_GRADE: return rapidDecelerationGrade.update(p);
                        case PROPERTY_LATE_NIGHT_GRADE: return lateNightGrade.update(p);
                        case PROPERTY_DISTANCE_OVER_TIME: return distanceOverTime.update(p);
                        case PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_START: return electricConsumptionRateSinceStart.update(p);
                        case PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_RESET: return electricConsumptionRateSinceReset.update(p);
                        case PROPERTY_ELECTRIC_DISTANCE_LAST_TRIP: return electricDistanceLastTrip.update(p);
                        case PROPERTY_ELECTRIC_DISTANCE_SINCE_RESET: return electricDistanceSinceReset.update(p);
                        case PROPERTY_ELECTRIC_DURATION_LAST_TRIP: return electricDurationLastTrip.update(p);
                        case PROPERTY_ELECTRIC_DURATION_SINCE_RESET: return electricDurationSinceReset.update(p);
                        case PROPERTY_FUEL_CONSUMPTION_RATE_LAST_TRIP: return fuelConsumptionRateLastTrip.update(p);
                        case PROPERTY_FUEL_CONSUMPTION_RATE_SINCE_RESET: return fuelConsumptionRateSinceReset.update(p);
                        case PROPERTY_AVERAGE_SPEED_LAST_TRIP: return averageSpeedLastTrip.update(p);
                        case PROPERTY_AVERAGE_SPEED_SINCE_RESET: return averageSpeedSinceReset.update(p);
                        case PROPERTY_FUEL_DISTANCE_LAST_TRIP: return fuelDistanceLastTrip.update(p);
                        case PROPERTY_FUEL_DISTANCE_SINCE_RESET: return fuelDistanceSinceReset.update(p);
                        case PROPERTY_DRIVING_DURATION_LAST_TRIP: return drivingDurationLastTrip.update(p);
                        case PROPERTY_DRIVING_DURATION_SINCE_RESET: return drivingDurationSinceReset.update(p);
                        case PROPERTY_ECO_SCORE_TOTAL: return ecoScoreTotal.update(p);
                        case PROPERTY_ECO_SCORE_FREE_WHEEL: return ecoScoreFreeWheel.update(p);
                        case PROPERTY_ECO_SCORE_CONSTANT: return ecoScoreConstant.update(p);
                        case PROPERTY_ECO_SCORE_BONUS_RANGE: return ecoScoreBonusRange.update(p);
                    }
    
                    return null;
                });
            }
    
            drivingModesActivationPeriods = drivingModesActivationPeriodsBuilder;
            drivingModesEnergyConsumptions = drivingModesEnergyConsumptionsBuilder;
        }
    
        private State(Builder builder) {
            super(builder);
    
            averageWeeklyDistance = builder.averageWeeklyDistance;
            averageWeeklyDistanceLongRun = builder.averageWeeklyDistanceLongRun;
            accelerationEvaluation = builder.accelerationEvaluation;
            drivingStyleEvaluation = builder.drivingStyleEvaluation;
            drivingModesActivationPeriods = builder.drivingModesActivationPeriods;
            drivingModesEnergyConsumptions = builder.drivingModesEnergyConsumptions;
            lastTripEnergyConsumption = builder.lastTripEnergyConsumption;
            lastTripFuelConsumption = builder.lastTripFuelConsumption;
            mileageAfterLastTrip = builder.mileageAfterLastTrip;
            lastTripElectricPortion = builder.lastTripElectricPortion;
            lastTripAverageEnergyRecuperation = builder.lastTripAverageEnergyRecuperation;
            lastTripBatteryRemaining = builder.lastTripBatteryRemaining;
            lastTripDate = builder.lastTripDate;
            averageFuelConsumption = builder.averageFuelConsumption;
            currentFuelConsumption = builder.currentFuelConsumption;
            odometerAfterLastTrip = builder.odometerAfterLastTrip;
            safetyDrivingScore = builder.safetyDrivingScore;
            rapidAccelerationGrade = builder.rapidAccelerationGrade;
            rapidDecelerationGrade = builder.rapidDecelerationGrade;
            lateNightGrade = builder.lateNightGrade;
            distanceOverTime = builder.distanceOverTime;
            electricConsumptionRateSinceStart = builder.electricConsumptionRateSinceStart;
            electricConsumptionRateSinceReset = builder.electricConsumptionRateSinceReset;
            electricDistanceLastTrip = builder.electricDistanceLastTrip;
            electricDistanceSinceReset = builder.electricDistanceSinceReset;
            electricDurationLastTrip = builder.electricDurationLastTrip;
            electricDurationSinceReset = builder.electricDurationSinceReset;
            fuelConsumptionRateLastTrip = builder.fuelConsumptionRateLastTrip;
            fuelConsumptionRateSinceReset = builder.fuelConsumptionRateSinceReset;
            averageSpeedLastTrip = builder.averageSpeedLastTrip;
            averageSpeedSinceReset = builder.averageSpeedSinceReset;
            fuelDistanceLastTrip = builder.fuelDistanceLastTrip;
            fuelDistanceSinceReset = builder.fuelDistanceSinceReset;
            drivingDurationLastTrip = builder.drivingDurationLastTrip;
            drivingDurationSinceReset = builder.drivingDurationSinceReset;
            ecoScoreTotal = builder.ecoScoreTotal;
            ecoScoreFreeWheel = builder.ecoScoreFreeWheel;
            ecoScoreConstant = builder.ecoScoreConstant;
            ecoScoreBonusRange = builder.ecoScoreBonusRange;
        }
    
        public static final class Builder extends SetCommand.Builder {
            private Property averageWeeklyDistance;
            private Property averageWeeklyDistanceLongRun;
            private Property accelerationEvaluation;
            private Property drivingStyleEvaluation;
            private final List> drivingModesActivationPeriods = new ArrayList<>();
            private final List> drivingModesEnergyConsumptions = new ArrayList<>();
            private Property lastTripEnergyConsumption;
            private Property lastTripFuelConsumption;
            private Property mileageAfterLastTrip;
            private Property lastTripElectricPortion;
            private Property lastTripAverageEnergyRecuperation;
            private Property lastTripBatteryRemaining;
            private Property lastTripDate;
            private Property averageFuelConsumption;
            private Property currentFuelConsumption;
            private Property odometerAfterLastTrip;
            private Property safetyDrivingScore;
            private Property rapidAccelerationGrade;
            private Property rapidDecelerationGrade;
            private Property lateNightGrade;
            private Property distanceOverTime;
            private Property electricConsumptionRateSinceStart;
            private Property electricConsumptionRateSinceReset;
            private Property electricDistanceLastTrip;
            private Property electricDistanceSinceReset;
            private Property electricDurationLastTrip;
            private Property electricDurationSinceReset;
            private Property fuelConsumptionRateLastTrip;
            private Property fuelConsumptionRateSinceReset;
            private Property averageSpeedLastTrip;
            private Property averageSpeedSinceReset;
            private Property fuelDistanceLastTrip;
            private Property fuelDistanceSinceReset;
            private Property drivingDurationLastTrip;
            private Property drivingDurationSinceReset;
            private Property ecoScoreTotal;
            private Property ecoScoreFreeWheel;
            private Property ecoScoreConstant;
            private Property ecoScoreBonusRange;
    
            public Builder() {
                super(IDENTIFIER);
            }
    
            public State build() {
                return new State(this);
            }
    
            /**
             * @param averageWeeklyDistance Average weekly distance
             * @return The builder
             */
            public Builder setAverageWeeklyDistance(Property averageWeeklyDistance) {
                this.averageWeeklyDistance = averageWeeklyDistance.setIdentifier(PROPERTY_AVERAGE_WEEKLY_DISTANCE);
                addProperty(this.averageWeeklyDistance);
                return this;
            }
            
            /**
             * @param averageWeeklyDistanceLongRun Average weekyl distance over long term
             * @return The builder
             */
            public Builder setAverageWeeklyDistanceLongRun(Property averageWeeklyDistanceLongRun) {
                this.averageWeeklyDistanceLongRun = averageWeeklyDistanceLongRun.setIdentifier(PROPERTY_AVERAGE_WEEKLY_DISTANCE_LONG_RUN);
                addProperty(this.averageWeeklyDistanceLongRun);
                return this;
            }
            
            /**
             * @param accelerationEvaluation Acceleration evaluation percentage
             * @return The builder
             */
            public Builder setAccelerationEvaluation(Property accelerationEvaluation) {
                this.accelerationEvaluation = accelerationEvaluation.setIdentifier(PROPERTY_ACCELERATION_EVALUATION);
                addProperty(this.accelerationEvaluation);
                return this;
            }
            
            /**
             * @param drivingStyleEvaluation Driving style evaluation percentage
             * @return The builder
             */
            public Builder setDrivingStyleEvaluation(Property drivingStyleEvaluation) {
                this.drivingStyleEvaluation = drivingStyleEvaluation.setIdentifier(PROPERTY_DRIVING_STYLE_EVALUATION);
                addProperty(this.drivingStyleEvaluation);
                return this;
            }
            
            /**
             * Add an array of driving modes activation periods.
             * 
             * @param drivingModesActivationPeriods The driving modes activation periods
             * @return The builder
             */
            public Builder setDrivingModesActivationPeriods(Property[] drivingModesActivationPeriods) {
                this.drivingModesActivationPeriods.clear();
                for (int i = 0; i < drivingModesActivationPeriods.length; i++) {
                    addDrivingModesActivationPeriod(drivingModesActivationPeriods[i]);
                }
            
                return this;
            }
            
            /**
             * Add a single driving modes activation period.
             * 
             * @param drivingModesActivationPeriod The driving modes activation period
             * @return The builder
             */
            public Builder addDrivingModesActivationPeriod(Property drivingModesActivationPeriod) {
                drivingModesActivationPeriod.setIdentifier(PROPERTY_DRIVING_MODES_ACTIVATION_PERIODS);
                addProperty(drivingModesActivationPeriod);
                drivingModesActivationPeriods.add(drivingModesActivationPeriod);
                return this;
            }
            
            /**
             * Add an array of driving modes energy consumptions.
             * 
             * @param drivingModesEnergyConsumptions The driving modes energy consumptions
             * @return The builder
             */
            public Builder setDrivingModesEnergyConsumptions(Property[] drivingModesEnergyConsumptions) {
                this.drivingModesEnergyConsumptions.clear();
                for (int i = 0; i < drivingModesEnergyConsumptions.length; i++) {
                    addDrivingModeEnergyConsumption(drivingModesEnergyConsumptions[i]);
                }
            
                return this;
            }
            
            /**
             * Add a single driving mode energy consumption.
             * 
             * @param drivingModeEnergyConsumption The driving mode energy consumption
             * @return The builder
             */
            public Builder addDrivingModeEnergyConsumption(Property drivingModeEnergyConsumption) {
                drivingModeEnergyConsumption.setIdentifier(PROPERTY_DRIVING_MODES_ENERGY_CONSUMPTIONS);
                addProperty(drivingModeEnergyConsumption);
                drivingModesEnergyConsumptions.add(drivingModeEnergyConsumption);
                return this;
            }
            
            /**
             * @param lastTripEnergyConsumption Energy consumption in the last trip
             * @return The builder
             */
            public Builder setLastTripEnergyConsumption(Property lastTripEnergyConsumption) {
                this.lastTripEnergyConsumption = lastTripEnergyConsumption.setIdentifier(PROPERTY_LAST_TRIP_ENERGY_CONSUMPTION);
                addProperty(this.lastTripEnergyConsumption);
                return this;
            }
            
            /**
             * @param lastTripFuelConsumption Fuel consumption in the last trip
             * @return The builder
             */
            public Builder setLastTripFuelConsumption(Property lastTripFuelConsumption) {
                this.lastTripFuelConsumption = lastTripFuelConsumption.setIdentifier(PROPERTY_LAST_TRIP_FUEL_CONSUMPTION);
                addProperty(this.lastTripFuelConsumption);
                return this;
            }
            
            /**
             * @param mileageAfterLastTrip Mileage after the last trip
             * @return The builder
             * @deprecated 'mileage' is an incorrect term for this. Replaced by {@link #getOdometerAfterLastTrip()}
             */
            @Deprecated
            public Builder setMileageAfterLastTrip(Property mileageAfterLastTrip) {
                this.mileageAfterLastTrip = mileageAfterLastTrip.setIdentifier(PROPERTY_MILEAGE_AFTER_LAST_TRIP);
                addProperty(this.mileageAfterLastTrip);
                return this;
            }
            
            /**
             * @param lastTripElectricPortion Portion of the last trip used in electric mode
             * @return The builder
             */
            public Builder setLastTripElectricPortion(Property lastTripElectricPortion) {
                this.lastTripElectricPortion = lastTripElectricPortion.setIdentifier(PROPERTY_LAST_TRIP_ELECTRIC_PORTION);
                addProperty(this.lastTripElectricPortion);
                return this;
            }
            
            /**
             * @param lastTripAverageEnergyRecuperation Energy recuperation rate for last trip
             * @return The builder
             */
            public Builder setLastTripAverageEnergyRecuperation(Property lastTripAverageEnergyRecuperation) {
                this.lastTripAverageEnergyRecuperation = lastTripAverageEnergyRecuperation.setIdentifier(PROPERTY_LAST_TRIP_AVERAGE_ENERGY_RECUPERATION);
                addProperty(this.lastTripAverageEnergyRecuperation);
                return this;
            }
            
            /**
             * @param lastTripBatteryRemaining Battery % remaining after last trip
             * @return The builder
             */
            public Builder setLastTripBatteryRemaining(Property lastTripBatteryRemaining) {
                this.lastTripBatteryRemaining = lastTripBatteryRemaining.setIdentifier(PROPERTY_LAST_TRIP_BATTERY_REMAINING);
                addProperty(this.lastTripBatteryRemaining);
                return this;
            }
            
            /**
             * @param lastTripDate The last trip date
             * @return The builder
             */
            public Builder setLastTripDate(Property lastTripDate) {
                this.lastTripDate = lastTripDate.setIdentifier(PROPERTY_LAST_TRIP_DATE);
                addProperty(this.lastTripDate);
                return this;
            }
            
            /**
             * @param averageFuelConsumption Average fuel consumption for current trip
             * @return The builder
             */
            public Builder setAverageFuelConsumption(Property averageFuelConsumption) {
                this.averageFuelConsumption = averageFuelConsumption.setIdentifier(PROPERTY_AVERAGE_FUEL_CONSUMPTION);
                addProperty(this.averageFuelConsumption);
                return this;
            }
            
            /**
             * @param currentFuelConsumption Current fuel consumption
             * @return The builder
             */
            public Builder setCurrentFuelConsumption(Property currentFuelConsumption) {
                this.currentFuelConsumption = currentFuelConsumption.setIdentifier(PROPERTY_CURRENT_FUEL_CONSUMPTION);
                addProperty(this.currentFuelConsumption);
                return this;
            }
            
            /**
             * @param odometerAfterLastTrip Odometer after the last trip
             * @return The builder
             */
            public Builder setOdometerAfterLastTrip(Property odometerAfterLastTrip) {
                this.odometerAfterLastTrip = odometerAfterLastTrip.setIdentifier(PROPERTY_ODOMETER_AFTER_LAST_TRIP);
                addProperty(this.odometerAfterLastTrip);
                return this;
            }
            
            /**
             * @param safetyDrivingScore Safety driving score as percentage
             * @return The builder
             */
            public Builder setSafetyDrivingScore(Property safetyDrivingScore) {
                this.safetyDrivingScore = safetyDrivingScore.setIdentifier(PROPERTY_SAFETY_DRIVING_SCORE);
                addProperty(this.safetyDrivingScore);
                return this;
            }
            
            /**
             * @param rapidAccelerationGrade Grade given for rapid acceleration over time
             * @return The builder
             */
            public Builder setRapidAccelerationGrade(Property rapidAccelerationGrade) {
                this.rapidAccelerationGrade = rapidAccelerationGrade.setIdentifier(PROPERTY_RAPID_ACCELERATION_GRADE);
                addProperty(this.rapidAccelerationGrade);
                return this;
            }
            
            /**
             * @param rapidDecelerationGrade Grade given for rapid deceleration over time
             * @return The builder
             */
            public Builder setRapidDecelerationGrade(Property rapidDecelerationGrade) {
                this.rapidDecelerationGrade = rapidDecelerationGrade.setIdentifier(PROPERTY_RAPID_DECELERATION_GRADE);
                addProperty(this.rapidDecelerationGrade);
                return this;
            }
            
            /**
             * @param lateNightGrade Grade given for late night driving over time
             * @return The builder
             */
            public Builder setLateNightGrade(Property lateNightGrade) {
                this.lateNightGrade = lateNightGrade.setIdentifier(PROPERTY_LATE_NIGHT_GRADE);
                addProperty(this.lateNightGrade);
                return this;
            }
            
            /**
             * @param distanceOverTime Distance driven over a given time period
             * @return The builder
             */
            public Builder setDistanceOverTime(Property distanceOverTime) {
                this.distanceOverTime = distanceOverTime.setIdentifier(PROPERTY_DISTANCE_OVER_TIME);
                addProperty(this.distanceOverTime);
                return this;
            }
            
            /**
             * @param electricConsumptionRateSinceStart Electric energy consumption rate since the start of a trip
             * @return The builder
             */
            public Builder setElectricConsumptionRateSinceStart(Property electricConsumptionRateSinceStart) {
                this.electricConsumptionRateSinceStart = electricConsumptionRateSinceStart.setIdentifier(PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_START);
                addProperty(this.electricConsumptionRateSinceStart);
                return this;
            }
            
            /**
             * @param electricConsumptionRateSinceReset Electric energy consumption rate since a reset
             * @return The builder
             */
            public Builder setElectricConsumptionRateSinceReset(Property electricConsumptionRateSinceReset) {
                this.electricConsumptionRateSinceReset = electricConsumptionRateSinceReset.setIdentifier(PROPERTY_ELECTRIC_CONSUMPTION_RATE_SINCE_RESET);
                addProperty(this.electricConsumptionRateSinceReset);
                return this;
            }
            
            /**
             * @param electricDistanceLastTrip Distance travelled with electricity in last trip
             * @return The builder
             */
            public Builder setElectricDistanceLastTrip(Property electricDistanceLastTrip) {
                this.electricDistanceLastTrip = electricDistanceLastTrip.setIdentifier(PROPERTY_ELECTRIC_DISTANCE_LAST_TRIP);
                addProperty(this.electricDistanceLastTrip);
                return this;
            }
            
            /**
             * @param electricDistanceSinceReset Distance travelled with electricity since reset
             * @return The builder
             */
            public Builder setElectricDistanceSinceReset(Property electricDistanceSinceReset) {
                this.electricDistanceSinceReset = electricDistanceSinceReset.setIdentifier(PROPERTY_ELECTRIC_DISTANCE_SINCE_RESET);
                addProperty(this.electricDistanceSinceReset);
                return this;
            }
            
            /**
             * @param electricDurationLastTrip Duration of travelling using electricity during last trip
             * @return The builder
             */
            public Builder setElectricDurationLastTrip(Property electricDurationLastTrip) {
                this.electricDurationLastTrip = electricDurationLastTrip.setIdentifier(PROPERTY_ELECTRIC_DURATION_LAST_TRIP);
                addProperty(this.electricDurationLastTrip);
                return this;
            }
            
            /**
             * @param electricDurationSinceReset Duration of travelling using electricity since reset
             * @return The builder
             */
            public Builder setElectricDurationSinceReset(Property electricDurationSinceReset) {
                this.electricDurationSinceReset = electricDurationSinceReset.setIdentifier(PROPERTY_ELECTRIC_DURATION_SINCE_RESET);
                addProperty(this.electricDurationSinceReset);
                return this;
            }
            
            /**
             * @param fuelConsumptionRateLastTrip Liquid fuel consumption rate during last trip
             * @return The builder
             */
            public Builder setFuelConsumptionRateLastTrip(Property fuelConsumptionRateLastTrip) {
                this.fuelConsumptionRateLastTrip = fuelConsumptionRateLastTrip.setIdentifier(PROPERTY_FUEL_CONSUMPTION_RATE_LAST_TRIP);
                addProperty(this.fuelConsumptionRateLastTrip);
                return this;
            }
            
            /**
             * @param fuelConsumptionRateSinceReset Liquid fuel consumption rate since reset
             * @return The builder
             */
            public Builder setFuelConsumptionRateSinceReset(Property fuelConsumptionRateSinceReset) {
                this.fuelConsumptionRateSinceReset = fuelConsumptionRateSinceReset.setIdentifier(PROPERTY_FUEL_CONSUMPTION_RATE_SINCE_RESET);
                addProperty(this.fuelConsumptionRateSinceReset);
                return this;
            }
            
            /**
             * @param averageSpeedLastTrip Average speed during last trip
             * @return The builder
             */
            public Builder setAverageSpeedLastTrip(Property averageSpeedLastTrip) {
                this.averageSpeedLastTrip = averageSpeedLastTrip.setIdentifier(PROPERTY_AVERAGE_SPEED_LAST_TRIP);
                addProperty(this.averageSpeedLastTrip);
                return this;
            }
            
            /**
             * @param averageSpeedSinceReset Average speed since reset
             * @return The builder
             */
            public Builder setAverageSpeedSinceReset(Property averageSpeedSinceReset) {
                this.averageSpeedSinceReset = averageSpeedSinceReset.setIdentifier(PROPERTY_AVERAGE_SPEED_SINCE_RESET);
                addProperty(this.averageSpeedSinceReset);
                return this;
            }
            
            /**
             * @param fuelDistanceLastTrip Distance travelled with (liquid) fuel during last trip
             * @return The builder
             */
            public Builder setFuelDistanceLastTrip(Property fuelDistanceLastTrip) {
                this.fuelDistanceLastTrip = fuelDistanceLastTrip.setIdentifier(PROPERTY_FUEL_DISTANCE_LAST_TRIP);
                addProperty(this.fuelDistanceLastTrip);
                return this;
            }
            
            /**
             * @param fuelDistanceSinceReset Distance travelled with (liquid) fuel since reset
             * @return The builder
             */
            public Builder setFuelDistanceSinceReset(Property fuelDistanceSinceReset) {
                this.fuelDistanceSinceReset = fuelDistanceSinceReset.setIdentifier(PROPERTY_FUEL_DISTANCE_SINCE_RESET);
                addProperty(this.fuelDistanceSinceReset);
                return this;
            }
            
            /**
             * @param drivingDurationLastTrip Duration of last trip
             * @return The builder
             */
            public Builder setDrivingDurationLastTrip(Property drivingDurationLastTrip) {
                this.drivingDurationLastTrip = drivingDurationLastTrip.setIdentifier(PROPERTY_DRIVING_DURATION_LAST_TRIP);
                addProperty(this.drivingDurationLastTrip);
                return this;
            }
            
            /**
             * @param drivingDurationSinceReset Duration of travelling since reset
             * @return The builder
             */
            public Builder setDrivingDurationSinceReset(Property drivingDurationSinceReset) {
                this.drivingDurationSinceReset = drivingDurationSinceReset.setIdentifier(PROPERTY_DRIVING_DURATION_SINCE_RESET);
                addProperty(this.drivingDurationSinceReset);
                return this;
            }
            
            /**
             * @param ecoScoreTotal Overall eco-score rating
             * @return The builder
             */
            public Builder setEcoScoreTotal(Property ecoScoreTotal) {
                this.ecoScoreTotal = ecoScoreTotal.setIdentifier(PROPERTY_ECO_SCORE_TOTAL);
                addProperty(this.ecoScoreTotal);
                return this;
            }
            
            /**
             * @param ecoScoreFreeWheel Eco-score rating for free-wheeling
             * @return The builder
             */
            public Builder setEcoScoreFreeWheel(Property ecoScoreFreeWheel) {
                this.ecoScoreFreeWheel = ecoScoreFreeWheel.setIdentifier(PROPERTY_ECO_SCORE_FREE_WHEEL);
                addProperty(this.ecoScoreFreeWheel);
                return this;
            }
            
            /**
             * @param ecoScoreConstant Eco-score rating constant
             * @return The builder
             */
            public Builder setEcoScoreConstant(Property ecoScoreConstant) {
                this.ecoScoreConstant = ecoScoreConstant.setIdentifier(PROPERTY_ECO_SCORE_CONSTANT);
                addProperty(this.ecoScoreConstant);
                return this;
            }
            
            /**
             * @param ecoScoreBonusRange Eco-score bonus range
             * @return The builder
             */
            public Builder setEcoScoreBonusRange(Property ecoScoreBonusRange) {
                this.ecoScoreBonusRange = ecoScoreBonusRange.setIdentifier(PROPERTY_ECO_SCORE_BONUS_RANGE);
                addProperty(this.ecoScoreBonusRange);
                return this;
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy