-
Notifications
You must be signed in to change notification settings - Fork 0
/
Building.java
52 lines (43 loc) · 1.43 KB
/
Building.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Comparator;
/**
* The Building class stores building metadata and implements Comparable interface
*/
public class Building implements Comparable<Building> {
private int buildingNo;
private int executedTime;
private int totalTime;
public Building(int buildingNo, int totalTime) {
this.buildingNo = buildingNo;
this.executedTime = 0;
this.totalTime = totalTime;
}
//copy constructor to maintain object integrity while swapping
public Building (Building building) {
this.buildingNo = building.buildingNo;
this.executedTime = building.executedTime;
this.totalTime = building.totalTime;
}
//checks if building has completed execution
public boolean hasCompletedExecution() {
return (totalTime - executedTime == 0);
}
public int getBuildingNo() {
return buildingNo;
}
public int getTotalTime() {
return totalTime;
}
public int getExecutedTime() {
return executedTime;
}
public void setExecutedTime(int executedTime) {
this.executedTime = executedTime;
}
//compare objects on executed time and then on building no while executing min heap operations
@Override
public int compareTo(Building o) {
return Comparator.comparingInt(Building::getExecutedTime)
.thenComparingInt(Building::getBuildingNo)
.compare(this, o);
}
}