Skip to content

Latest commit

 

History

History
90 lines (68 loc) · 2.47 KB

README_EN.md

File metadata and controls

90 lines (68 loc) · 2.47 KB

Expression Language

An expressive expression engine.

Build Status Maven Central LICENSE

中文说明/Chinese Documentation

Installation

<dependency>
    <groupId>io.github.slince</groupId>
    <artifactId>expression</artifactId>
    <version>0.0.2-RELEASE</version>
</dependency>

ObjectPath:

<dependency>
    <groupId>io.github.slince</groupId>
    <artifactId>expression-data-path</artifactId>
    <version>0.0.2-RELEASE</version>
</dependency>

ObjectPath Documentation

Getting Started

import io.github.slince.expression.Evaluator;
import io.github.slince.expression.MapContext;

import java.util.Arrays;
import java.util.List;

public class Book {

    private final String name;
    private final float price;
    private final List<String> tags;

    public Book(String name, float price, List<String> tags) {
        this.name = name;
        this.price = price;
        this.tags = tags;
    }

    public String getName() {
        return name;
    }

    public float getPrice() {
        return price;
    }

    public List<String> getTags() {
        return tags;
    }

    public static void main(String[] args) {
        // Create a book
        Book book = new Book("The Lady of the Camellias", 12.89f, Arrays.asList("Love Story", "France", null));
        MapContext ctx = new MapContext();
        ctx.setVar("book", book);
        // evaluate expression
        // "The Lady of the Camellias"
        System.out.println(Evaluator.INSTANCE.evaluate("book.name", ctx));
        // 3
        System.out.println(Evaluator.INSTANCE.evaluate("book.tags|size", ctx));
        // 22.89f
        System.out.println(Evaluator.INSTANCE.evaluate("book.price + 10", ctx));
    }
} 

Documentation

Read the Documentation.

Issue

Issue Report: github issues

LICENSE

The Apache 2.0 license. See Apache-2.0