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 --- BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java | 46 +++++++++++++--------- 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java b/BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java index 3f2c078..daaf423 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java +++ b/BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java @@ -15,11 +15,13 @@ import java.util.regex.Pattern; * */ public class PropertyDB { - private static SimpleProperties regexes; - private static Map compiledRegexes; + private static SimpleProperties regexes; + private static Map compiledRegexes; private static SimpleProperties formats; + private static final boolean LOGLOAD = false; + /* * The lock to use to ensure a read can't happen during a reload */ @@ -37,20 +39,27 @@ public class PropertyDB { */ public static void reloadProperties() { loadLock.write(() -> { - System.out.println("Reading regex properties:"); + if(LOGLOAD) { + System.out.println("Reading regex properties:"); + } regexes = new SimpleProperties(); regexes.loadFrom(PropertyDB.class.getResourceAsStream("/regexes.sprop"), false); - System.out.println(); + if(LOGLOAD) { + regexes.outputProperties(); + System.out.println(); + } compiledRegexes = new HashMap<>(); - System.out.println("Reading format properties:"); + if(LOGLOAD) { + System.out.println("Reading format properties:"); + } formats = new SimpleProperties(); formats.loadFrom(PropertyDB.class.getResourceAsStream("/formats.sprop"), false); - System.out.println(); - - if (regexes.equals(formats)) - System.out.println("WAT"); + if(LOGLOAD) { + formats.outputProperties(); + System.out.println(); + } }); } @@ -58,13 +67,13 @@ public class PropertyDB { * Retrieve a persisted regular expression. * * @param key - * The name of the regular expression. + * The name of the regular expression. * * @return The regular expression with that name. */ public static String getRegex(String key) { return loadLock.read(() -> { - if (!regexes.containsKey(key)) { + if(!regexes.containsKey(key)) { String msg = String.format("No regular expression named '%s' found", key); throw new NoSuchElementException(msg); @@ -79,13 +88,13 @@ public class PropertyDB { * expression. * * @param key - * The name of the regular expression. + * The name of the regular expression. * * @return The regular expression with that name. */ public static Pattern getCompiledRegex(String key) { return loadLock.read(() -> { - if (!regexes.containsKey(key)) { + if(!regexes.containsKey(key)) { String msg = String.format("No regular expression named '%s' found", key); throw new NoSuchElementException(msg); @@ -101,13 +110,13 @@ public class PropertyDB { * Retrieve a persisted format string. * * @param key - * The name of the format string. + * The name of the format string. * * @return The format string with that name. */ public static String getFormat(String key) { return loadLock.read(() -> { - if (!formats.containsKey(key)) { + if(!formats.containsKey(key)) { String msg = String.format("No format string named '%s' found", key); throw new NoSuchElementException(msg); @@ -118,13 +127,14 @@ public class PropertyDB { } /** - * Retrieve a persisted format string, and apply it to a set of arguments. + * Retrieve a persisted format string, and apply it to a set of + * arguments. * * @param key - * The name of the format string. + * The name of the format string. * * @param objects - * The parameters to the format string. + * The parameters to the format string. * * @return The format string with that name. */ -- cgit v1.2.3