Skip to content

Commit

Permalink
Replaced instances of println with printf
Browse files Browse the repository at this point in the history
  • Loading branch information
Meeples10 committed Dec 14, 2023
1 parent 79d73a9 commit 2f7cc4b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
21 changes: 8 additions & 13 deletions src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ public static void main(String[] args) {
} catch(IOException e) {
e.printStackTrace();
}
Main.println("Save statistics: " + saveStatistics + "\nGenerate HTML table: " + generateTable
+ (generateTable
? ("\nTable template: " + (tableTemplatePath.equals("") ? "(none)" : tableTemplatePath))
: "")
+ "\nRegion version: " + selectedVersion + "\nModernize block IDs: " + modernizeIDs + "\nBlock IDs: "
+ BLOCK_NAMES.size() + "\nBlock IDs to merge: " + BLOCKS_TO_MERGE.size() + "\nInput: "
+ inputFile.getPath() + "\nOutput prefix: " + (outputPrefix.equals("") ? "(default)" : outputPrefix)
+ "\n--------------------------------");
Main.printf("Save statistics: %b\nGenerate HTML table: %b%s\nRegion version: %s\nModernize block IDs: %b"
+ "\nBlock IDs: %d\nBlock IDs to merge: %d\nInput: %s\nOutput prefix: %s\n--------------------------------\n",
saveStatistics, generateTable,
(generateTable ? ("\nTable template: " + (tableTemplatePath.equals("") ? "(none)" : tableTemplatePath))
: ""),
selectedVersion, modernizeIDs, BLOCK_NAMES.size(), BLOCKS_TO_MERGE.size(), inputFile.getPath(),
(outputPrefix.equals("") ? "(default)" : outputPrefix));
RegionAnalyzer analyzer;
try {
analyzer = selectedVersion.getAnalyzerInstance();
Expand All @@ -85,7 +84,7 @@ public static void main(String[] args) {
System.exit(1);
}
analyzer.run(inputFile);
Main.println("Completed after " + millisToHMS(System.currentTimeMillis() - analyzer.getStartTime()));
Main.printf("Completed after %s\n", millisToHMS(System.currentTimeMillis() - analyzer.getStartTime()));
}

private static CommandSpec createCommandSpec() {
Expand Down Expand Up @@ -284,10 +283,6 @@ public static void print(Object s) {
if(!silent) System.out.print(s);
}

public static void println(Object s) {
if(!silent) System.out.println(s);
}

public static void printf(String format, Object... args) {
if(!silent) System.out.printf(format, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ public void run(File input) {
}

duration = System.currentTimeMillis() - getStartTime();
Main.println("Completed analysis in " + Main.millisToHMS(duration));
Main.printf("Completed analysis in %s\n", Main.millisToHMS(duration));

long totalBlocks = 0L;
for(String key : blockCounter.keySet()) {
totalBlocks += blockCounter.get(key);
}
Main.println("--------------------------------\n" + blockCounter.size() + " unique blocks\n" + totalBlocks
+ " blocks total\n--------------------------------");
Main.printf(
"--------------------------------\n%d unique blocks\n%d blocks total\n--------------------------------\n",
blockCounter.size(), totalBlocks);

Main.print("Sorting data... ");
heightCounter = heightCounter.entrySet().stream().sorted(Map.Entry.comparingByKey(new Comparator<String>() {
Expand All @@ -81,7 +82,7 @@ public int compare(String arg0, String arg1) {
return Long.compare(blockCounter.get(arg1), blockCounter.get(arg0));
}
})).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
Main.println("Done");
Main.print("Done\n");

double totalExcludingAir = (double) (totalBlocks - (blockCounter.containsKey("0") ? blockCounter.get("0") : 0)
- (blockCounter.containsKey("minecraft:air") ? blockCounter.get("minecraft:air") : 0)
Expand Down Expand Up @@ -119,11 +120,11 @@ public int compare(String arg0, String arg1) {
}
data.append("\n");
}
Main.println("Done");
Main.print("Done\n");
try {
File out = new File(Main.getOutputPrefix() + ".csv");
Main.writeStringToFile(out, data.toString());
Main.println("CSV written to " + out.getAbsolutePath());
Main.printf("CSV written to %s\n", out.getAbsolutePath());
} catch(IOException e) {
e.printStackTrace();
System.exit(1);
Expand All @@ -132,7 +133,7 @@ public int compare(String arg0, String arg1) {
try {
File out = new File(Main.getOutputPrefix() + ".html");
Main.writeStringToFile(out, generateTable((double) totalBlocks, totalExcludingAir));
Main.println("\nTable written to " + out.getAbsolutePath());
Main.printf("\nTable written to %s\n", out.getAbsolutePath());
} catch(IOException e) {
e.printStackTrace();
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void findChunks(File world) {
System.err.println("Error: World directory is empty");
System.exit(1);
}
Main.println(chunkFiles.size() + " chunks found");
Main.printf("%d chunks found\n", chunkFiles.size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void findChunks(File world) {
public void analyze() {
Analysis a = analyzeWorld(blocks, data, width, height);
duration = System.currentTimeMillis() - getStartTime();
Main.println(("Completed analysis in " + Main.millisToHMS(duration)));
Main.printf("Completed analysis in %d\n", Main.millisToHMS(duration));
blockCounter.putAll(a.blocks);
heightCounter.putAll(a.heights);
}
Expand Down

0 comments on commit 2f7cc4b

Please sign in to comment.