diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1428c26..0856bb1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,10 @@ + - - @@ -32,13 +31,26 @@ - - + + + + + + + + + + + + + + + @@ -52,8 +64,8 @@ - - + + @@ -82,8 +94,8 @@ - - + + @@ -113,6 +125,7 @@ @@ -152,9 +165,6 @@ - - - @@ -193,6 +203,9 @@ + + + @@ -206,10 +219,10 @@ - @@ -690,6 +705,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1010,14 +1065,6 @@ - - - - - - - - @@ -1026,26 +1073,45 @@ - + - - + + - - + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/out/production/Textanalyse/com/structix/CommandLineInterface.class b/out/production/Textanalyse/com/structix/CommandLineInterface.class new file mode 100644 index 0000000..bf29723 Binary files /dev/null and b/out/production/Textanalyse/com/structix/CommandLineInterface.class differ diff --git a/out/production/Textanalyse/com/structix/Main.class b/out/production/Textanalyse/com/structix/Main.class index 501f126..ca89f90 100644 Binary files a/out/production/Textanalyse/com/structix/Main.class and b/out/production/Textanalyse/com/structix/Main.class differ diff --git a/src/com/structix/CommandLineInterface.java b/src/com/structix/CommandLineInterface.java new file mode 100644 index 0000000..4d65e75 --- /dev/null +++ b/src/com/structix/CommandLineInterface.java @@ -0,0 +1,145 @@ +package com.structix; + +import java.util.Scanner; + +/** + * Created by structix on 24.05.16. + */ +public class CommandLineInterface { + + private String cmds[]; + private String cmdseinzeln[]; + private String kommandos[] = {"-h", "-?", "--help", "--credits", "-w", "-v", "-b", "-ha"}; + private String hilfe[] = {"Hilfe", "Hilfe", "Hilfe", "Credits", "Anzahl der Wörter", "Anzahl der verwschiedenen Wörter", "Anzahl der Buchstaben", "Häufigkeit der Wörter"}; + String dateipfad = ""; + int dateipfadstelle = -1; + + public CommandLineInterface(String args[]) { + cmds = args; + verschiedenCmds(); + } + + public boolean argTest() { + boolean rueckgabe = false; + if (cmds.length > 0) { + rueckgabe = true; + } + return rueckgabe; + } + + private boolean gueltigkeit() { + int i = 0, dateizaehler = 0; + boolean ungueltig = false, vorhanden; + while (i < cmdseinzeln.length && !ungueltig) { + if (cmdseinzeln[i].substring(0, 1).equals("-") && cmdseinzeln[i].length() > 1) { + vorhanden = false; + for (int z = 0; z < kommandos.length; z++) { + if (cmdseinzeln[i].equals(kommandos[z])) { + vorhanden = true; + } + } + if (!vorhanden) { + ungueltig = true; + } + } else { + if (cmdseinzeln[i].matches("[a-zA-Z0-9]+.[a-zA-Z]{3}")) { + dateipfad = cmdseinzeln[i]; + dateizaehler++; + if (dateizaehler > 1) { + ungueltig = true; + } + } + } + + i++; + } + + return !ungueltig; + } + + public void ausfuehren() { + if (gueltigkeit()) { + + String datei = dateipfad; + if (datei.isEmpty()) { + System.out.println("Geben Sie einen Dateipfad an (relativ sowie absolut erlaubt): "); + Scanner eingabe = new Scanner(System.in); + datei = eingabe.nextLine(); + } + Analyse an = new Analyse(datei); + + for (int i = 0; i < cmdseinzeln.length; i++) { + if (i != dateipfadstelle) { + switch (cmdseinzeln[i]) { + case "-h": + case "-?": + case "--help": + System.out.println(hilfe()); + break; + case "--credits": + System.out.println(credits()); + break; + case "-w": + System.out.println("Anzahl der Wörter: " + an.laenge()); + break; + case "-v": + System.out.println("Anzahl der verschiedenen Wörter: " + an.verschiedenWoerter()); + break; + case "-b": + System.out.println("Anzahl der Buchstaben (inklusive Leerzeichen): " + an.anzBuchstabenMLeerzeichen()); + System.out.println("Anzahl der Buchstaben (ohne Leerzeichen): " + an.anzBuchstabenOLeerzeichen()); + break; + case "-ha": + System.out.println(an.haeufigkeit()); + break; + } + } + } + } else { + System.out.println("Ungültige Argumente"); + } + } + + + private String hilfe() { + String hilfeText = "Benutzung: Textanalyse \n"; + for (int i = 0; i < kommandos.length; i++) { + hilfeText += kommandos[i] + " - " + hilfe[i] + "\n"; + } + return hilfeText; + } + + private String credits() { + return "Muss noch geschrieben werden."; + } + + + + private void verschiedenCmds() { + String tempCmds[] = new String[cmds.length]; + boolean vorhanden; + int tbelegt = 0; + for (int i = 0; i < cmds.length; i++) { + vorhanden = false; + for (int z = 0; z < tempCmds.length; z++) { + if (cmds[i].equals(tempCmds[z])) { + vorhanden = true; + } + } + if (!vorhanden) { + tempCmds[tbelegt] = cmds[i]; + tbelegt++; + } + } + cmdseinzeln = new String[tbelegt]; + for (int i = 0; i < tbelegt; i++) { + cmdseinzeln[i] = tempCmds[i]; + + } + } + + + + + +} diff --git a/src/com/structix/Main.java b/src/com/structix/Main.java index df33d8e..2af51cc 100644 --- a/src/com/structix/Main.java +++ b/src/com/structix/Main.java @@ -27,23 +27,37 @@ package com.structix; * 16.05.16: 20:47 - 21:44 Uhr * 17.05.16: 11:59 - 12:37 Uhr * 20.05.16: 11:18 - 12:32 Uhr + * 24:05.16: 17:46 - 19:17 Uhr */ public class Main { public static void main(String[] args) { - //Menü Objekt wird erzeugt - Menu m = new Menu(); - //Auskommentieren, um einen Dateipfad einzugeben - m.debug(); - //m.dateipfad(); + CommandLineInterface cmd = new CommandLineInterface(args); - //Solange kein exit Befehl kommt, wird das Menü angezeigt. - //Es ist kein Schleifenkörper notwendig, da die Methode Hauptmenu - //schon einen Boolean Wert zurückgibt und damit bestimmt, ob die Bedingung wahr - //bleibt oder nicht - while (!m.hauptmenu()); - //Nachricht vor dem Beenden des Programms - System.out.println("Auf Wiedersehen!"); + if (!cmd.argTest()) { + + + //Menüteil wird ausgeführt, wenn keine Argumente übergeben werden + + //Menü Objekt wird erzeugt + Menu m = new Menu(); + //Auskommentieren, um einen Dateipfad einzugeben + m.debug(); + //m.dateipfad(); + + //Solange kein exit Befehl kommt, wird das Menü angezeigt. + //Es ist kein Schleifenkörper notwendig, da die Methode Hauptmenu + //schon einen Boolean Wert zurückgibt und damit bestimmt, ob die Bedingung wahr + //bleibt oder nicht + while (!m.hauptmenu()) ; + //Nachricht vor dem Beenden des Programms + System.out.println("Auf Wiedersehen!"); + } else { + + //Commandline Part + cmd.ausfuehren(); + + } } }