summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-14 15:32:29 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-14 15:32:40 +0200
commit709c04082ffdcc30c93cd13e7aef06eab1f1f428 (patch)
treec4ac4347da7e63b295ae4d563f525b902ac67d11 /src
parent4e6c764a4f143b6055fd357d444efbbd8237b91e (diff)
downloadGoldfarmer-709c04082ffdcc30c93cd13e7aef06eab1f1f428.tar.gz
Fixups
Diffstat (limited to 'src')
-rw-r--r--src/main/FarmShell.java37
-rw-r--r--src/main/Main.java14
2 files changed, 20 insertions, 31 deletions
diff --git a/src/main/FarmShell.java b/src/main/FarmShell.java
index 82478ec..c41ad6b 100644
--- a/src/main/FarmShell.java
+++ b/src/main/FarmShell.java
@@ -1,43 +1,24 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
package main;
import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;
-import java.util.Set;
/**
*
* @author s123188
*/
public class FarmShell {
-
+
private final Scanner scanner = new Scanner(System.in);
-
+
Analyzor analyzor;
-
- /*
+
private void printPrompt() {
- if (stream_cached == null) {
- // "dollars are worthless"
- System.out.print("$ ");
- } else if (stream_cached.isValid()) {
- // "we make money now by receiving tweets"
- System.out.print("€ ");
- } else {
- // "we previously made money, but not anymore"
- System.out.print("ƒ ");
- }
+ System.out.print("$ ");
}
-*/
+
/**
* Processes commands from stdin until the exit command is received or EOF.
*/
@@ -46,7 +27,7 @@ public class FarmShell {
+ "or 'exit' to leave. '.' repeats the previous interactive "
+ "command.");
// print prompt for reading first command
- //printPrompt();
+ printPrompt();
String lastLine = "";
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
@@ -62,7 +43,7 @@ public class FarmShell {
lastLine = line;
}
// print prompt for reading next line
- //printPrompt();
+ printPrompt();
}
// prevent corrupted compressed files when exiting without a command
throw new NoSuchElementException();
@@ -88,7 +69,7 @@ public class FarmShell {
public boolean execute(String[] args) {
//make a new Analyzor
analyzor = new Analyzor();
-
+
try {
Command command = Command.fromString(args[0]);
String[] params = Arrays.copyOfRange(args, 1, args.length);
@@ -107,7 +88,7 @@ public class FarmShell {
}
enum Command {
-
+
query("make a query to the database; needed to do analysis", 1),
filterbots("marks all users as bot or not"),
sentiment("analyzes all tweets on positivity (about a brand)"),
diff --git a/src/main/Main.java b/src/main/Main.java
index 1ba2579..1766332 100644
--- a/src/main/Main.java
+++ b/src/main/Main.java
@@ -4,6 +4,7 @@ import database.ConnectionBuilder;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
@@ -26,6 +27,7 @@ public class Main {
return;
}
}
+ private String[] leftover_params;
public Main(String[] args) {
cb = new ConnectionBuilder()
@@ -37,13 +39,16 @@ public class Main {
try {
FarmShell shell = new FarmShell();
- shell.execute(args);
+ if (leftover_params != null && leftover_params.length > 0) {
+ shell.execute(leftover_params);
+ }
+ shell.process_forever();
} catch (IllegalArgumentException ex) {
System.err.println(ex.getMessage());
System.exit(1);
}
}
-
+
private void parseGlobalOptions(String[] args)
throws IllegalArgumentException {
/* parse global options */
@@ -60,10 +65,13 @@ public class Main {
cb.setDbName(getArg(args, ++i, "--dbname"));
} else if (args[i].startsWith("-")) {
throw new IllegalArgumentException("Invalid option: " + args[i]);
+ } else {
+ leftover_params = Arrays.copyOfRange(args, i, args.length);
+ break;
}
}
}
-
+
private String getArg(String[] params, int index, String name) {
if (index >= params.length) {
System.err.println("Missing argument for parameter " + name);