diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5e311cf --- /dev/null +++ b/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + net.altimate + glt + 1.0-SNAPSHOT + + glt + + http://www.example.com + + + UTF-8 + 21 + + + + + + org.junit + junit-bom + 5.11.0 + pom + import + + + + + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.junit.jupiter + junit-jupiter-params + test + + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.3.0 + + net.altimate.App + + "-f" + "/tmp/1.txt" + "-w" + "5" + "-C" + "_" + + + + + + + maven-clean-plugin + 3.4.0 + + + + maven-resources-plugin + 3.3.1 + + + maven-compiler-plugin + 3.13.0 + + + maven-surefire-plugin + 3.3.0 + + + maven-jar-plugin + 3.4.2 + + + maven-install-plugin + 3.1.2 + + + maven-deploy-plugin + 3.1.2 + + + + maven-site-plugin + 3.12.1 + + + maven-project-info-reports-plugin + 3.6.1 + + + + + diff --git a/src/main/java/net/altimate/App.java b/src/main/java/net/altimate/App.java new file mode 100644 index 0000000..1d3715f --- /dev/null +++ b/src/main/java/net/altimate/App.java @@ -0,0 +1,42 @@ +package net.altimate; + +/** + * Hello world! + */ +public class App { + public static void main(String[] args) { + + String fileName = ""; + int eachWord = 0; + boolean printComplete = false; + char replaceWith = ' '; + + for (int i = 0; i < args.length; i++) { + String tmpString = args[i].replace("\"", ""); + + if (tmpString.equals("-f")) { + fileName = args[i + 1].replace("\"", ""); + } + if (tmpString.equals("-w")) { + eachWord = Integer.parseInt(args[i + 1].replace("\"", "")); + } + if (tmpString.equals("-c")) { + printComplete = true; + } + if (tmpString.equals("-C")) { + replaceWith = args[i + 1].replace("\"", "").charAt(0); + } + } + + + System.out.println("filename: " + fileName + " eachWord: " + eachWord + " print: " + printComplete + " replace: " + replaceWith); + + + GLTParser gltParser = new GLTParser(); + //gltParser.getArgs(args); + //System.out.println(gltParser.readFile("/tmp/1.txt")); + gltParser.printText(gltParser.readFile(fileName), eachWord, replaceWith); + //System.out.println("Hello World!"); + + } +} diff --git a/src/main/java/net/altimate/GLTParser.java b/src/main/java/net/altimate/GLTParser.java new file mode 100644 index 0000000..bcf9a10 --- /dev/null +++ b/src/main/java/net/altimate/GLTParser.java @@ -0,0 +1,74 @@ +package net.altimate; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Scanner; + +public class GLTParser { + + + + public String readFile(String fileName) { + + StringBuilder builder = new StringBuilder(); + try (BufferedReader buffer = new BufferedReader( + new FileReader(fileName))) { + + String str; + + while ((str = buffer.readLine()) != null) { + builder.append(str).append("\n"); + } + } + + catch (IOException e) { + e.printStackTrace(); + } + + return builder.toString(); + } + + public void printText(String completeText, int eachWord, char replaceWith ) { + + String[] allWords = completeText.split("\\s+" ); + + + for (int i=0; i < allWords.length; i++){ + + //System.out.println(i); + //System.out.println(allWords[i]); + + if (i % eachWord == 0) { + System.out.printf(allWords[i] + " "); + + } else { + + //System.out.println("i: " + i); + //System.out.println("eachWord: " + eachWord); + + for (int j=0; j < allWords[i].length(); j++) { + System.out.print(replaceWith); + } + System.out.printf(" "); + + } + + + //System.out.println(word); + + } + //System.out.println("Splits: " + allWords.length); + //System.out.println(Text); + } + +} + + diff --git a/src/test/java/net/altimate/AppTest.java b/src/test/java/net/altimate/AppTest.java new file mode 100644 index 0000000..6711a84 --- /dev/null +++ b/src/test/java/net/altimate/AppTest.java @@ -0,0 +1,19 @@ +package net.altimate; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** + * Unit test for simple App. + */ +public class AppTest { + + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() { + assertTrue(true); + } +}