Konloch Software

String Vars

Published 02/18/2023 Updated 02/23/2023

StringVars is a zero dependency pure Java solution to create recursive String variables, such as $var$ or %var%.

What Does It Do?

  • StringVars leverages maps to efficiently store and retrieve variable values, managing and resolving variable references in strings.
  • This approach allows for flexible and dynamic text processing, where variables are looked up in the map and replaced with their values, handling nested or recursive references as needed.
  1. Variable Storage: Variables and their values are stored in a map, where the keys are variable names and the values are the corresponding strings.
  2. Value Retrieval: When resolving a variable, StringVars uses a map to fetch the value associated with a given key. If the value contains other variables, it recursively retrieves and replaces them.
  3. Dynamic Resolution: It dynamically resolves variables by looking them up in the map and replacing them with their values, handling nested or recursive references as needed.

Links

Requirements

  • Java 8 or greater

How To Integrate as a Dependency

Add the following to your pom.xml as a maven dependency, or just download the latest release and import it with your IDE.

<dependency>
	<groupId>com.konloch</groupId>
	<artifactId>StringVars</artifactId>
	<version>1.0.1</version>
</dependency>

How To Use

Click here for the StringHolderExample class

StringHolderExample example = new StringHolderExample()
{
	@Override
	public String getString(String key)
	{
		return StringVars.getVariableValue('$', ()-> getMap().get(key),(vkey)-> getMap().get(vkey));
	}
};
		
example.getMap().put("example", "Example: $var$");
example.getMap().put("var", "This is a great example of how it functions!");

System.out.println("Results: " + example.getString("example"));

Latest Updates

StringVars v1.0.1

This is the second public release of the library, it has been heavily tested but please feel free to report any issues found.

To add it as a…

Read More

StringVars v1.0.0

This is the first public release of the library, it has been heavily tested but please feel free to report any issues found.

To add it as a…

Read More