Formatted code according to google java (aosp) format

This commit is contained in:
Claudio Maggioni 2020-02-24 14:28:13 +01:00
parent e932c5cf58
commit e3df659e82
26 changed files with 101 additions and 162 deletions

View File

@ -1,12 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@Controller @Controller
@ -14,7 +13,12 @@ public class WelcomeController {
@GetMapping("/") @GetMapping("/")
List<Device> testDevices() { List<Device> testDevices() {
return Arrays.asList(new KnobDimmer(), new RegularLight(), new MotionSensor(), return Arrays.asList(
new Sensor(), new SmartPlug(), new Switch()); new KnobDimmer(),
new RegularLight(),
new MotionSensor(),
new Sensor(),
new SmartPlug(),
new Switch());
} }
} }

View File

@ -3,8 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /**
* Represents a dimmer that can only instruct an increase or decrease of intensity * Represents a dimmer that can only instruct an increase or decrease of intensity (i.e. like a
* (i.e. like a dimmer with a '+' and a '-' button) * dimmer with a '+' and a '-' button)
*/ */
@Entity @Entity
public class ButtonDimmer extends Dimmer { public class ButtonDimmer extends Dimmer {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface ButtonDimmerRepository extends CrudRepository<ButtonDimmer, Long> { public interface ButtonDimmerRepository extends CrudRepository<ButtonDimmer, Long> {}
}

View File

@ -2,53 +2,42 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.*; import javax.persistence.*;
/** /** Generic abstraction for a smart home device */
* Generic abstraction for a smart home device
*/
@Entity @Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Device { public abstract class Device {
/** /** Ways a device can behave in the automation flow. For now only input/output */
* Ways a device can behave in the automation flow. For now only input/output
*/
public enum FlowType { public enum FlowType {
INPUT, INPUT,
OUTPUT OUTPUT
} }
/** /** Device identifier */
* Device identifier
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false) @Column(name = "id", updatable = false, nullable = false)
private long id; private long id;
/** /** The room this device belongs in */
* The room this device belongs in
*/
@ManyToOne @ManyToOne
@JoinColumn(name="room_id") @JoinColumn(name = "room_id")
private Room room; private Room room;
/** /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
* The name of the device as assigned by the user (e.g. 'Master bedroom light') @Column private String name;
*/
@Column
private String name;
/** /**
* The name for the category of this particular device (e.g 'dimmer'). * The name for the category of this particular device (e.g 'dimmer'). Not stored in the
* Not stored in the database (thanks to 'transient') but set thanks to constructors * database (thanks to 'transient') but set thanks to constructors
*/ */
private transient final String kind; private final transient String kind;
/** /**
* The way this device behaves in the automation flow. * The way this device behaves in the automation flow. Not stored in the database (thanks to
* Not stored in the database (thanks to 'transient') but set thanks to constructors * 'transient') but set thanks to constructors
*/ */
private transient final FlowType flowType; private final transient FlowType flowType;
public long getId() { public long getId() {
return id; return id;

View File

@ -3,9 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /** Represent a dimmable light */
* Represent a dimmable light
*/
@Entity @Entity
public class DimmableLight extends Light { public class DimmableLight extends Light {
@ -13,11 +11,8 @@ public class DimmableLight extends Light {
super("light"); super("light");
} }
/** /** The light intensity value. Goes from 0 (off) to 100 (on) */
* The light intensity value. Goes from 0 (off) to 100 (on) @Column private int intensity = 0;
*/
@Column
private int intensity = 0;
public int getIntensity() { public int getIntensity() {
return intensity; return intensity;

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface DimmableLightRepository extends CrudRepository<DimmableLight, Long> { public interface DimmableLightRepository extends CrudRepository<DimmableLight, Long> {}
}

View File

@ -4,9 +4,7 @@ import javax.persistence.Entity;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
/** /** Represents a generic dimmer input device */
* Represents a generic dimmer input device
*/
@Entity @Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Dimmer extends InputDevice { public abstract class Dimmer extends InputDevice {

View File

@ -3,8 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /**
* A generic abstraction for an input device, i.e. something that captures input either from the environment (sensor) * A generic abstraction for an input device, i.e. something that captures input either from the
* or the user (switch / dimmer). * environment (sensor) or the user (switch / dimmer).
*/ */
@Entity @Entity
public abstract class InputDevice extends Device { public abstract class InputDevice extends Device {

View File

@ -3,7 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /**
* Represents a dimmer able to set absolute intensity values (i.e. knowing the absolute intensity value, like a knob) * Represents a dimmer able to set absolute intensity values (i.e. knowing the absolute intensity
* value, like a knob)
*/ */
@Entity @Entity
public class KnobDimmer extends Dimmer { public class KnobDimmer extends Dimmer {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface KnobDimmerRepository extends CrudRepository<KnobDimmer, Long> { public interface KnobDimmerRepository extends CrudRepository<KnobDimmer, Long> {}
}

View File

@ -5,17 +5,13 @@ import javax.persistence.Entity;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
/** /** Represents a generic light */
* Represents a generic light
*/
@Entity @Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Light extends OutputDevice { public abstract class Light extends OutputDevice {
/** /** Whether the light is on or not */
* Whether the light is on or not @Column(name = "light_on")
*/
@Column(name="light_on")
boolean on; boolean on;
protected Light(String kind) { protected Light(String kind) {

View File

@ -2,9 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /** Represents a motion sensor device */
* Represents a motion sensor device
*/
@Entity @Entity
public class MotionSensor extends InputDevice { public class MotionSensor extends InputDevice {
public MotionSensor() { public MotionSensor() {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface MotionSensorRepository extends CrudRepository<MotionSensor, Long> { public interface MotionSensorRepository extends CrudRepository<MotionSensor, Long> {}
}

View File

@ -5,7 +5,8 @@ import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
/** /**
* Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs, ...). * Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs,
* ...).
*/ */
@Entity @Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@ -14,4 +15,3 @@ public abstract class OutputDevice extends Device {
super(kind, FlowType.OUTPUT); super(kind, FlowType.OUTPUT);
} }
} }

View File

@ -2,9 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /** Represents a standard non-dimmable light */
* Represents a standard non-dimmable light
*/
@Entity @Entity
public class RegularLight extends Light { public class RegularLight extends Light {
public RegularLight() { public RegularLight() {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface RegularLightRepository extends CrudRepository<RegularLight, Long> { public interface RegularLightRepository extends CrudRepository<RegularLight, Long> {}
}

View File

@ -1,11 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.*;
import java.util.Set; import java.util.Set;
import javax.persistence.*;
/** /** Represents a room in the house owned by the user */
* Represents a room in the house owned by the user
*/
@Entity @Entity
public class Room { public class Room {
@ -14,22 +12,15 @@ public class Room {
@Column(name = "id", updatable = false, nullable = false) @Column(name = "id", updatable = false, nullable = false)
private Long id; private Long id;
/** /** User that owns the house this room is in */
* User that owns the house this room is in
*/
@ManyToOne @ManyToOne
@JoinColumn(name="user_id") @JoinColumn(name = "user_id")
private User user; private User user;
/** /** The user given name of this room (e.g. 'Master bedroom') */
* The user given name of this room (e.g. 'Master bedroom') @Column private String name;
*/
@Column
private String name;
/** /** Collectiion of devices present in this room */
* Collectiion of devices present in this room
*/
@OneToMany(mappedBy = "room") @OneToMany(mappedBy = "room")
private Set<Device> devices; private Set<Device> devices;
@ -63,11 +54,16 @@ public class Room {
@Override @Override
public String toString() { public String toString() {
return "Room{" + return "Room{"
"id=" + id + + "id="
", user=" + user + + id
", name='" + name + '\'' + + ", user="
", devices=" + devices + + user
'}'; + ", name='"
+ name
+ '\''
+ ", devices="
+ devices
+ '}';
} }
} }

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface RoomRepository extends CrudRepository<Room, User> { public interface RoomRepository extends CrudRepository<Room, User> {}
}

View File

@ -5,37 +5,25 @@ import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
/** /** A sensor input device that measures a quantity in a continuous scale (e.g. temperature) */
* A sensor input device that measures a quantity in a continuous scale (e.g. temperature)
*/
@Entity @Entity
public class Sensor extends InputDevice { public class Sensor extends InputDevice {
/** /** Type of sensor, i.e. of the thing the sensor measures. */
* Type of sensor, i.e. of the thing the sensor measures.
*/
enum SensorType { enum SensorType {
/** /** A sensor that measures temperature in degrees celsius */
* A sensor that measures temperature in degrees celsius
*/
TEMPERATURE, TEMPERATURE,
/** /** A sensor that measures relative humidity in percentage points */
* A sensor that measures relative humidity in percentage points
*/
HUMIDITY, HUMIDITY,
/** /** A sensor that measures light in degrees */
* A sensor that measures light in degrees
*/
LIGHT LIGHT
} }
/** /** The type of this sensor */
* The type of this sensor
*/
@Column @Column
@Enumerated(value=EnumType.STRING) @Enumerated(value = EnumType.STRING)
private SensorType sensor; private SensorType sensor;
public Sensor() { public Sensor() {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface SensorRepository extends CrudRepository<Sensor, Long> { public interface SensorRepository extends CrudRepository<Sensor, Long> {}
}

View File

@ -3,16 +3,12 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /** A smart plug that can be turned either on or off */
* A smart plug that can be turned either on or off
*/
@Entity @Entity
public class SmartPlug extends OutputDevice { public class SmartPlug extends OutputDevice {
/** /** Whether the smart plug is on */
* Whether the smart plug is on @Column(name = "smart_plug_on")
*/
@Column(name="smart_plug_on")
private boolean on; private boolean on;
public boolean isOn() { public boolean isOn() {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface SmartPlugRepository extends CrudRepository<SmartPlug, Long> { public interface SmartPlugRepository extends CrudRepository<SmartPlug, Long> {}
}

View File

@ -2,10 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity; import javax.persistence.Entity;
/** /** A switch input device TODO: define switch behaviour (push button vs on/off state) */
* A switch input device
* TODO: define switch behaviour (push button vs on/off state)
*/
@Entity @Entity
public class Switch extends InputDevice { public class Switch extends InputDevice {
public Switch() { public Switch() {

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface SwitchRepository extends CrudRepository<Switch, Long> { public interface SwitchRepository extends CrudRepository<Switch, Long> {}
}

View File

@ -1,11 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.*;
import java.util.Set; import java.util.Set;
import javax.persistence.*;
/** /** A user of the Smarthut application */
* A user of the Smarthut application
*/
@Entity(name = "smarthutuser") @Entity(name = "smarthutuser")
public class User { public class User {
@ -14,29 +12,16 @@ public class User {
@Column(name = "id", updatable = false, nullable = false) @Column(name = "id", updatable = false, nullable = false)
private Long id; private Long id;
/** /** The full name of the user */
* The full name of the user @Column private String name;
*/
@Column
private String name;
/** /** A properly salted way to store the password TODO: define the implementation of salt */
* A properly salted way to store the password @Column private String hashedPassword;
* TODO: define the implementation of salt
*/
@Column
private String hashedPassword;
/** /** The user's email TODO: validate email in setters */
* The user's email @Column private String email;
* TODO: validate email in setters
*/
@Column
private String email;
/** /** All rooms in the user's house */
* All rooms in the user's house
*/
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private Set<Room> rooms; private Set<Room> rooms;
@ -78,12 +63,20 @@ public class User {
@Override @Override
public String toString() { public String toString() {
return "User{" + return "User{"
"id=" + id + + "id="
", name='" + name + '\'' + + id
", hashedPassword='" + hashedPassword + '\'' + + ", name='"
", email='" + email + '\'' + + name
", rooms=" + rooms + + '\''
'}'; + ", hashedPassword='"
+ hashedPassword
+ '\''
+ ", email='"
+ email
+ '\''
+ ", rooms="
+ rooms
+ '}';
} }
} }

View File

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Long> { public interface UserRepository extends CrudRepository<User, Long> {}
}