summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/PropertyDB.java46
1 files changed, 28 insertions, 18 deletions
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<String, Pattern> compiledRegexes;
+ private static SimpleProperties regexes;
+ private static Map<String, Pattern> 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.
*/