import org.graalvm.polyglot.*;
import org.graalvm.polyglot.proxy.*;
public class DataFilter {
public static void main(String[] args) {
List<DataItem> data = new ArrayList<>();
data.add(new DataItem("A", 10));
data.add(new DataItem("B", 20));
data.add(new DataItem("C", 30));
Context polyglot = Context.newBuilder().allowAllAccess(true).build();
polyglot.eval(
"js",
"var filteredData = d3.select(data).filter(function(d) { return d.value > 15; }).data();");
Value filteredDataValue = polyglot.getBindings("js").getMember("filteredData");
List<DataItem> filteredData = filteredDataValue.as(List.class);
for (DataItem item : filteredData) {
System.out.println(item.getName() + ": " + item.getValue());
}
}
public static class DataItem {
private String name;
private int value;
public DataItem(String name, int value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public int getValue() {
return value;
}
}
}