Skip to content

Commit 8d55976

Browse files
refactor: create abstract room artifact and switchable artifact abstraction
1 parent e2cd01d commit 8d55976

File tree

5 files changed

+80
-50
lines changed

5 files changed

+80
-50
lines changed

src/agt/temperatureControl.asl

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// Cooling goal
4343
+!turnOnCooling(RoomId) : not cooling(RoomId)
4444
<- .concat(RoomId, "-cooler", ResultString);
45-
makeArtifact(ResultString, "artifact.environment.Cooler", [RoomId], CoolerId);
45+
makeArtifact(ResultString, "artifact.environment.roomartifact.Cooler", [RoomId], CoolerId);
4646
turnOn [aid(CoolerId)];
4747
+cooling(RoomId); // add mental note to not re-turn on
4848
disposeArtifact(CoolerId).
@@ -51,7 +51,7 @@
5151

5252
+!turnOffCooling(RoomId) : cooling(RoomId)
5353
<- .concat(RoomId, "-cooler", ResultString);
54-
makeArtifact(ResultString, "artifact.environment.Cooler", [RoomId], CoolerId);
54+
makeArtifact(ResultString, "artifact.environment.roomartifact.Cooler", [RoomId], CoolerId);
5555
turnOff [aid(CoolerId)];
5656
-cooling(RoomId); // remove mental note to not re-turn off
5757
disposeArtifact(CoolerId).
@@ -61,7 +61,7 @@
6161
// Heating goal
6262
+!turnOnHeating(RoomId) : not heating(RoomId)
6363
<- .concat(RoomId, "-heater", ResultString);
64-
makeArtifact(ResultString, "artifact.environment.Heater", [RoomId], HeaterId);
64+
makeArtifact(ResultString, "artifact.environment.roomartifact.Heater", [RoomId], HeaterId);
6565
turnOn [aid(HeaterId)];
6666
+heating(RoomId); // add mental note to not re-turn on
6767
disposeArtifact(HeaterId).
@@ -70,7 +70,7 @@
7070

7171
+!turnOffHeating(RoomId) : heating(RoomId)
7272
<- .concat(RoomId, "-heater", ResultString);
73-
makeArtifact(ResultString, "artifact.environment.Heater", [RoomId], HeaterId);
73+
makeArtifact(ResultString, "artifact.environment.roomartifact.Heater", [RoomId], HeaterId);
7474
turnOff [aid(HeaterId)];
7575
-heating(RoomId); // remove mental note to not re-turn off
7676
disposeArtifact(HeaterId).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package artifact.environment.roomartifact;
10+
11+
import cartago.Artifact;
12+
13+
/**
14+
* Abstract class that represent the base class for a CArtAgO boundary artifacts placed inside a Room within
15+
* the Operating Block.
16+
*/
17+
public abstract class AbstractRoomArtifact extends Artifact {
18+
private String roomId;
19+
20+
/**
21+
* Initialize the artifact.
22+
* This method is called by Jason agents.
23+
* @param roomId the id of the room where the artifact is placed.
24+
*/
25+
protected void init(final String roomId) {
26+
this.roomId = roomId;
27+
}
28+
29+
/**
30+
* Obtain the roomId where the artifact is placed.
31+
* @return the roomId.
32+
*/
33+
public String getRoomId() {
34+
return this.roomId;
35+
}
36+
}

src/env/artifact/environment/Cooler.java src/env/artifact/environment/roomartifact/Cooler.java

+8-23
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* https://opensource.org/licenses/MIT.
77
*/
88

9-
package artifact.environment;
9+
package artifact.environment.roomartifact;
1010

11-
import cartago.Artifact;
1211
import cartago.OPERATION;
1312

1413
import java.util.logging.Logger;
@@ -17,30 +16,16 @@
1716
* CArtAgO artifact that is responsible for the communication with the hvac system of the operating block respect
1817
* to the cooling part.
1918
*/
20-
public class Cooler extends Artifact {
21-
private String roomId;
22-
23-
/**
24-
* Initialize the cooler artifact.
25-
* @param roomId the id of the room where the cooler is placed
26-
*/
27-
void init(final String roomId) {
28-
this.roomId = roomId;
29-
}
30-
31-
/**
32-
* Turn on the cooling system.
33-
*/
19+
public class Cooler extends AbstractRoomArtifact implements SwitchableArtifact {
20+
@Override
3421
@OPERATION
35-
void turnOn() {
36-
Logger.getLogger(Cooler.class.toString()).info("[" + this.roomId + "]" + " ON");
22+
public final void turnOn() {
23+
Logger.getLogger(Cooler.class.toString()).info("[" + this.getRoomId() + "]" + " ON");
3724
}
3825

39-
/**
40-
* Turn off the cooling system.
41-
*/
26+
@Override
4227
@OPERATION
43-
void turnOff() {
44-
Logger.getLogger(Cooler.class.toString()).info("[" + this.roomId + "]" + " OFF");
28+
public final void turnOff() {
29+
Logger.getLogger(Cooler.class.toString()).info("[" + this.getRoomId() + "]" + " OFF");
4530
}
4631
}

src/env/artifact/environment/Heater.java src/env/artifact/environment/roomartifact/Heater.java

+8-23
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* https://opensource.org/licenses/MIT.
77
*/
88

9-
package artifact.environment;
9+
package artifact.environment.roomartifact;
1010

11-
import cartago.Artifact;
1211
import cartago.OPERATION;
1312

1413
import java.util.logging.Logger;
@@ -17,30 +16,16 @@
1716
* CArtAgO artifact that is responsible for the communication with the hvac system of the operating block respect
1817
* to the heating part.
1918
*/
20-
public class Heater extends Artifact {
21-
private String roomId;
22-
23-
/**
24-
* Initialize the heater artifact.
25-
* @param roomId the id of the room where the heater is placed
26-
*/
27-
void init(final String roomId) {
28-
this.roomId = roomId;
29-
}
30-
31-
/**
32-
* Turn on the heating system.
33-
*/
19+
public class Heater extends AbstractRoomArtifact implements SwitchableArtifact {
20+
@Override
3421
@OPERATION
35-
void turnOn() {
36-
Logger.getLogger(Heater.class.toString()).info("[" + this.roomId + "]" + " ON");
22+
public final void turnOn() {
23+
Logger.getLogger(Heater.class.toString()).info("[" + this.getRoomId() + "]" + " ON");
3724
}
3825

39-
/**
40-
* Turn off the heating system.
41-
*/
26+
@Override
4227
@OPERATION
43-
void turnOff() {
44-
Logger.getLogger(Heater.class.toString()).info("[" + this.roomId + "]" + " OFF");
28+
public final void turnOff() {
29+
Logger.getLogger(Heater.class.toString()).info("[" + this.getRoomId() + "]" + " OFF");
4530
}
4631
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package artifact.environment.roomartifact;
10+
11+
/**
12+
* Interface that models a switchable artifact, that is an artifacts that offers method to turn it on and off.
13+
*/
14+
public interface SwitchableArtifact {
15+
/**
16+
* Turn the artifact on.
17+
*/
18+
void turnOn();
19+
20+
/**
21+
* Turn the artifact off.
22+
*/
23+
void turnOff();
24+
}

0 commit comments

Comments
 (0)