Skip to content

Commit a11eda2

Browse files
Ty CoghlanTy Coghlan
Ty Coghlan
authored and
Ty Coghlan
committed
Visual src documentation and a screenshot
1 parent e6d8986 commit a11eda2

34 files changed

+924
-0
lines changed

Visual/Building.java

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package Visual;
2+
3+
/**
4+
* Represents a building.
5+
*/
6+
public interface Building extends Comparable<Building>{
7+
/**
8+
* @return the name of the building
9+
*/
10+
String name();
11+
12+
/**
13+
* An int that represents the building itself
14+
*
15+
* @return the buildling id
16+
*/
17+
int buildingID();
18+
19+
/**
20+
* Some buildings have more than one site id
21+
*
22+
* @return the int that represents the value of the meter id
23+
*/
24+
Site[] sites();
25+
26+
/**
27+
* Returns the carbon footprint of the building
28+
*
29+
* @return the footprint
30+
*/
31+
int footprint();
32+
33+
/**
34+
* Returns the perimeter of the buildling
35+
*
36+
* @return the perimeter
37+
*/
38+
int perimeter();
39+
40+
/**
41+
* Returns the area of the building
42+
*
43+
* @return the area
44+
*/
45+
double area();
46+
47+
/**
48+
* Returns the latitude and longitude of the center of the building
49+
*
50+
* @return the centroid
51+
*/
52+
LatLong centroid();
53+
54+
/**
55+
* Returns the latitude and longitude points that make up the corners of the buildling
56+
*
57+
* @return the outline
58+
*/
59+
LatLong[] outline();
60+
61+
/**
62+
* Returns the current time stamp of the building
63+
*
64+
* @return the current unix time stamp
65+
*/
66+
long currentTime();
67+
68+
/**
69+
* Changes the currentTime of the building to the given unixTime
70+
* @param time the nex unix time of the building
71+
*/
72+
void changeTime(long time);
73+
74+
/**
75+
* The current wattage of electricity the building is using.
76+
*
77+
* @return the wattage
78+
*/
79+
double currentWattage();
80+
81+
/**
82+
* The wattage of electricity the building was using at the specified time
83+
*
84+
* @return the wattage at the specified time
85+
* @param time
86+
*/
87+
double wattage(long time);
88+
}

Visual/BuildingBuilder.java

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package Visual;
2+
3+
import java.util.HashMap;
4+
import java.util.Objects;
5+
6+
/**
7+
* A helper class used to create an instance of a Building, allows for incremental
8+
* building
9+
*/
10+
public class BuildingBuilder {
11+
private String name;
12+
private int bID = -1;
13+
private Site[] sites;
14+
private int footprint;
15+
private int perimeter;
16+
private double area;
17+
private LatLong centroid;
18+
private LatLong[] outline;
19+
private long currentTime;
20+
21+
/**
22+
* Creates the initial, empty builder
23+
*/
24+
public BuildingBuilder() {}
25+
26+
/**
27+
* Sets the name
28+
* @param name the name of the building
29+
* @return this builder
30+
*/
31+
public BuildingBuilder name(String name) {
32+
this.name = name;
33+
return this;
34+
}
35+
36+
/**
37+
* Sets the building ID
38+
* @param bID the id of the building
39+
* @return this builder
40+
*/
41+
public BuildingBuilder bID(int bID) {
42+
this.bID = bID;
43+
return this;
44+
}
45+
46+
/**
47+
* Sets the sites
48+
* @param sites the electric meters of the building
49+
* @return this builder
50+
*/
51+
public BuildingBuilder sites(Site[] sites) {
52+
this.sites = sites;
53+
return this;
54+
}
55+
56+
/**
57+
* Sets the footprint
58+
* @param footprint the footprint of the building
59+
* @return this builder
60+
*/
61+
public BuildingBuilder footprint(int footprint) {
62+
this.footprint = footprint;
63+
return this;
64+
}
65+
66+
/**
67+
* Sets the perimeter of the building
68+
* @param perimeter the perimeter of the building
69+
* @return this builder
70+
*/
71+
public BuildingBuilder perimeter(int perimeter) {
72+
this.perimeter = perimeter;
73+
return this;
74+
}
75+
76+
/**
77+
* Sets the perimeter of the building
78+
* @param area the area of the building
79+
* @return this builder
80+
*/
81+
public BuildingBuilder area(double area) {
82+
this.area = area;
83+
return this;
84+
}
85+
86+
/**
87+
* Sets the centroid of the building
88+
* @param centroid the latitude and longitude of the center point of the building
89+
* @return this builder
90+
*/
91+
public BuildingBuilder centroid(LatLong centroid) {
92+
this.centroid = centroid;
93+
return this;
94+
}
95+
96+
/**
97+
* Sets the outline of the building
98+
* @param outline the latitude and longitude of the outlines of the building
99+
* @return
100+
*/
101+
public BuildingBuilder outline(LatLong[] outline) {
102+
this.outline = outline;
103+
return this;
104+
}
105+
106+
/**
107+
* Sets the current time for the building
108+
* @param currentTime the current time in unix
109+
* @return this builder
110+
*/
111+
public BuildingBuilder currentTime(long currentTime) {
112+
this.currentTime = currentTime;
113+
return this;
114+
}
115+
116+
/**
117+
* Returns the current building ID for identification purposes
118+
* @return the current building ID
119+
* @throws IllegalStateException if this is called before an ID has been set
120+
*/
121+
public int identify() {
122+
if (bID == -1) {
123+
throw new IllegalStateException("Builder has not been given an id yet!");
124+
}
125+
return bID;
126+
}
127+
128+
/**
129+
* Builds a building from the given parameters.
130+
* @return the building
131+
* @throws NullPointerException if any of the params have not been set
132+
*/
133+
public Building build() {
134+
Objects.requireNonNull(this.name, "Name not Initialized");
135+
Objects.requireNonNull(this.sites, "Sites not Initialized");
136+
Objects.requireNonNull(this.centroid, "Centroid not Initialized");
137+
Objects.requireNonNull(this.outline, "Outline not Initialized");
138+
return new BuildingImpl(this.name, this.bID, this.sites, this.footprint, this.perimeter,
139+
this.area, this.centroid, this.outline, this.currentTime);
140+
}
141+
}

