Home » Source Code » groovy表达式解析


2016-12-09 04:57:01
The author
Download(s): 0
Point (s): 1 
Category Category:
java,shelljava,shell AllAll


public class ExprSupport {
    private static final Object lock = new Object();
    private static final GroovyShell shell;
    private static Hashtable cache = new Hashtable();
    static {
        CompilerConfiguration cfg = new CompilerConfiguration();
        shell = new GroovyShell(cfg);
    public static Object parseExpr(String expr) {
        Script s = getScriptFromCache(expr);
        return s.run();
    public static Object parseExpr(String expr, Map<?, ?> map) {
        Binding binding = new Binding(map);
        Script script = getScriptFromCache(expr);
        return script.run();
    private static Script getScriptFromCache(String expr) {
        if (cache.contains(expr)) {
            return cache.get(expr);
        synchronized (lock) {
            if (cache.contains(expr)) {
                return cache.get(expr);
            Script script = shell.parse(expr);
            cache.put(expr, script);
            return script;
     * @param args
    public static void main(String[] args) {
        Map row = new HashMap();
        row.put("id", 42);
        row.put("name", "");
        System.out.println(ExprSupport.parseExpr("nvl(id,0)", row));
        System.out.println(ExprSupport.parseExpr("nvl(name,'anonymous')", row));
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
ExprSupport.java2.07 kB2016-11-28 21:27
MyBasicScript.java608.00 B2016-11-28 10:12
groovy_10.00 B2016-12-09 17:53
Sponsored links


(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

groovy表达式解析 (1.31 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points


Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com


CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D