package no.ssb.vtl.model;

import java.util.function.Function;

public abstract class VTLExpression implements Function<DataPoint, VTLObject> {
    
    public abstract Class<?> getType();
    
    @Override
    public String toString() {
        return "VTLExpression";
    }
    
    
    public static class Builder {
        private final Function<DataPoint, VTLObject> function;
        private final Class<?> type;
        private String description;
    
        public Builder(Class<?> type, Function<DataPoint, VTLObject> function) {
            this.function = function;
            this.type = type;
        }
    
        public Builder description(String description) {
            this.description = description;
            return this;
        }
    
        public VTLExpression build() {
            return new VTLExpression() {
                @Override
                public VTLObject apply(DataPoint dataPoint) {
                    return function.apply(dataPoint);
                }
        
                @Override
                public Class<?> getType() {
                    return type;
                }
        
                @Override
                public String toString() {
                    return description;
                }
            };
        }
    }
}

@@ -57,16 +57,229 @@
 ction;%0A%0A
+/**%0A * Base VTL expression%0A *%0A * Represents a scalar value (VTLObject)  whose computation can be function of a data point (ultimately of a Bindings,%0A * but we are not there yet) but still exposes its type.%0A *%0A */%0A
 public a

Add javadoc for VTLExpression