From e6c3cf3941aff03a01b31b49edd61f4cfca80fc8 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Tue, 6 Oct 2020 19:19:06 -0400 Subject: Info cleanup --- src/main/java/tlIItools/AffixLister.java | 321 +++++++++++++++------------- src/main/java/tlIItools/AffixSet.java | 1 + src/main/java/tlIItools/Main.java | 11 + src/main/java/tlIItools/NameFileReader.java | 20 +- 4 files changed, 208 insertions(+), 145 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/tlIItools/AffixLister.java b/src/main/java/tlIItools/AffixLister.java index 3a096bd2..4601ef4d 100644 --- a/src/main/java/tlIItools/AffixLister.java +++ b/src/main/java/tlIItools/AffixLister.java @@ -59,7 +59,8 @@ public class AffixLister { /** * Main method. * - * @param args The names of the files to read affix data from. + * @param args + * The names of the files to read affix data from. */ public static void main(String[] args) { listAffixes(args); @@ -69,22 +70,26 @@ public class AffixLister { * Main method that actually does stuff. * * @param args - * The names of the files to read affix data from. + * The names of the files to read affix data from. + * + * @return The listed affix set. + * */ + @SuppressWarnings("unused") public static AffixSet listAffixes(String[] args) { AffixSet affixSetByName = new AffixSet(); - boolean doingArgs = true; + boolean doingArgs = true; - boolean omitZeros = false; - boolean listZeros = false; + boolean omitZeros = false; + boolean listZeros = false; NameMode nameMode = NameMode.ALL; - int namedCount = 0; + int namedCount = 0; int unnamedCount = 0; - int zeroCount = 0; - int groupCount = 0; + int zeroCount = 0; + int groupCount = 0; boolean outputAffixGroups = false; OutputStream affixGroupDest = null; @@ -98,165 +103,174 @@ public class AffixLister { long startTime = System.nanoTime(); - for(int i = 0; i < args.length; i++) { + for (int i = 0; i < args.length; i++) { String fName = args[i]; if (doingArgs && fName.startsWith("-")) { boolean isArg = true; switch (fName) { - case "--": - doingArgs = false; - break; - - case "--omit-zero": - case "-z": - omitZeros = true; - break; - - case "--no-omit-zero": - case "-Z": - omitZeros = false; - break; - - case "--list-zero": - case "-l": - listZeros = true; - break; - - case "--no-list-zero": - case "-L": - listZeros = false; - break; - - case "--timing": - case "-t": - doTiming = true; - Effect.doTiming = true; + case "--": + doingArgs = false; + break; + + case "--omit-zero": + case "-z": + omitZeros = true; + break; + + case "--no-omit-zero": + case "-Z": + omitZeros = false; + break; + + case "--list-zero": + case "-l": + listZeros = true; + break; + + case "--no-list-zero": + case "-L": + listZeros = false; + break; + + case "--timing": + case "-t": + doTiming = true; + Effect.doTiming = true; + break; + + case "--no-timing": + case "-T": + doTiming = false; + Effect.doTiming = false; + break; + + case "--file-names": + case "-f": + addFileName = true; + break; + + case "--no-file-names": + case "-F": + addFileName = true; + break; + + case "--name-mode": + case "-n": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: name mode argument requires the mode to use be specified (all, unnamed or named)\n"); break; + } - case "--no-timing": - case "-T": - doTiming = false; - Effect.doTiming = false; - break; + nameMode = NameMode.valueOf(args[++i].toUpperCase()); - case "--file-names": - case "-f": - addFileName = true; - break; + break; - case "--no-file-names": - case "-F": - addFileName = true; + case "--file-group": + case "-g": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: file group argument requires the group name to use be specified\n"); break; + } - case "--name-mode": - case "-n": - if (i + 1 >= args.length) { - errOut.printf("ERROR: name mode argument requires the mode to use be specified (all, unnamed or named)\n"); - break; - } + nfr.swapGroup(args[++i]); - nameMode = NameMode.valueOf(args[++i].toUpperCase()); + break; - break; + case "--guess-groups": + nfr.guessGroups = true; - case "--file-group": - case "-g": - if (i + 1 >= args.length) { - errOut.printf("ERROR: file group argument requires the group name to use be specified\n"); - break; - } - - nfr.swapGroup(args[++i]); + break; - break; + case "--no-guess-groups": + nfr.guessGroups = false; - case "--guess-groups": - nfr.guessGroups = true; - - break; - - case "--no-guess-groups": - nfr.guessGroups = false; + break; + case "--read-names-from-file": + case "-r": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: read name file argument requires the file to use be specified\n"); break; + } - case "--read-names-from-file": - case "-r": - if (i + 1 >= args.length) { - errOut.printf("ERROR: read name file argument requires the file to use be specified\n"); - break; - } + nfr.readFrom(args[++i]); - nfr.readFrom(args[++i]); + break; + case "--output": + case "-o": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: output file argument requires the file to use be specified\n"); break; + } - case "--output": - case "-o": - if (i + 1 >= args.length) { - errOut.printf("ERROR: output file argument requires the file to use be specified\n"); - break; - } + try { + normOut = new PrintStream(args[++i]); - try { - normOut = new PrintStream(args[++i]); + nfr.normOut = normOut; + } catch (IOException ioex) { + errOut.printf("Could not open output file %s\n", args[i]); - nfr.normOut = normOut; - } catch (IOException ioex) { - errOut.printf("Could not open output file %s\n", args[i]); + ioex.printStackTrace(errOut); + } - ioex.printStackTrace(errOut); - } + break; + case "--output-errors": + case "-e": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: error output file argument requires the file to use be specified\n"); break; + } - case "--output-errors": - case "-e": - if (i + 1 >= args.length) { - errOut.printf("ERROR: error output file argument requires the file to use be specified\n"); - break; - } + try { + errOut = new PrintStream(args[++i]); - try { - errOut = new PrintStream(args[++i]); + nfr.errOut = errOut; + } catch (IOException ioex) { + errOut.printf("Could not open error output file %s\n", args[i]); - nfr.errOut = errOut; - } catch (IOException ioex) { - errOut.printf("Could not open error output file %s\n", args[i]); + ioex.printStackTrace(errOut); + } - ioex.printStackTrace(errOut); - } + break; + case "--guess-regex": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: group regex argument requires the regex to use be specified\n"); break; + } - case "--guess-regex": - if (i + 1 >= args.length) { - errOut.printf("ERROR: group regex argument requires the regex to use be specified\n"); - break; - } - - nfr.groupRx = args[++i]; + nfr.groupRx = args[++i]; + break; + case "--output-affix-groups": + if (i + 1 >= args.length) { + errOut.printf( + "ERROR: to output affix-groups, must specify a file to output them to"); break; - case "--output-affix-groups": - if (i + 1 >= args.length) { - errOut.printf("ERROR: to output affix-groups, must specify a file to output them to"); - break; - } + } - try { - affixGroupDest = new PrintStream(args[++i]); + try { + affixGroupDest = new PrintStream(args[++i]); - outputAffixGroups = true; - } catch (IOException ioex) { - errOut.printf("ERROR: Couldn't open file %s to write affix groups to\n", affixGroupDest); - } + outputAffixGroups = true; + } catch (IOException ioex) { + errOut.printf( + "ERROR: Couldn't open file %s to write affix groups to\n", + affixGroupDest); + } - break; - default: - isArg = false; + break; + default: + isArg = false; } if (isArg) { @@ -270,9 +284,10 @@ public class AffixLister { } AffixSet affixSetByContents = new AffixSet(); - + for (Entry> fGroup : nfr.fNames.entrySet()) { - if (fGroup.getValue().size() == 0) continue; + if (fGroup.getValue().size() == 0) + continue; normOut.printf("\nFile Group '%s' starting\n", fGroup.getKey()); for (String fName : fGroup.getValue()) { try (FileReader fr = new FileReader(fName)) { @@ -280,7 +295,7 @@ public class AffixLister { Affix afx = Affix.loadAffix(sc, fName); affixSetByContents.addAffixByContents(afx); - + effectCount += afx.effects.size(); if (afx.intName != null && afx.weight != 0) { @@ -290,10 +305,12 @@ public class AffixLister { if (!groupContents.containsKey(groupName)) { groupCount += 1; - // errOut.printf("\tTRACE: Counted distinct group %s from %s\n", groupName, afx.intName); + // errOut.printf("\tTRACE: Counted distinct group %s from + // %s\n", groupName, afx.intName); if (hasGroup) { - // errOut.printf("\tTRACE: Counted actual group %s from %s\n", groupName, afx.intName); + // errOut.printf("\tTRACE: Counted actual group %s from + // %s\n", groupName, afx.intName); groupContents.put(groupName, new HashSet<>()); } else { @@ -306,24 +323,32 @@ public class AffixLister { } } - if (afx.weight == 0) zeroCount += 1; + if (afx.weight == 0) + zeroCount += 1; if (afx.weight == 0 && !listZeros) { if (!omitZeros) - normOut.printf("\nAffix %s has zero spawn weight\n", afx.intName); + normOut.printf("\nAffix %s has zero spawn weight\n", + afx.intName); } else { - boolean isNamed = (afx.affixSuffix != null) || (afx.affixPrefix != null); + boolean isNamed + = (afx.affixSuffix != null) || (afx.affixPrefix != null); - if (isNamed) namedCount += 1; - else unnamedCount += 1; + if (isNamed) + namedCount += 1; + else + unnamedCount += 1; - if (nameMode == NameMode.UNNAMED && isNamed) continue; - if (nameMode == NameMode.NAMED && !isNamed) continue; + if (nameMode == NameMode.UNNAMED && isNamed) + continue; + if (nameMode == NameMode.NAMED && !isNamed) + continue; normOut.printf("\n%s\n", afx.toLongString()); } } catch (Exception ex) { - errOut.printf("Something bad happened for file %s:%s\n", fName, ex.getMessage()); + errOut.printf("Something bad happened for file %s:%s\n", fName, + ex.getMessage()); ex.printStackTrace(errOut); @@ -334,14 +359,15 @@ public class AffixLister { } errOut.println("\nGroup Contents: "); - for (Entry> ent: groupContents.entrySet()) { + for (Entry> ent : groupContents.entrySet()) { errOut.printf("\t%s: %s\n", ent.getKey(), ent.getValue()); } errOut.println(); errOut.println(); if (outputAffixGroups) { - for (Entry> ent : affixSetByContents.affixGroups.entrySet()) { + for (Entry> ent : affixSetByContents.affixGroups + .entrySet()) { String groupName = ent.getKey(); Set affixes = ent.getValue(); @@ -358,8 +384,15 @@ public class AffixLister { } long endTime = System.nanoTime(); - errOut.printf("\nProcessed %,d affixes (%,d named, %,d unnamed, %,d zero-weight) (%,d effects) (%,d distinct groups, %,d actual groups, %,d nongrouped affixes) out of %,d files (%,d groups) in %,d nanoseconds (%.2f seconds)\n", nfr.fCount, namedCount, unnamedCount, zeroCount, effectCount, groupCount, groupContents.size(), nonGroupContents.size(), nfr.fCount, nfr.fNames.size(), endTime - startTime, ((double)(endTime - startTime) / 1000000000)); - errOut.printf("\tOptions: Name Mode: %s, Special-case zero weight: %s, Noting zero-weight in special case: %s\n", nameMode, !listZeros, !omitZeros); + errOut.printf( + "\nProcessed %,d affixes (%,d named, %,d unnamed, %,d zero-weight) (%,d effects) (%,d distinct groups, %,d actual groups, %,d nongrouped affixes) out of %,d files (%,d groups) in %,d nanoseconds (%.2f seconds)\n", + nfr.fCount, namedCount, unnamedCount, zeroCount, effectCount, groupCount, + groupContents.size(), nonGroupContents.size(), nfr.fCount, + nfr.fNames.size(), endTime - startTime, + ((double) (endTime - startTime) / 1000000000)); + errOut.printf( + "\tOptions: Name Mode: %s, Special-case zero weight: %s, Noting zero-weight in special case: %s\n", + nameMode, !listZeros, !omitZeros); return affixSetByName; } diff --git a/src/main/java/tlIItools/AffixSet.java b/src/main/java/tlIItools/AffixSet.java index d7f14211..d43b34e1 100644 --- a/src/main/java/tlIItools/AffixSet.java +++ b/src/main/java/tlIItools/AffixSet.java @@ -9,6 +9,7 @@ import java.util.*; */ public class AffixSet { private static class AffixComparator implements Comparator { + @Override public int compare(Affix a1, Affix a2) { if (a1.minLevel == a2.minLevel) { return a1.maxLevel - a2.maxLevel; diff --git a/src/main/java/tlIItools/Main.java b/src/main/java/tlIItools/Main.java index 234f0bd3..fa2617c5 100644 --- a/src/main/java/tlIItools/Main.java +++ b/src/main/java/tlIItools/Main.java @@ -1,6 +1,17 @@ package tlIItools; +/** + * Main method for TLIITools + * + * @author Ben Culkin + * + */ public class Main { + /** + * Main method. + * + * @param args Unused CLI args. + */ public static void main(String[] args) { // TODO implement this } diff --git a/src/main/java/tlIItools/NameFileReader.java b/src/main/java/tlIItools/NameFileReader.java index 87407162..8b1b62d4 100644 --- a/src/main/java/tlIItools/NameFileReader.java +++ b/src/main/java/tlIItools/NameFileReader.java @@ -51,7 +51,14 @@ public class NameFileReader { */ public int fCount; + /** + * Stream to write normal output to. + */ public PrintStream normOut = System.out; + + /** + * Stream to write error output to. + */ public PrintStream errOut = System.err; /** @@ -171,12 +178,23 @@ public class NameFileReader { } } + /** + * Add a file to this file reader. + * + * @param fName The file to add. + */ public void addFile(String fName) { curList.add(fName); fCount += 1; } - + + /** + * Add a file to this file reader. + * + * @param groupName The group to add the file to. * + * @param fName The file to add. + */ public void addFile(String groupName, String fName) { fNames.computeIfAbsent(groupName, (key) -> new ArrayList<>()).add(fName); -- cgit v1.2.3