plus Code

This commit is contained in:
Michael Hayder 2025-05-22 13:51:39 +02:00
parent b9462fcd2c
commit 14a92b38ec
4 changed files with 243 additions and 0 deletions

108
pom.xml Normal file
View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.altimate</groupId>
<artifactId>glt</artifactId>
<version>1.0-SNAPSHOT</version>
<name>glt</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Optionally: parameterized tests support -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<mainClass>net.altimate.App</mainClass>
<arguments>
<argument>"-f"</argument>
<argument>"/tmp/1.txt"</argument>
<argument>"-w"</argument>
<argument>"5"</argument>
<argument>"-C"</argument>
<argument>"_"</argument>
</arguments>
</configuration>
</plugin>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -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!");
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}