Home

Awesome

mapexpression

MapExpression is an Expression Evaluator for Java. Open Source Java project under Apache License v2.0

Current Stable Version is 1.0.3


DOC

Usage Example

import java.util.HashMap;
import org.javastack.mapexpression.MapExpression;
import org.javastack.mapexpression.mapper.MapMapper;
import org.javastack.mapexpression.mapper.SystemPropertyMapper;

public class Example {
	public static void main(final String[] args) throws Throwable {
		final String TEST_TEXT = "Hi ${user.name}, you are ${state}!!";
		final HashMap<String, String> map = new HashMap<String, String>();
		map.put("state", "lucky");
		MapExpression m;
		// Shot
		m = new MapExpression(TEST_TEXT, map, true);
		System.out.println(m.get());
		// Fluent
		m = new MapExpression();
		m.setExpression(TEST_TEXT) //
				.setPreMapper(SystemPropertyMapper.getInstance()) //
				.setPostMapper(new MapMapper(map)) //
				.parse() //
				.eval();
		System.out.println(m.get());
	}
}

MAVEN

Add the dependency to your pom.xml:

<dependency>
    <groupId>org.javastack</groupId>
    <artifactId>mapexpression</artifactId>
    <version>1.0.3</version>
</dependency>

Benchmarks

Values are not accurate, but orientative. Higher better (Iterations/Second). All test Running on Laptop { Windows 7 (64bits), sun_jdk1.6.0_45 (32bits), Dell Latitude 3330 }.
TestNameIterationsTimeIterations/Second
ParseOnly10.000.0004000ms2.500.000
EvalOnly10.000.0002911ms3.435.000
Parse+Eval10.000.0006995ms1.429.000

Inspired in Java Expression Language and Spring-Placeholders, this code is Java-minimalistic version.