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;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@EnableAutoConfiguration
@Controller
@ -14,7 +13,12 @@ public class WelcomeController {
@GetMapping("/")
List<Device> testDevices() {
return Arrays.asList(new KnobDimmer(), new RegularLight(), new MotionSensor(),
new Sensor(), new SmartPlug(), new Switch());
return Arrays.asList(
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;
/**
* Represents a dimmer that can only instruct an increase or decrease of intensity
* (i.e. like a dimmer with a '+' and a '-' button)
* Represents a dimmer that can only instruct an increase or decrease of intensity (i.e. like a
* dimmer with a '+' and a '-' button)
*/
@Entity
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;
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.*;
/**
* Generic abstraction for a smart home device
*/
/** Generic abstraction for a smart home device */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
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 {
INPUT,
OUTPUT
}
/**
* Device identifier
*/
/** Device identifier */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private long id;
/**
* The room this device belongs in
*/
/** The room this device belongs in */
@ManyToOne
@JoinColumn(name = "room_id")
private Room room;
/**
* The name of the device as assigned by the user (e.g. 'Master bedroom light')
*/
@Column
private String name;
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
@Column private String name;
/**
* The name for the category of this particular device (e.g 'dimmer').
* Not stored in the database (thanks to 'transient') but set thanks to constructors
* The name for the category of this particular device (e.g 'dimmer'). Not stored in the
* 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.
* Not stored in the database (thanks to 'transient') but set thanks to constructors
* The way this device behaves in the automation flow. Not stored in the database (thanks to
* 'transient') but set thanks to constructors
*/
private transient final FlowType flowType;
private final transient FlowType flowType;
public long getId() {
return id;

View file

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

View file

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
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.InheritanceType;
/**
* Represents a generic dimmer input device
*/
/** Represents a generic dimmer input device */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Dimmer extends InputDevice {

View file

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

View file

@ -3,7 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
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
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;
public interface KnobDimmerRepository extends CrudRepository<KnobDimmer, Long> {
}
public interface KnobDimmerRepository extends CrudRepository<KnobDimmer, Long> {}

View file

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

View file

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

View file

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
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;
/**
* 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
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@ -14,4 +15,3 @@ public abstract class OutputDevice extends Device {
super(kind, FlowType.OUTPUT);
}
}

View file

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

View file

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
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;
import javax.persistence.*;
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
public class Room {
@ -14,22 +12,15 @@ public class Room {
@Column(name = "id", updatable = false, nullable = false)
private Long id;
/**
* User that owns the house this room is in
*/
/** User that owns the house this room is in */
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
/**
* The user given name of this room (e.g. 'Master bedroom')
*/
@Column
private String name;
/** The user given name of this room (e.g. 'Master bedroom') */
@Column private String name;
/**
* Collectiion of devices present in this room
*/
/** Collectiion of devices present in this room */
@OneToMany(mappedBy = "room")
private Set<Device> devices;
@ -63,11 +54,16 @@ public class Room {
@Override
public String toString() {
return "Room{" +
"id=" + id +
", user=" + user +
", name='" + name + '\'' +
", devices=" + devices +
'}';
return "Room{"
+ "id="
+ id
+ ", user="
+ 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;
public interface RoomRepository extends CrudRepository<Room, User> {
}
public interface RoomRepository extends CrudRepository<Room, User> {}

View file

@ -5,35 +5,23 @@ import javax.persistence.Entity;
import javax.persistence.EnumType;
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
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 {
/**
* A sensor that measures temperature in degrees celsius
*/
/** A sensor that measures temperature in degrees celsius */
TEMPERATURE,
/**
* A sensor that measures relative humidity in percentage points
*/
/** A sensor that measures relative humidity in percentage points */
HUMIDITY,
/**
* A sensor that measures light in degrees
*/
/** A sensor that measures light in degrees */
LIGHT
}
/**
* The type of this sensor
*/
/** The type of this sensor */
@Column
@Enumerated(value = EnumType.STRING)
private SensorType sensor;

View file

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

View file

@ -3,15 +3,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
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
public class SmartPlug extends OutputDevice {
/**
* Whether the smart plug is on
*/
/** Whether the smart plug is on */
@Column(name = "smart_plug_on")
private boolean on;

View file

@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
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;
/**
* 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
public class Switch extends InputDevice {
public Switch() {

View file

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