From 9e342b2c919e076a6986522e4ea037c67c0e0681 Mon Sep 17 00:00:00 2001 From: Duncan Sterken Date: Wed, 7 Nov 2018 18:26:40 +0100 Subject: [PATCH 1/2] Add gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd1b092 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea/ +*.iml \ No newline at end of file From 8d06aeae63e865c4d2ceccf36ecc03a395bf6dbe Mon Sep 17 00:00:00 2001 From: Duncan Sterken Date: Wed, 7 Nov 2018 18:34:22 +0100 Subject: [PATCH 2/2] Add the get and getOrDefault methods --- src/main/java/com/jagrosh/jagtag/Parser.java | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/com/jagrosh/jagtag/Parser.java b/src/main/java/com/jagrosh/jagtag/Parser.java index fae3ceb..e43555b 100644 --- a/src/main/java/com/jagrosh/jagtag/Parser.java +++ b/src/main/java/com/jagrosh/jagtag/Parser.java @@ -76,6 +76,30 @@ public synchronized Parser clear() environment.clear(); return this; } + + /** + * Gets an item from the environment, can be used to retrieve objects after parsing + * + * @param key - the name of the object to retrieve + * @return a possibly null object with the specified key + * @see #getOrDefault(String, Object) + */ + public synchronized T get(String key) + { + return environment.get(key); + } + + /** + * Gets an item from the environment, can be used to retrieve objects after parsing + * + * @param key - the name of the object to retrieve + * @param defaultValue - the default value to return in case no object was found for the specified key + * @return the object stored for the key or the default value + */ + public synchronized T getOrDefault(String key, T defaultValue) + { + return environment.getOrDefault(key, defaultValue); + } /** * Parses a String of JagTag code, utilizing the object that have been added