This is an old revision of the document!


To use TimEL you need to import the following dependecy:




implementation 'net.vleo.timel:timel-core:0.9.1'

When the dependency is in place, use the TimEL facade class to compile and evaluate expressions:

// Assemble the evaluation interval as [now, now + 1 second)
Instant now =;
Interval interval = Interval.of(now,, ChronoUnit.SECONDS));
// Compile the expression 1 + 1.
// As we expect an Integer here, we explicitly request an IntegerType
// for the sake of type safety, but we can compile generic code as well.
Expression<Integer> expression = TimEL
        .parse("1 + 1")
        .compile(new IntegerType());
// Iterate through the results
TimeIterator<Integer> itor = TimEL
        .evaluate(expression, interval);
// Since 1+1 is constant we'll have a single sample for the whole interval
int v =;

That's it!

Now let's try something a bit more complex, where we provide an input time-serie variable. As TimEL is a streaming api, it will pull values out of the variable when it needs them. In this case we are going to use a TreeMapVariable, which is a Variable backed by a regular in memory TreeMap:

// Create a new variable backed by a TreeMap
TreeMapVariable<Integer> variable = new TreeMapVariable<>();
TreeMap<Interval, Integer> values = variable.getTreeMap();
// Add some values to the variable
Instant now =;
for(int[] i : new int[][] {
        // start, end, value
        {0, 1, 1},
        {1, 2, 2},
        // gap between 2nd and 3rd minute
        {3, 4, 4}
 }) {
  [0], ChronoUnit.MINUTES),
  [1], ChronoUnit.MINUTES)
    ), i[2]);
// Compile "a * a" without type requirement
Expression<?> expression = TimEL
        .parse("a * a")
        .withVariable("a", new IntegerType(), variable) // Declare 'a' as a int
// Evaluate the expression in the interval [now, now + 5 minutes)
TimeIterator<?> itor = TimEL
        .evaluate(expression, Interval.of(now,, ChronoUnit.MINUTES)));
// Pull the results, effectively evaluating the expression.
// This will print 3 lines, one for each interval, with the value 1, 4 and 16.
    System.out.println("\t" +;

That's it!

  • quickstart.1558123996.txt.gz
  • Last modified: 2019/05/17 20:13
  • by a.leofreddi