https://github.com/ggrandes/mapexpression
Expression Evaluator for use in placeholders like ${name} for Java
https://github.com/ggrandes/mapexpression
expression-evaluator expression-template java
Last synced: 5 months ago
JSON representation
Expression Evaluator for use in placeholders like ${name} for Java
- Host: GitHub
- URL: https://github.com/ggrandes/mapexpression
- Owner: ggrandes
- License: apache-2.0
- Created: 2014-05-27T19:45:33.000Z (about 12 years ago)
- Default Branch: main
- Last Pushed: 2024-09-15T09:56:35.000Z (almost 2 years ago)
- Last Synced: 2025-07-24T16:32:45.771Z (11 months ago)
- Topics: expression-evaluator, expression-template, java
- Language: Java
- Size: 29.3 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mapexpression
MapExpression is an Expression Evaluator for Java. Open Source Java project under Apache License v2.0
### Current Stable Version is [1.0.3](https://search.maven.org/#search|ga|1|g%3Aorg.javastack%20a%3Amapexpression)
---
## DOC
#### Usage Example
```java
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 map = new HashMap();
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());
}
}
```
* More examples in [Example package](https://github.com/ggrandes/mapexpression/tree/master/src/main/java/org/javastack/mapexpression/example/)
---
## MAVEN
Add the dependency to your pom.xml:
org.javastack
mapexpression
1.0.3
---
## 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 }.
TestName | Iterations | Time | Iterations/Second
:--- | ---: | ---: | ---:
ParseOnly | 10.000.000 | 4000ms | 2.500.000
EvalOnly | 10.000.000 | 2911ms | 3.435.000
Parse+Eval | 10.000.000 | 6995ms | 1.429.000
---
Inspired in [Java Expression Language](http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html) and [Spring-Placeholders](http://docs.spring.io/spring/docs/4.0.4.RELEASE/javadoc-api/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.html), this code is Java-minimalistic version.