Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DynVarMap - Pure Java zero dependency runtime variables
#1
About: DynVarMap is zero dependency easy and straight forward way to manage attribute-like runtime variables for Java.
License: MIT License
Source: https://konloch.com/DynVarMap/
Download Jar: https://konloch.com/DynVarMap/releases/
Add as maven dependency:
Code:
<dependency>
  <groupId>com.konloch</groupId>
  <artifactId>DynVarMap</artifactId>
  <version>1.0.0</version>
</dependency>

Creating a new instance
To create a new instance all you need to do is create a new VarMap object.
Code:
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.
Code:
boolean booleanValue = map.getBoolean("githubBoolExample");

To supply a default value you can do it while grabbing the value.
Code:
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.
Code:
boolean booleanValue = map.getVarBoolean("githubBoolExample", false).get();

To fully leverage DynVarMap the trick is to chain methods to create easy-to-read one liners.
Code:
//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
if(map.getVarBoolean("githubBoolExample").get())

//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
if(!map.getVarBoolean("githubBoolExample").getThenSet(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.
Code:
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.
Code:
new VarMapSerializer("map.ini", map, true).save();
new VarMapSerializer("map.ini", map, true).load();
Reply
 


Forum Jump:


Users browsing this thread: 3 Guest(s)

About The Bytecode Club

We're a community forum focused on Reverse Engineering, we try to target Java/Android but we also include other langauges/platforms. We pride ourselves in supporting and free and open sourced applications.

Website