16
16
import java .util .Map ;
17
17
import java .util .NoSuchElementException ;
18
18
19
+ import static java .lang .System .Logger .Level .INFO ;
19
20
import static java .util .Objects .requireNonNull ;
20
21
21
22
/**
22
23
* Repository interface implementation that loads a metro map from a JSON file
23
24
*/
24
25
@ Repository
25
26
public class MetroRepositoryJson implements MetroRepository , InitializingBean {
27
+ private static final System .Logger LOGGER = System .getLogger (MetroRepositoryJson .class .getName ());
26
28
27
29
private static final TypeReference <Map <String , Deque <Station >>> SCHEMA_TYPE = new TypeReference <>() {
28
30
};
@@ -37,7 +39,9 @@ public class MetroRepositoryJson implements MetroRepository, InitializingBean {
37
39
38
40
@ Override
39
41
public void afterPropertiesSet () throws Exception {
42
+ LOGGER .log (INFO , "Loading metro schema from file: „{0}“" , schemaPath );
40
43
metroMap = new JsonMapper ().readValue (schemaPath .toFile (), SCHEMA_TYPE );
44
+ LOGGER .log (INFO , "Metro map successfully loaded." );
41
45
}
42
46
43
47
@ Override
@@ -51,6 +55,7 @@ private Deque<Station> getLine(String line) {
51
55
52
56
@ Override
53
57
public void addHead (String line , String station , int time ) {
58
+ LOGGER .log (INFO , "Executing command: add-head „{0}“ „{1}“ „{2}“" , line , station , time );
54
59
var metroLine = getLine (line );
55
60
var metroStation = new Station (station , time );
56
61
@@ -66,6 +71,7 @@ public void addHead(String line, String station, int time) {
66
71
67
72
@ Override
68
73
public void append (String line , String station , int time ) {
74
+ LOGGER .log (INFO , "Executing command: append „{0}“ „{1}“ „{2}“" , line , station , time );
69
75
var metroLine = getLine (line );
70
76
var metroStation = new Station (station , time );
71
77
@@ -81,11 +87,14 @@ public void append(String line, String station, int time) {
81
87
82
88
@ Override
83
89
public void remove (String line , String station ) {
90
+ LOGGER .log (INFO , "Executing command: remove „{0}“ „{1}“" , line , station );
84
91
throw new UnsupportedOperationException ("This operation has not yet been implemented" );
85
92
}
86
93
87
94
@ Override
88
95
public void connect (String sourceLine , String sourceStation , String targetLine , String targetStation ) {
96
+ LOGGER .log (INFO , "Executing command: connect „{0}“ „{1}“ „{2}“ „{3}“" ,
97
+ sourceLine , sourceStation , targetLine , targetStation );
89
98
var source = getStation (sourceLine , sourceStation );
90
99
var target = getStation (targetLine , targetStation );
91
100
source .transfer ().add (new StationId (targetLine , targetStation ));
0 commit comments