This project sorts number (long), word (string), or line (string) data by natural order or by occurrence count.
For example, given an input file src/main/resources/data/input.txt
:
2 6 4 3 5 44
1 11
2 7 4
2 7 4
This can sort the data along two dimensions: data type (long, word, line) and sort type (natural, by occurrence count).
- Data type = Long, Sort type = Natural. Output:
Total numbers: 14. Sorted data: 1 2 2 2 3 4 4 4 5 6 7 7 11 44
- Data type = Word, Sort type = Natural
Total words: 14. Sorted data: 1 11 2 2 2 3 4 4 4 44 5 6 7 7
- Data type = Line, Sort type = Natural
Total lines: 4. Sorted data: 1 11 2 6 4 3 5 44 2 7 4 2 7 4
- Data type = Long, Sort type = By Count
Total numbers: 14. 1: 1 time(s), 7% 3: 1 time(s), 7% 5: 1 time(s), 7% 6: 1 time(s), 7% 11: 1 time(s), 7% 44: 1 time(s), 7% 7: 2 time(s), 14% 2: 3 time(s), 21% 4: 3 time(s), 21%
- Data type = Word, Sort type = By Count
Total words: 14. 1: 1 time(s), 7% 11: 1 time(s), 7% 3: 1 time(s), 7% 44: 1 time(s), 7% 5: 1 time(s), 7% 6: 1 time(s), 7% 7: 2 time(s), 14% 2: 3 time(s), 21% 4: 3 time(s), 21%
- Data type = Line, Sort type = By Count
Total lines: 4. 1 11: 1 time(s), 25% 2 6 4 3 5 44: 1 time(s), 25% 2 7 4: 2 time(s), 50%
- Java 11 JDK
- Apache Maven (for building with included
pom.xml
)
To create a fat JAR with Maven Assembly, follow these steps:
- Use Maven Assembly to create a fat JAR:
mvn clean package assembly:single
From the project directory, run the fat JAR passing arguments to the 4 parameters:
-dataType
:long
,word
, orline
-sortingType
:natural
(default) orbyCount
-inputFile
(optional): Path to input text file from project directory. If the-inputFile
arg is not set, the app will read user input from STDIN.-outputFile
(optional): Path to output text file from project directory. This output file will contain app results. If the-outputFile
arg is not set, the app will print to STDOUT.
- Data type = Long, Sort type = Natural. Output:
java -jar target/sortingTool-jar-with-dependencies.jar \ -dataType long -sortingType natural \ -inputFile src/main/resources/data/input.txt \ -outputfile src/main/resources/data/output.txt
- Data type = Word, Sort type = Natural
java -jar target/sortingTool-jar-with-dependencies.jar \ -dataType word -sortingType natural \ -inputFile src/main/resources/data/input.txt \ -outputfile src/main/resources/data/output.txt
- Data type = Line, Sort type = Natural
java -jar target/sortingTool-jar-with-dependencies.jar \ -dataType line -sortingType natural \ -inputFile src/main/resources/data/input.txt \ -outputfile src/main/resources/data/output.txt
- Data type = Long, Sort type = By Count
java -jar target/sortingTool-jar-with-dependencies.jar \ -dataType long -sortingType byCount \ -inputFile src/main/resources/data/input.txt \ -outputfile src/main/resources/data/output.txt
- Data type = Word, Sort type = By Count
java -jar target/sortingTool-jar-with-dependencies.jar \ -dataType word -sortingType byCount \ -inputFile src/main/resources/data/input.txt \ -outputfile src/main/resources/data/output.txt
- Data type = Line, Sort type = By Count
java -jar target/sortingTool-jar-with-dependencies.jar \ -dataType line -sortingType byCount \ -inputFile src/main/resources/data/input.txt \ -outputfile src/main/resources/data/output.txt
This tool is also good at providing word counts for large text files such as books:
java -jar target/sortingTool-jar-with-dependencies.jar \
-dataType word -sortingType byCount \
-inputFile src/main/resources/data/alice_in_wonderland.txt \
-outputfile src/main/resources/data/output.txt
@LDNicolasMay - Work
Thanks to JetBrains Academy for the project!