The Bytecode Club
DynVarMap - Pure Java zero dependency runtime variables - Printable Version

+- The Bytecode Club (
+-- Forum: Software (
+--- Forum: Java Projects / Libraries (
+--- Thread: DynVarMap - Pure Java zero dependency runtime variables (/showthread.php?tid=46008)

DynVarMap - Pure Java zero dependency runtime variables - Konloch - 02-17-2023

About: DynVarMap is zero dependency easy and straight forward way to manage attribute-like runtime variables for Java.
License: MIT License
Download Jar:
Add as maven dependency:

Creating a new instance
To create a new instance all you need to do is create a new VarMap object.
VarMap map = new VarMap();

Creating & accessing new variables
To create a new variable all you need to do is define the type first, then enter the unique variable name you would like to use.
boolean booleanValue = map.getBoolean("githubBoolExample");

To supply a default value you can do it while grabbing the value.
boolean booleanValue = map.getBoolean("githubBoolExample", false);

To access the DynVarMap field, you need to call upon the getVar* function. This exposes the API to allow method chaining on the variable.
boolean booleanValue = map.getVarBoolean("githubBoolExample", false).get();

To fully leverage DynVarMap the trick is to chain methods to create easy-to-read one liners.
//create a new variable if it doesn't exist yet and check if it's been set to true, if it has execute the code below

//create a new variable if it doesn't exist yet, check if it's been set as true, if it hasn't execute the code below, either way set it to being set as true

//create a new variable if it doesn't exist yet, add one, check if it equals any of the numbers, if it does execute the code below
if(map.getVarInt("githubIntExample").add(1).equals(13, 21, 34, 55, 89))

Time & Custom Types
DynVarMap supports custom types, one built-in example common is system time interaction. The Time type is based on the Long type, this means it comes with all of the helper functions such as add, subtract, divide and multiply.
map.getTime("githubTimeExample").setNow(); //set the stop-watch to start counting now
if(map.getVarTime("githubTimeExample").hasPassed(30_000)) //return true if 30 seconds have passed

Serializing/saving & loading from disk
You can serialize the map using the built-in serializer, it uses it's own format similar to .ini. Deserializing supports .ini format as well if you perfer to have hand-written configurations.
new VarMapSerializer("map.ini", map, true).save();
new VarMapSerializer("map.ini", map, true).load();