1
1
package ie .gmit .sw .menu ;
2
2
3
+ import ie .gmit .sw .query .Query ;
4
+ import ie .gmit .sw .query .QueryFile ;
5
+ import ie .gmit .sw .query .QueryText ;
6
+
3
7
import java .io .File ;
4
8
import java .io .FileNotFoundException ;
9
+ import java .nio .file .Path ;
5
10
import java .util .Scanner ;
6
11
7
12
public class Menu {
8
- private String dataLoc ;
9
- private String queryFileLoc ;
13
+ private Path dataPath ;
14
+ private Query query ;
10
15
11
- public String getDataLoc () {
12
- return dataLoc ;
16
+ public Path getDataPath () {
17
+ return dataPath ;
13
18
}
14
19
15
- public void setDataLoc (String dataLoc ) throws FileNotFoundException {
16
- if (isInvalidFile (dataLoc )) {
17
- throw new FileNotFoundException ("Couldn't find file: \" " + dataLoc + "\" " );
18
- }
19
-
20
- this .dataLoc = dataLoc ;
20
+ public void setDataPath (Path dataPath ) {
21
+ this .dataPath = dataPath ;
21
22
}
22
23
23
- public String getQueryFileLoc () {
24
- return queryFileLoc ;
24
+ public Query getQuery () {
25
+ return query ;
25
26
}
26
27
27
- public void setQueryFileLoc (String queryFileLoc ) throws FileNotFoundException {
28
- if (isInvalidFile (queryFileLoc )) {
29
- throw new FileNotFoundException ("Couldn't find file: \" " + queryFileLoc + "\" " );
30
- }
31
-
32
- this .queryFileLoc = queryFileLoc ;
28
+ public void setQuery (Query query ) {
29
+ this .query = query ;
33
30
}
34
31
35
32
public void display () {
@@ -42,16 +39,26 @@ public void display() {
42
39
43
40
do {
44
41
try {
45
- if (dataLoc == null ) {
42
+ if (dataPath == null ) {
46
43
System .out .print ("$ Enter WiLi data location: " );
47
44
input = console .nextLine ().trim ();
48
- setDataLoc (input );
45
+
46
+ if (isFile (input )) {
47
+ setDataPath (Path .of (input ));
48
+ } else {
49
+ throw new FileNotFoundException ("That file does not exist" );
50
+ }
49
51
}
50
52
51
- if (queryFileLoc == null ) {
52
- System .out .print ("$ Enter the query file location : " );
53
+ if (query == null ) {
54
+ System .out .print ("$ Enter the query text/ file: " );
53
55
input = console .nextLine ().trim ();
54
- setQueryFileLoc (input );
56
+
57
+ if (isFile (input )) {
58
+ setQuery (new QueryFile (Path .of (input )));
59
+ } else {
60
+ setQuery (new QueryText (input ));
61
+ }
55
62
}
56
63
57
64
break ;
@@ -61,7 +68,7 @@ public void display() {
61
68
} while (true );
62
69
}
63
70
64
- private static boolean isInvalidFile (String path ) {
65
- return ! new File (path ).isFile ();
71
+ private static boolean isFile (String filename ) {
72
+ return new File (filename ).isFile ();
66
73
}
67
74
}
0 commit comments