forked from lucaslouca/Trains
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.html
169 lines (169 loc) · 26.8 KB
/
README.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html><html><head><meta charset="utf-8"><title>README.md</title><style>.markdown-body hr:after,.markdown-body hr:before{display:table;content:""}.markdown-body ol,.markdown-body td,.markdown-body th,.markdown-body ul{padding:0}.markdown-body h1,.markdown-body h2{padding-bottom:.3em;border-bottom:1px solid #eee}@font-face{font-family:octicons-anchor;src:url(data:font/woff;charset=utf-8;base64,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)format('woff')}.markdown-body{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#333;overflow:hidden;font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;word-wrap:break-word}.markdown-body strong{font-weight:700}.markdown-body h1{margin:.67em 0}.markdown-body img{border:0}.markdown-body hr{-moz-box-sizing:content-box;box-sizing:content-box}.markdown-body *,.markdown-body img{-moz-box-sizing:border-box;box-sizing:border-box}.markdown-body input{color:inherit;margin:0;line-height:normal;font:13px/1.4 Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.markdown-body html input[disabled]{cursor:default}.markdown-body input[type=checkbox]{-moz-box-sizing:border-box;box-sizing:border-box;padding:0}.markdown-body a{background:0 0;color:#4183c4;text-decoration:none}.markdown-body a:active,.markdown-body a:hover{outline:0;text-decoration:underline}.markdown-body hr:after{clear:both}.markdown-body blockquote{margin:0}.markdown-body ol ol,.markdown-body ul ol{list-style-type:lower-roman}.markdown-body ol ol ol,.markdown-body ol ul ol,.markdown-body ul ol ol,.markdown-body ul ul ol{list-style-type:lower-alpha}.markdown-body dd{margin-left:0}.markdown-body .octicon{font:normal normal 16px octicons-anchor;line-height:1;display:inline-block;text-decoration:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-body .octicon-link:before{content:'\f05c'}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdown-body .anchor{position:absolute;top:0;left:0;display:block;padding-right:6px;padding-left:30px;margin-left:-30px}.markdown-body .anchor:focus{outline:0}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{position:relative;margin-top:1em;margin-bottom:16px;font-weight:700;line-height:1.4}.markdown-body h1 .octicon-link,.markdown-body h2 .octicon-link,.markdown-body h3 .octicon-link,.markdown-body h4 .octicon-link,.markdown-body h5 .octicon-link,.markdown-body h6 .octicon-link{display:none;color:#000;vertical-align:middle}.markdown-body h1:hover .anchor,.markdown-body h2:hover .anchor,.markdown-body h3:hover .anchor,.markdown-body h4:hover .anchor,.markdown-body h5:hover .anchor,.markdown-body h6:hover .anchor{padding-left:8px;margin-left:-30px;text-decoration:none}.markdown-body h1:hover .anchor .octicon-link,.markdown-body h2:hover .anchor .octicon-link,.markdown-body h3:hover .anchor .octicon-link,.markdown-body h4:hover .anchor .octicon-link,.markdown-body h5:hover .anchor .octicon-link,.markdown-body h6:hover .anchor .octicon-link{display:inline-block}.markdown-body h1{font-size:2.25em;line-height:1.2}.markdown-body h1 .anchor{line-height:1}.markdown-body h2{font-size:1.75em;line-height:1.225}.markdown-body h2 .anchor{line-height:1}.markdown-body h3{font-size:1.5em;line-height:1.43}.markdown-body h3 .anchor,.markdown-body h4 .anchor{line-height:1.2}.markdown-body h4{font-size:1.25em}.markdown-body h5 .anchor,.markdown-body h6 .anchor{line-height:1.1}.markdown-body h5{font-size:1em}.markdown-body h6{font-size:1em;color:#777}.markdown-body blockquote,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-top:0;margin-bottom:16px}.markdown-body hr{overflow:hidden;background:0 0;height:4px;padding:0;margin:16px 0;background-color:#e7e7e7;border:0 none}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-top:0;margin-bottom:0}.markdown-body li>p{margin-top:16px}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:700}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body blockquote{padding:0 15px;color:#777;border-left:4px solid #ddd}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body table{border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}.markdown-body table th{font-weight:700}.markdown-body table td,.markdown-body table th{padding:6px 13px;border:1px solid #ddd}.markdown-body table tr{background-color:#fff;border-top:1px solid #ccc}.markdown-body table tr:nth-child(2n){background-color:#f8f8f8}.markdown-body img{max-width:100%}.markdown-body code{border-radius:3px}.markdown-body .pl-c{color:#969896}.markdown-body .pl-c1,.markdown-body .pl-mdh,.markdown-body .pl-mm,.markdown-body .pl-mp,.markdown-body .pl-mr,.markdown-body .pl-s1 .pl-v,.markdown-body .pl-s3,.markdown-body .pl-sc,.markdown-body .pl-sv{color:#0086b3}.markdown-body .pl-e,.markdown-body .pl-en{color:#795da3}.markdown-body .pl-s1 .pl-s2,.markdown-body .pl-smi,.markdown-body .pl-smp,.markdown-body .pl-stj,.markdown-body .pl-vo,.markdown-body .pl-vpf{color:#333}.markdown-body .pl-ent{color:#63a35c}.markdown-body .pl-k,.markdown-body .pl-s,.markdown-body .pl-st{color:#a71d5d}.markdown-body .pl-pds,.markdown-body .pl-s1,.markdown-body .pl-s1 .pl-pse .pl-s2,.markdown-body .pl-sr,.markdown-body .pl-sr .pl-cce,.markdown-body .pl-sr .pl-sra,.markdown-body .pl-sr .pl-sre,.markdown-body .pl-src{color:#df5000}.markdown-body .pl-mo,.markdown-body .pl-v{color:#1d3e81}.markdown-body .pl-id{color:#b52a1d}.markdown-body .pl-ii{background-color:#b52a1d;color:#f8f8f8}.markdown-body .pl-sr .pl-cce{color:#63a35c;font-weight:700}.markdown-body .pl-ml{color:#693a17}.markdown-body .pl-mh,.markdown-body .pl-mh .pl-en,.markdown-body .pl-ms{color:#1d3e81;font-weight:700}.markdown-body .pl-mq{color:teal}.markdown-body .pl-mi{color:#333;font-style:italic}.markdown-body .pl-mb{color:#333;font-weight:700}.markdown-body .pl-md,.markdown-body .pl-mdhf{background-color:#ffecec;color:#bd2c00}.markdown-body .pl-mdht,.markdown-body .pl-mi1{background-color:#eaffea;color:#55a532}.markdown-body .pl-mdr{color:#795da3;font-weight:700}.markdown-body kbd{display:inline-block;padding:3px 5px;font:11px Consolas,"Liberation Mono",Menlo,Courier,monospace;line-height:10px;color:#555;vertical-align:middle;background-color:#fcfcfc;border:solid 1px #ccc;border-bottom-color:#bbb;border-radius:3px;box-shadow:inset 0 -1px 0 #bbb}.markdown-body .task-list-item{list-style-type:none}.markdown-body .task-list-item+.task-list-item{margin-top:3px}.markdown-body .task-list-item input{float:left;margin:.3em 0 .25em -1.6em;vertical-align:middle}.markdown-body :checked+.radio-label{z-index:1;position:relative;border-color:#4183c4}.hljs{display:block;overflow-x:auto;padding:.5em;background:#eee;-webkit-text-size-adjust:none}.hljs-annotation,.hljs-decorator,.hljs-header{color:#007}.hljs-attribute,.hljs-emphasis,.hljs-horizontal_rule,.hljs-link_url{color:#070}.hljs-emphasis{font-style:italic}.hljs-link_label,.hljs-string,.hljs-strong,.hljs-value,.scss .hljs-value .hljs-string{color:#d14}.hljs-strong{font-weight:700}.hljs-blockquote,.hljs-comment{color:#998;font-style:italic}.asciidoc .hljs-title,.hljs-function .hljs-title{color:#900}.hljs-class{color:#458}.hljs-constant,.hljs-hexcolor,.hljs-id,.hljs-pseudo{color:teal}.hljs-variable{color:#369}.hljs-bullet,.hljs-javadoc{color:#970}.hljs-doctype,.hljs-pi{color:#34b}.hljs-code,.hljs-number{color:#099}.hljs-important{color:red}.hljs-label,.smartquote{color:#970}.hljs-pragma,.hljs-preprocessor{color:#579}.hljs-keyword,.hljs-reserved,.scss .hljs-value{color:#000}.hljs-regexp{background-color:#fff0ff;color:#808}.hljs-symbol{color:#990073}.hljs-symbol .hljs-string{color:#a60}.hljs-tag{color:#070}.hljs-at_rule,.hljs-at_rule .hljs-keyword{color:#088}.hljs-at_rule .hljs-preprocessor{color:#808}.scss .hljs-attribute,.scss .hljs-tag{color:#339}.markdown-body {min-width: 200px;max-width: 790px;width: auto !important;margin: 0 auto;padding: 30px;}.markdown-body img {max-width: 100%;}</style></head><body><article class="markdown-body"><p>Author: Lucas Louca ([email protected])</p>
<h1 id="trains">Trains</h1>
<p>Commuter railroad service for the towns in Kiwiland. </p>
<h2 id="problem-statement">Problem Statement</h2>
<p>The local commuter railroad services a number of towns in Kiwiland. Because of monetary concerns, all of the tracks are 'one-way.' That is, a route from Kaitaia to Invercargill does not imply the existence of a route from Invercargill to Kaitaia. In fact, even if both of these routes do happen to exist, they are distinct and are not necessarily the same distance!</p>
<p>The purpose of this problem is to help the railroad provide its customers with information about the routes. In particular, you will compute the distance along a certain route, the number of different routes between two towns, and the shortest route between two towns.</p>
<p><strong>Input</strong> </p>
<blockquote>
<p>A directed graph where a node represents a town and an edge represents a route between two towns. The weighting of the edge represents the distance between the two towns. A given route will never appear more than once, and for a given route, the starting and ending town will not be the same town. </p>
<p>The towns are named using the first few letters of the alphabet from <code>A</code> to <code>E</code>. A route between two towns (<code>A</code> to <code>B</code>) with a distance of <code>5</code> is represented as <code>AB5</code>. A directed graph is represented by a list of routes, with each route as a separate line.</p>
</blockquote>
<p><strong>Available Actions</strong></p>
<ul>
<li>Compute the distance along a certain route. If no such route exists, output 'NO SUCH ROUTE'. Otherwise, follow the route as given; do not make any extra stops!</li>
<li>Compute the number of different routes between two towns.</li>
<li>Compute the shortest route between two towns.</li>
</ul>
<h2 id="example-input-output">Example Input & Output</h2>
<p>Below follows an example with input data, actions performed and expected output result.</p>
<p><strong>Sample Input:</strong></p>
<pre><code class="hljs nginx"><span class="hljs-title">AB5</span>
BC4
CD8
DC8
DE6
AD5
CE2
EB3
AE7
</code></pre><p><strong>Actions:</strong></p>
<pre><code class="hljs livecodeserver">The distance <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> route A-B-C.
The distance <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> route A-D.
The distance <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> route A-D-C.
The distance <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> route A-E-B-C-D.
The distance <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> route A-E-D.
The <span class="hljs-built_in">number</span> <span class="hljs-operator">of</span> trips starting <span class="hljs-keyword">at</span> C <span class="hljs-operator">and</span> ending <span class="hljs-keyword">at</span> C <span class="hljs-operator">with</span> <span class="hljs-operator">a</span> maximum <span class="hljs-operator">of</span> <span class="hljs-number">3</span> stops. In <span class="hljs-operator">the</span> sample data below, there are <span class="hljs-constant">two</span> such trips: C-D-C (<span class="hljs-number">2</span> stops). <span class="hljs-operator">and</span> C-E-B-C (<span class="hljs-number">3</span> stops).
The <span class="hljs-built_in">number</span> <span class="hljs-operator">of</span> trips starting <span class="hljs-keyword">at</span> A <span class="hljs-operator">and</span> ending <span class="hljs-keyword">at</span> C <span class="hljs-operator">with</span> exactly <span class="hljs-number">4</span> stops. In <span class="hljs-operator">the</span> sample data below, there are <span class="hljs-constant">three</span> such trips: A <span class="hljs-built_in">to</span> C (via B,C,D); A <span class="hljs-built_in">to</span> C (via D,C,D); <span class="hljs-operator">and</span> A <span class="hljs-built_in">to</span> C (via D,E,B).
The <span class="hljs-built_in">length</span> <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> shortest route (<span class="hljs-operator">in</span> terms <span class="hljs-operator">of</span> distance <span class="hljs-built_in">to</span> travel) <span class="hljs-built_in">from</span> A <span class="hljs-built_in">to</span> C.
The <span class="hljs-built_in">length</span> <span class="hljs-operator">of</span> <span class="hljs-operator">the</span> shortest route (<span class="hljs-operator">in</span> terms <span class="hljs-operator">of</span> distance <span class="hljs-built_in">to</span> travel) <span class="hljs-built_in">from</span> B <span class="hljs-built_in">to</span> B.
The <span class="hljs-built_in">number</span> <span class="hljs-operator">of</span> different routes <span class="hljs-built_in">from</span> C <span class="hljs-built_in">to</span> C <span class="hljs-operator">with</span> <span class="hljs-operator">a</span> distance <span class="hljs-operator">of</span> less than <span class="hljs-number">30.</span> In <span class="hljs-operator">the</span> sample data, <span class="hljs-operator">the</span> trips are: CDC, CEBC, CEBCDC, CDCEBC, CDEBC, CEBCEBC, CEBCEBCEBC.
</code></pre><p><strong>Expected Output:</strong></p>
<pre><code class="hljs nginx"><span class="hljs-title">Output</span> <span class="hljs-comment">#1: 9</span>
Output <span class="hljs-comment">#2: 5</span>
Output <span class="hljs-comment">#3: 13</span>
Output <span class="hljs-comment">#4: 22</span>
Output <span class="hljs-comment">#5: NO SUCH ROUTE</span>
Output <span class="hljs-comment">#6: 2</span>
Output <span class="hljs-comment">#7: 3</span>
Output <span class="hljs-comment">#8: 9</span>
Output <span class="hljs-comment">#9: 9</span>
Output <span class="hljs-comment">#10: 7</span>
</code></pre><h2 id="implementation">Implementation</h2>
<h2 id="requirenments">Requirenments</h2>
<ul>
<li>JDK 1.8</li>
<li>Gradle</li>
</ul>
<h2 id="run-junit-tests">Run JUnit Tests</h2>
<p>To run the existing JUnit tests using Gradle, execute the following commands</p>
<pre><code class="lang-shell hljs dos">$ <span class="hljs-built_in">cd</span> <span class="hljs-built_in">path</span>/to/Trains
$ gradle test
</code></pre>
<p><code>JUnit</code> tests are located under <code>/src/test/java</code>.</p>
<h2 id="properties">Properties</h2>
<p>Output messages are both availabe in English and German, depending on the system's default locale. The messages are available in the <code>trains.properties</code> and <code>trains_de.properties</code> file, respectively, and can be found under <code>/src/main/resources/com/lucaslouca/</code>.</p>
<h2 id="build">Build</h2>
<p>The project is a Gradle project. To build, open up your Terminal and fire up the following commands:</p>
<pre><code class="lang-shell hljs dos">$ <span class="hljs-built_in">cd</span> <span class="hljs-built_in">path</span>/to/Trains
$ gradle build
</code></pre>
<p>You should see a 'BUILD SUCCESSFUL' message when everything went well. When the build completed succesfully, the program will be named <code>Trains.jar</code> and can be found under <code>/build/libs/</code> in the <code>Trains</code> project directory.</p>
<h2 id="usage">Usage</h2>
<p>Run the program as follows:</p>
<pre><code class="lang-shell hljs stylus">$ java -jar Trains<span class="hljs-class">.jar</span> path/to/graph<span class="hljs-class">.txt</span> path/to/commands<span class="hljs-class">.txt</span>
</code></pre>
<p><strong>Example</strong></p>
<pre><code class="lang-shell hljs stylus">MacBook-Pro:Trains lucas$ java -jar build/libs/Trains<span class="hljs-class">.jar</span> ../../graph<span class="hljs-class">.txt</span> ../../commands<span class="hljs-class">.txt</span>
<span class="hljs-number">9</span>
<span class="hljs-number">5</span>
<span class="hljs-number">13</span>
<span class="hljs-number">22</span>
<span class="hljs-number">2</span>
<span class="hljs-number">3</span>
<span class="hljs-number">9</span>
<span class="hljs-number">9</span>
<span class="hljs-number">7</span>
<span class="hljs-number">7</span>
</code></pre>
<h2 id="import-project-with-an-ide">Import Project with an IDE</h2>
<h3 id="import-project-with-intellij-idea">Import Project with IntelliJ IDEA</h3>
<p>To import the project using Eclipse, do the following:</p>
<ul>
<li><code>File -> New -> Project from Existing Sources</code> from the main menu.</li>
<li>Browse to the project directory and click <code>OK</code>.</li>
<li>Select <code>Gradle</code> as build tool and click <code>Next</code>.</li>
<li>Specify <code>Gradle home</code> and make sure the <code>Gradle JVM</code> is set to version <code>1.8.x</code>.</li>
<li>Click <code>Finish</code>.</li>
</ul>
<h3 id="import-project-with-eclipse">Import Project with Eclipse</h3>
<p>To import the project using Eclipse, do the following:</p>
<ul>
<li><code>File -> Import... -> Gradle -> Gradle Project</code> from the main menu.</li>
<li>Click <code>Next</code>.</li>
<li>Click <code>Browse...</code> for the <code>Root Directory</code>.</li>
<li>Select and open the <code>Trains</code> project.</li>
<li>Click <code>Build Model</code>.</li>
<li>Select all projects.</li>
<li>Click <code>Finish</code>.</li>
</ul>
<p>Notes:</p>
<ul>
<li>You may need <a href="http://marketplace.eclipse.org/content/gradle-integration-eclipse-44" target="_blank">Gradle Integration for Eclipse</a></li>
<li>Make sure to replace <code>apply plugin: 'idea'</code> with <code>apply plugin: 'eclipse'</code> in the <code>build.gradle</code> file located in project's root directory.</li>
</ul>
<h3 id="javadoc">JavaDoc</h3>
<p><code>JavaDoc</code> can be found in the <code>JavaDoc</code> folder.</p>
<h2 id="important-classes-interfaces">Important Classes & Interfaces</h2>
<h3 id="-main-"><code>Main</code></h3>
<p>The <code>Main</code> class is the main entry point of the application. It contains a <code>main()</code> method whose signature looks like this</p>
<pre><code class="lang-java hljs"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String args[])</span>
</span></code></pre>
<p>which the runtime system calls when the program starts. The <code>main()</code> method then calls all the other methods required to run the application. It takes two arguments. The first argument is the path to the file containing the <em>Town Graph</em>, while the second argument points to the file containing the <em>commands</em> we want our application to execute.</p>
<h3 id="-lldirectedgraph-t-"><code>LLDirectedGraph<T></code></h3>
<p><code>LLDirectedGraph</code> represents a generic directed graph. It provides basic functionality for adding nodes and edges as well as methods for computing the shortest path (Dijkstra) and distance between nodes.</p>
<h3 id="-lltownmap-"><code>LLTownMap</code></h3>
<p>The <code>LLTownMap</code> interface represents a map that stores towns using a <code>LLDirectedGraph</code> underneath. It wraps the functionality of <code>LLDirectedGraph</code> and provides methods for accessing it using the town names.</p>
<h3 id="-lltown-"><code>LLTown</code></h3>
<p>Model representing a town.</p>
<h3 id="-llrailroadserviceimpl-"><code>LLRailRoadServiceImpl</code></h3>
<p><code>LLRailRoadServiceImpl</code> implements the <code>LLRailRoadService</code> interface. It makes use of <code>LLTownMap</code>. Although most of the functionality in <code>LLRailRoadServiceImpl</code> is cascaded to <code>LLTownMap</code>, the idea of providing <code>LLRailRoadServiceImpl</code>, is to separate the functionality between a service system and a map. That is, <code>LLRailRoadServiceImpl</code> could be expanded to support further functionality such as <code>requestClosingHours()</code> or <code>nextTrainDepartureTime()</code> without the need to modify the <code>LLTownMap</code>.</p>
<h3 id="-llcommand-"><code>LLCommand</code></h3>
<p>Interface defining a command that can be executed by calling its <code>execute()</code> method. A typical command would be calculating the distance of a route.</p>
<h3 id="-llcommandfactory-"><code>LLCommandFactory</code></h3>
<p>Interface that defines which functionality an <code>LLCommand</code> factory must provide.<code>LLCommandFactory</code> provides functionality for creating new commands that implement the <code>LLCommand</code> interface.</p>
<h3 id="-llrailroadservicecommandfactory-"><code>LLRailRoadServiceCommandFactory</code></h3>
<p>This class implements the <code>LLCommandFactory</code> interface. It provides methods for creating concrete command implementations of the abstract type <code>LLAbstractRailRoadServiceCommand</code>. The <code>LLRailRoadServiceCommandFactory</code> gets initialised with an <code>LLRailRoadService</code>, which it sets as <em>receiver</em> in <code>LLAbstractRailRoadServiceCommand</code> instances:</p>
<pre><code class="lang-java hljs">LLCommandFactory commandFactory = <span class="hljs-keyword">new</span> LLRailRoadServiceCommandFactory(service);
</code></pre>
<p>Classes inheriting from <code>LLAbstractRailRoadServiceCommand</code> are commands that implement the <code>LLCommand</code> interface but are specifically implemented for the <code>LLRailRoadService</code>. An example would be the <code>LLDistanceCommand</code>. </p>
<h3 id="-llcommandproccesor-"><code>LLCommandProccesor</code></h3>
<p><code>LLCommandProccesor</code> executes <code>LLCommand</code> commands. The <code>LLCommandProccesor</code> gets initialised with an <code>LLCommandFactory</code>.</p>
<pre><code class="lang-java hljs">LLCommandProccesor processor = <span class="hljs-keyword">new</span> LLCommandProccesor(commandFactory);
</code></pre>
<p>The <code>LLCommandFactory</code> will then be used by <code>LLCommandProccesor</code> to create <code>LLCommand</code> objects for a given input. <code>LLCommandProccesor</code> can take and execute a single command in the form of text:</p>
<pre><code class="lang-java hljs">String result = processor.run(<span class="hljs-string">"distance;A;D"</span>); <span class="hljs-comment">// compute distance between node 'A' and 'B'</span>
</code></pre>
<p>or run all commands contained in a text file:</p>
<pre><code class="lang-java hljs">String result = processor.runAll(<span class="hljs-string">"/Users/lucas/commands.txt"</span>); <span class="hljs-comment">// execute all commands in commands.txt</span>
</code></pre>
<h4 id="available-commands">Available commands</h4>
<ul>
<li><strong>distance;[TOWN 1];[TOWN 2]; ... ;[TOWN N]</strong> - Compute distance of route. Example: <pre><code class="hljs swift"><span class="hljs-built_in">distance</span>;<span class="hljs-type">A</span>;<span class="hljs-type">B</span>;<span class="hljs-type">C</span>
</code></pre></li>
<li><strong>count_routes_with_max_hops;[START TOWN];[DESTINATION TOWN];[MAX HOP COUNT]</strong> - Count routes with maximum number of hops. Example: <pre><code class="hljs mathematica">count_routes_with_max_hops;<span class="hljs-keyword">C</span>;<span class="hljs-keyword">C</span>;<span class="hljs-number">3</span>
</code></pre></li>
<li><strong>count_routes_with_hops;[START TOWN];[DESTINATION TOWN];[HOP COUNT]</strong> - Count routes with exact number of hops. Example: <pre><code class="hljs mathematica">count_routes_with_hops;A;<span class="hljs-keyword">C</span>;<span class="hljs-number">4</span>
</code></pre></li>
<li><strong>count_routes_with_max_distance;[START TOWN];[DESTINATION TOWN];[MAX DISTANCE]</strong> - Count routes with maximum distance. Example: <pre><code class="hljs mathematica">count_routes_with_max_distance;<span class="hljs-keyword">C</span>;<span class="hljs-keyword">C</span>;<span class="hljs-number">29</span>
</code></pre></li>
<li><strong>length_of_shortest_path;[START TOWN];[DESTINATION TOWN]</strong> - Compute length of shortest path between node. Example:<pre><code class="hljs mathematica">length_of_shortest_path;A;<span class="hljs-keyword">C</span>
</code></pre></li>
<li><strong>shortest_path;[START TOWN];[DESTINATION TOWN]</strong> - Compute shortest path between nodes. Example: <pre><code class="hljs">shortest_path;B;B
</code></pre></li>
</ul>
<h3 id="-llpropertyfactory-"><code>LLPropertyFactory</code></h3>
<p>Provides <code>static</code> methods for global access to the application's properties.</p>
<h2 id="sample-data">Sample Data</h2>
<p>Sample data for a <em>graph</em> and <em>commands</em> can be found under <code>/src/test/resources/</code>.</p>
</article></body></html>