mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-07 21:01:03 +00:00
Increased performance of groovy execution
This commit is contained in:
1 parent
ebf2a376ab
commit
dc8b81d8d5
1 file changed
+6
-6
+6
-6
@@ -2,26 +2,26 @@ package com.sap.sailing.datamining.impl;
|
||||
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyShell;
|
||||
import groovy.lang.Script;
|
||||
|
||||
import com.sap.sailing.datamining.shared.GenericGroupKey;
|
||||
import com.sap.sailing.datamining.shared.GroupKey;
|
||||
|
||||
public class DynamicGrouper<DataType> extends AbstractGrouper<DataType> {
|
||||
|
||||
private String scriptText;
|
||||
private Binding binding;
|
||||
private Script script;
|
||||
|
||||
public DynamicGrouper(String scriptText) {
|
||||
super();
|
||||
this.scriptText = scriptText;
|
||||
binding = new Binding();
|
||||
script = new GroovyShell().parse(scriptText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupKey getGroupKeyFor(DataType dataEntry) {
|
||||
Binding binding = new Binding();
|
||||
binding.setVariable("data", dataEntry);
|
||||
GroovyShell shell = new GroovyShell(binding);
|
||||
Object value = shell.evaluate(scriptText);
|
||||
script.setBinding(binding);
|
||||
Object value = script.run();
|
||||
return new GenericGroupKey<Object>(value);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user