2023-06-20 19:39:06 +03:00
|
|
|
/*
|
|
|
|
* %W% %E% Dymik739
|
|
|
|
* Email: dymik739@109.86.70.81
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 FIOT Dev Team
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class representing a general appliance and containing basic methods
|
|
|
|
* that are used in multiple child classes. Supposed to be extended by
|
|
|
|
* other classes and not to be used as a standalone class.
|
|
|
|
*
|
|
|
|
* @author Dymik739
|
|
|
|
* @since 0.3
|
|
|
|
*/
|
|
|
|
public class Appliance implements Comparable<Appliance> {
|
|
|
|
/** Indicates if this device is drawing power from the power network. */
|
2023-06-18 20:08:19 +03:00
|
|
|
private boolean powerConnected;
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/** Defines the type of this device */
|
|
|
|
private String type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for this class. Should be called only from within
|
|
|
|
* constructors of other classes which inherit this one.
|
|
|
|
*
|
|
|
|
* @param connected defines if the device is connected to the network
|
|
|
|
* at the start
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public Appliance(boolean connected) {
|
|
|
|
this.powerConnected = connected;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Getter for checking the power connection.
|
|
|
|
*
|
|
|
|
* @return true if connected and false otherwise
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public boolean getPowerState() {
|
|
|
|
return powerConnected;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Getter for the device type variable.
|
|
|
|
*
|
|
|
|
* @return device type string
|
|
|
|
*/
|
|
|
|
public String getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setter for setting the device type string.
|
|
|
|
* Should be used only from the constructors of the classes
|
|
|
|
* which inherit this one!
|
|
|
|
*
|
|
|
|
* @param type type of the device
|
|
|
|
*/
|
|
|
|
public void setType(String type) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method for connecting power to the device.
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public void plug() {
|
|
|
|
powerConnected = true;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Method for disconnecting power from the device.
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public void unplug() {
|
|
|
|
powerConnected = false;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Method for getting the smaller value out of two.
|
|
|
|
*
|
|
|
|
* @param v1 first value
|
|
|
|
* @param v2 second value
|
|
|
|
*
|
|
|
|
* @return smaller value of the two given
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public float min(float v1, float v2) {
|
|
|
|
return v1 <= v2 ? v1 : v2;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Method for getting the bigger value out of two.
|
|
|
|
*
|
|
|
|
* @param v1 first value
|
|
|
|
* @param v2 second value
|
|
|
|
*
|
|
|
|
* @return bigger value of the two given
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public float max(float v1, float v2) {
|
|
|
|
return v1 >= v2 ? v1 : v2;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Dummy method for getting the power consumption of the device.
|
|
|
|
* Should be overridden by the child class!
|
|
|
|
*
|
|
|
|
* @return current power consumption.
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public float getPowerConsumption() {
|
|
|
|
return 0f;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Dummy method for performing the simulation.
|
|
|
|
* Should be overridden by the child class!
|
|
|
|
*
|
|
|
|
* @param seconds delta time for the correct simulation step
|
|
|
|
* @param ventRPM air flow created by the vent
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public void step(float seconds, float ventRPM) {}
|
2023-06-20 19:39:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method for comparing this appliance's power consumption to another
|
|
|
|
* one. Part os the Comparable implementation.
|
|
|
|
*
|
|
|
|
* @param o another appliance to compare to
|
|
|
|
*
|
|
|
|
* @return difference between power consumption values
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int compareTo(Appliance o) {
|
|
|
|
return (int) (getPowerConsumption() - o.getPowerConsumption());
|
|
|
|
}
|
2023-06-18 20:08:19 +03:00
|
|
|
}
|