2424
2525import java .awt .event .ActionEvent ;
2626import java .awt .event .ActionListener ;
27- import java .util .Iterator ;
27+ import java .util .Iterator ;import java . util . Locale ;
2828
2929public class DistrictTask implements ActionListener {
3030
@@ -56,15 +56,15 @@ public void actionPerformed(ActionEvent e) {
5656
5757 logger .info ("Reading " + DISTRICT_URL + " for current districts..." );
5858
59- JSONObject districts = districtsJSON .getJSONObject ("populationByDistrict" );
59+ JSONObject populationByDistrict = districtsJSON .getJSONObject ("populationByDistrict" );
6060 // iterate through each district
61- Iterator <String > keys = districts .keys ();
62- while (keys .hasNext ()) {
63- String districtFromJSON = keys .next ();
61+ Iterator <String > populationKeys = populationByDistrict .keys ();
62+ while (populationKeys .hasNext ()) {
63+ String districtFromJSON = populationKeys .next ();
6464 // if we do not have that district stored, create a new district object
6565 // and add it to the list
6666 if (!districtTracker .districts .containsKey (districtFromJSON )) {
67- int population = districts .getInt (districtFromJSON );
67+ int population = populationByDistrict .getInt (districtFromJSON );
6868 District district = new District (districtFromJSON );
6969 district .setPopulation (population );
7070 districtTracker .districts .put (districtFromJSON , district );
@@ -74,10 +74,23 @@ public void actionPerformed(ActionEvent e) {
7474 }
7575 // if we already have it saved, update the population
7676 District tempDistrict = districtTracker .districts .get (districtFromJSON );
77- int population = districts .getInt (districtFromJSON );
77+ int population = populationByDistrict .getInt (districtFromJSON );
7878 tempDistrict .setPopulation (population );
7979 }
8080 }
81+
82+ JSONObject statusByDistrict = districtsJSON .getJSONObject ("statusByDistrict" );
83+ // iterate through each district
84+ Iterator <String > statusKeys = statusByDistrict .keys ();
85+ while (statusKeys .hasNext ()) {
86+ String districtFromJSON = statusKeys .next ();
87+ // only update the status of districts we track
88+ if (districtTracker .districts .containsKey (districtFromJSON )) {
89+ String status = statusByDistrict .getString (districtFromJSON );
90+ District tempDistrict = districtTracker .districts .get (districtFromJSON );
91+ tempDistrict .setCurrentStatus (status );
92+ }
93+ }
8194 districtTracker .lastFetched = System .currentTimeMillis ();
8295 }
8396}
0 commit comments