Visual/BuildingImpl.java

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package Visual;
2+
3+
import java.util.Arrays;
4+
import java.util.Objects;
5+
6+
/**
7+
* An implementation of the building class that reads data from CVS readers.
8+
*/
9+
public class BuildingImpl implements Building {
10+
11+
private String name;
12+
private int bID;
13+
private Site[] sites;
14+
private int footprint;
15+
private int perimeter;
16+
private double area;
17+
private LatLong centroid;
18+
private LatLong[] outline;
19+
private long currentTime;
20+
21+
22+
/**
23+
* A public constructor that constructs the building from the parameters
24+
* @param name the name of the building
25+
* @param bID the id of the building
26+
* @param sites the electric meters of the building
27+
* @param footprint the footprint of the building
28+
* @param perimeter the perimeter of the building
29+
* @param area the area of the building
30+
* @param centroid the center of the building in latitude/longitude
31+
* @param outline the outline of the building in latitude/longitude
32+
* @param currentTime the current time of the building
33+
* @throws NullPointerException if any of the parameters have not been set.
34+
*/
35+
public BuildingImpl(String name, int bID, Site[] sites, int footprint, int perimeter,
36+
double area, LatLong centroid, LatLong[] outline, long currentTime)
37+
{
38+
Objects.requireNonNull(name, "Name not Initialized");
39+
Objects.requireNonNull(sites, "Sites not Initialized");
40+
Objects.requireNonNull(centroid, "Centroid not Initialized");
41+
Objects.requireNonNull(outline, "Outline not Initialized");
42+
Objects.requireNonNull(currentTime, "Current Time not Initialized");
43+
this.name = name;
44+
this.bID = bID;
45+
this.sites = sites;
46+
this.footprint = footprint;
47+
this.perimeter = perimeter;
48+
this.area = area;
49+
this.centroid = centroid;
50+
this.outline = outline;
51+
this.currentTime = currentTime;
52+
}
53+
54+
@Override
55+
public String name() {
56+
return name;
57+
}
58+
59+
@Override
60+
public int buildingID() {
61+
return bID;
62+
}
63+
64+
@Override
65+
public Site[] sites() {
66+
return sites;
67+
}
68+
69+
@Override
70+
public int footprint() {
71+
return footprint;
72+
}
73+
74+
@Override
75+
public int perimeter() {
76+
return perimeter;
77+
}
78+
79+
@Override
80+
public double area() {
81+
return area;
82+
}
83+
84+
@Override
85+
public LatLong centroid() {
86+
return centroid;
87+
}
88+
89+
@Override
90+
public LatLong[] outline() {
91+
return outline;
92+
}
93+
94+
@Override
95+
public long currentTime() {
96+
return currentTime;
97+
}
98+
99+
@Override
100+
public void changeTime(long time) {
101+
long roundedTime = SiteImpl.roundToNearestTime(1386547200, 1418168700, 900, time);
102+
currentTime = roundedTime;
103+
}
104+
105+
@Override
106+
public double currentWattage() {
107+
return wattage(currentTime);
108+
}
109+
110+
@Override
111+
public double wattage(long time) {
112+
int siteNum = sites.length;
113+
double total = 0;
114+
if (siteNum < 1) {
115+
return 0;
116+
}
117+
for (Site s : sites) {
118+
total += s.wattage(time);
119+
}
120+
return total / siteNum;
121+
}
122+
123+
@Override
124+
public String toString() {
125+
return "Visual.Building: [" + name + ", " + Integer.toString(bID) + "], Sites: " +
126+
Arrays.toString(sites) + ", Specs: [" + "footprint: " + Integer.toString(footprint) +
127+
", perimeter: " + Integer.toString(perimeter) + ", area: " + Double.toString(area) +
128+
"] Coordinates: " + centroid.toString() + ", " + Arrays.toString(outline) +
129+
", Data: [" + Long.toString(currentTime) + ", " + Double.toString(currentWattage()) +
130+
"Watts]";
131+
}
132+
133+
@Override
134+
public int compareTo(Building other) {
135+
return Double.compare(currentWattage(), other.currentWattage());
136+
}
137+
}

0 commit comments

Comments
 (0)