From 80ae6644b158b47e17e5ee697c665f9fc76cfa05 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Mon, 11 Sep 2017 13:57:39 -0300 Subject: Use java.util.logging, not System.err --- .../java/bjc/utils/cli/objects/BlockReaderCLI.java | 57 ++++++++++++---------- .../main/java/bjc/utils/cli/objects/DefineCLI.java | 48 +++++++++++++++++- 2 files changed, 76 insertions(+), 29 deletions(-) (limited to 'BJC-Utils2/src/main/java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java b/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java index c6cb062..ae5cff8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.function.Predicate; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -15,6 +16,8 @@ import bjc.utils.ioutils.Prompter; import bjc.utils.ioutils.blocks.*; public class BlockReaderCLI { + private final Logger LOGGER = Logger.getLogger(BlockReaderCLI.class.getName()); + public static class BlockReaderState { public final Map readers; public final Map sources; @@ -110,7 +113,7 @@ public class BlockReaderCLI { stat.readers.size(), com.lineNo); break; default: - System.err.print(com.error("Unknown command '%s'\n", com.nameCommand)); + LOGGER.severe(com.error("Unknown command '%s'\n", com.nameCommand)); break; } } @@ -123,7 +126,7 @@ public class BlockReaderCLI { */ int idx = remn.indexOf(' '); if(idx == -1) { - System.err.print(com.error("No name argument for def-filtered.\n")); + LOGGER.severe(com.error("No name argument for def-filtered.\n")); } String blockName = remn.substring(0, idx).trim(); remn = remn.substring(idx).trim(); @@ -132,7 +135,7 @@ public class BlockReaderCLI { * Check there isn't a reader already bound to this name. */ if(stat.readers.containsKey(blockName)) { - System.err.print(com.warn("Shadowing existing reader named %s\n", blockName)); + LOGGER.warning(com.warn("Shadowing existing reader named %s\n", blockName)); } /* @@ -140,7 +143,7 @@ public class BlockReaderCLI { */ idx = remn.indexOf(' '); if(idx == -1) { - System.err.print("No reader-name argument for def-filtered.\n"); + LOGGER.severe(com.error("No reader-name argument for def-filtered.\n")); } String readerName = remn.substring(0, idx).trim(); remn = remn.substring(idx).trim(); @@ -149,7 +152,7 @@ public class BlockReaderCLI { * Check there is a reader bound to that name. */ if(!stat.readers.containsKey(readerName)) { - System.err.print(com.error("No source named %s\n", readerName)); + LOGGER.severe(com.error("No source named %s\n", readerName)); return; } @@ -157,7 +160,7 @@ public class BlockReaderCLI { * Get the pattern. */ if(remn.equals("")) { - System.err.print("No filter argument for def-filtered\n"); + LOGGER.severe(com.error("No filter argument for def-filtered\n")); } String filter = remn; @@ -175,7 +178,7 @@ public class BlockReaderCLI { stat.readers.put(blockName, reader); } catch (PatternSyntaxException psex) { - System.err.print(com.error("Invalid regular expression '%s' for filter. (%s)\n", filter, psex.getMessage())); + LOGGER.severe(com.error("Invalid regular expression '%s' for filter. (%s)\n", filter, psex.getMessage())); } } @@ -183,18 +186,18 @@ public class BlockReaderCLI { String[] parts = com.remnCommand.split(" "); if(parts.length != 2) { - System.err.print(com.error("Incorrect number of arguments to def-pushback. Requires a block name and a reader name\n")); + LOGGER.severe(com.error("Incorrect number of arguments to def-pushback. Requires a block name and a reader name\n")); return; } String blockName = parts[0]; if(stat.readers.containsKey(blockName)) { - System.err.print(com.warn("Shadowing existing reader %s\n", blockName)); + LOGGER.warning(com.warn("Shadowing existing reader %s\n", blockName)); } String readerName = parts[1]; if(!stat.readers.containsKey(readerName)) { - System.err.print(com.error("No reader named %s\n", readerName)); + LOGGER.severe(com.error("No reader named %s\n", readerName)); return; } @@ -206,7 +209,7 @@ public class BlockReaderCLI { String[] parts = com.remnCommand.split(" "); if(parts.length != 3) { - System.err.print(com.error("Incorrect number of arguments to def-toggled. Requires a block name and two reader names\n")); + LOGGER.severe(com.error("Incorrect number of arguments to def-toggled. Requires a block name and two reader names\n")); return; } @@ -215,19 +218,19 @@ public class BlockReaderCLI { */ String blockName = parts[0]; if(stat.readers.containsKey(blockName)) { - System.err.print(com.warn("Shadowing existing reader named %s\n", blockName)); + LOGGER.warning(com.warn("Shadowing existing reader named %s\n", blockName)); } /* * Make sure the component readers exist. */ if(!stat.readers.containsKey(parts[1])) { - System.err.print(com.error("No reader named %s\n", parts[1])); + LOGGER.severe(com.error("No reader named %s\n", parts[1])); return; } if(!stat.readers.containsKey(parts[2])) { - System.err.print(com.error("No reader named %s\n", parts[2])); + LOGGER.severe(com.error("No reader named %s\n", parts[2])); return; } @@ -239,7 +242,7 @@ public class BlockReaderCLI { String[] parts = com.remnCommand.split(" "); if(parts.length != 3) { - System.err.print(com.error("Incorrect number of arguments to def-layered. Requires a block name and two reader names\n")); + LOGGER.severe(com.error("Incorrect number of arguments to def-layered. Requires a block name and two reader names\n")); return; } @@ -248,19 +251,19 @@ public class BlockReaderCLI { */ String blockName = parts[0]; if(stat.readers.containsKey(blockName)) { - System.err.print(com.warn("Shadowing existing reader named %s\n", blockName)); + LOGGER.warning(com.warn("Shadowing existing reader named %s\n", blockName)); } /* * Make sure the component readers exist. */ if(!stat.readers.containsKey(parts[1])) { - System.err.print(com.error("No reader named %s\n", parts[1])); + LOGGER.severe(com.error("No reader named %s\n", parts[1])); return; } if(!stat.readers.containsKey(parts[2])) { - System.err.print(com.error("No reader named %s\n", parts[2])); + LOGGER.severe(com.error("No reader named %s\n", parts[2])); return; } @@ -272,7 +275,7 @@ public class BlockReaderCLI { String[] parts = com.remnCommand.split(" "); if(parts.length < 2) { - System.err.print(com.error("Not enough arguments to def-serial. Requires at least a block name and at least one reader name\n")); + LOGGER.severe(com.error("Not enough arguments to def-serial. Requires at least a block name and at least one reader name\n")); return; } @@ -284,7 +287,7 @@ public class BlockReaderCLI { * Check there isn't a reader already bound to this name. */ if(stat.readers.containsKey(blockName)) { - System.err.print(com.warn("Shadowing existing reader named %s\n", blockName)); + LOGGER.warning(com.warn("Shadowing existing reader named %s\n", blockName)); } /* @@ -298,7 +301,7 @@ public class BlockReaderCLI { * Check there is a reader bound to that name. */ if(!stat.readers.containsKey(readerName)) { - System.err.print(com.error("No reader named %s\n", readerName)); + LOGGER.severe(com.error("No reader named %s\n", readerName)); return; } @@ -318,7 +321,7 @@ public class BlockReaderCLI { */ int idx = remn.indexOf(' '); if(idx == -1) { - System.err.print(com.error("No name argument for def-simple.\n")); + LOGGER.severe(com.error("No name argument for def-simple.\n")); } String blockName = remn.substring(0, idx).trim(); remn = remn.substring(idx).trim(); @@ -327,7 +330,7 @@ public class BlockReaderCLI { * Check there isn't a reader already bound to this name. */ if(stat.readers.containsKey(blockName)) { - System.err.print(com.warn("Shadowing existing reader named %s\n", blockName)); + LOGGER.warning(com.warn("Shadowing existing reader named %s\n", blockName)); } /* @@ -335,7 +338,7 @@ public class BlockReaderCLI { */ idx = remn.indexOf(' '); if(idx == -1) { - System.err.print("No source-name argument for def-simple.\n"); + LOGGER.severe(com.error("No source-name argument for def-simple.\n")); } String sourceName = remn.substring(0, idx).trim(); remn = remn.substring(idx).trim(); @@ -344,7 +347,7 @@ public class BlockReaderCLI { * Check there is a source bound to that name. */ if(!stat.sources.containsKey(sourceName)) { - System.err.print(com.error("No source named %s\n", sourceName)); + LOGGER.severe(com.error("No source named %s\n", sourceName)); return; } @@ -352,7 +355,7 @@ public class BlockReaderCLI { * Get the pattern. */ if(remn.equals("")) { - System.err.print("No delimiter argument for def-simple\n"); + LOGGER.severe(com.error("No delimiter argument for def-simple\n")); } String delim = remn; @@ -362,7 +365,7 @@ public class BlockReaderCLI { stat.readers.put(blockName, reader); } catch (PatternSyntaxException psex) { - System.err.print(com.error("Invalid regular expression '%s' for delimiter. (%s)\n", delim, psex.getMessage())); + LOGGER.severe(com.error("Invalid regular expression '%s' for delimiter. (%s)\n", delim, psex.getMessage())); } } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/objects/DefineCLI.java b/BJC-Utils2/src/main/java/bjc/utils/cli/objects/DefineCLI.java index 71c683d..ead8b36 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/objects/DefineCLI.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/objects/DefineCLI.java @@ -1,8 +1,47 @@ package bjc.utils.cli.objects; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; +import java.util.function.UnaryOperator; +import java.util.logging.Logger; +import java.util.regex.Pattern; + public class DefineCLI { - public static void main(String[] args) { + private final Logger LOGGER = Logger.getLogger(DefineCLI.class.getName()); + + public static class DefineState { + public final Map> defines; + + public final Map strings; + public final Map formats; + + public final Map patterns; + + public DefineState() { + this(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>()); + } + + public DefineState(Map> defines, + Map strings, Map formats, + Map patterns) { + this.defines = defines; + + this.strings = strings; + this.formats = formats; + this.patterns = patterns; + } + } + + private DefineState state; + + public DefineCLI() { + state = new DefineState(); + } + + public static void main(String[] args) { + DefineCLI defin = new DefineCLI(); } /** @@ -35,6 +74,11 @@ public class DefineCLI { } public void handleCommand(Command com, boolean interactive) { - + switch(com.nameCommand) { + case "": + default: + LOGGER.severe(com.error("Unknown command %s\n", com.nameCommand)); + break; + } } } -- cgit v1.2.3