From f4baa925b0b5590bc8b12ba5f32e0218384c8efc Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 7 Apr 2017 16:06:18 -0400 Subject: Add simple toggle values --- .../java/bjc/utils/ioutils/SimpleProperties.java | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java b/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java index a43b16a..531e8b8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java +++ b/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java @@ -32,27 +32,25 @@ public class SimpleProperties implements Map { * All leading/trailing spaces from the name & body are removed. * * @param is - * The stream to read from. + * The stream to read from. * * @param allowDuplicates - * Whether or not duplicate keys should be allowed. + * Whether or not duplicate keys should be allowed. */ public void loadFrom(InputStream is, boolean allowDuplicates) { - try (Scanner scn = new Scanner(is)) { - while (scn.hasNextLine()) { + try(Scanner scn = new Scanner(is)) { + while(scn.hasNextLine()) { String ln = scn.nextLine().trim(); /* * Skip blank lines/comments */ - if (ln.equals("")) - continue; - if (ln.startsWith("#")) - continue; + if(ln.equals("")) continue; + if(ln.startsWith("#")) continue; int sepIdx = ln.indexOf(' '); - if (sepIdx == -1) { + if(sepIdx == -1) { String fmt = "Properties must be a name, a space, then the body.\n\tOffending line is '%s'"; String msg = String.format(fmt, ln); @@ -62,7 +60,7 @@ public class SimpleProperties implements Map { String name = ln.substring(0, sepIdx).trim(); String body = ln.substring(sepIdx).trim(); - if (!allowDuplicates && containsKey(name)) { + if(!allowDuplicates && containsKey(name)) { String msg = String.format("Duplicate key '%s'", name); throw new IllegalStateException(msg); @@ -71,13 +69,19 @@ public class SimpleProperties implements Map { put(name, body); } } + } + /** + * Output the set of read properties. + */ + public void outputProperties() { System.out.println("Read properties:"); - for (Entry entry : entrySet()) { + + for(Entry entry : entrySet()) { System.out.printf("\t'%s'\t'%s'\n", entry.getKey(), entry.getValue()); } - System.out.println(); + System.out.println(); } @Override -- cgit v1.2.3