package no.ssb.vtl.model;

/*-
 * ========================LICENSE_START=================================
 * Java VTL
 * %%
 * Copyright (C) 2016 - 2017 Hadrien Kohl
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =========================LICENSE_END==================================
 */

import java.util.function.Function;

/**
 * Base VTL expression
 *
 * Represents a scalar value (VTLObject)  whose computation can be function of a data point (ultimately of a Bindings,
 * but we are not there yet) but still exposes its type.
 *
 */
public abstract class VTLExpression implements Function<DataPoint, VTLObject>, VTLTyped {

    @Override
    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;
                }
            };
        }
    }
}

@@ -801,16 +801,46 @@
 ==%0A */%0A%0A
+import javax.script.Bindings;%0A
 import j
@@ -938,17 +938,16 @@
 LObject)
- 
  whose c
@@ -961,14 +961,10 @@
 ion 
-can be
+is
  fun
@@ -978,74 +978,16 @@
 f a 
-data point (ultimately of a Bindings,%0A * but we are not there yet)
+Bindings
  but
@@ -1011,19 +1011,16 @@
 s type.%0A
- *%0A
  */%0Apubl
@@ -1067,33 +1067,32 @@
 ts Function%3C
-DataPoint
+Bindings
 , VTLObject%3E
@@ -1252,21 +1252,16 @@
  %7D%0A    %0A
-    %0A
     publ
@@ -1313,33 +1313,32 @@
 al Function%3C
-DataPoint
+Bindings
 , VTLObject%3E
@@ -1473,25 +1473,24 @@
 unction%3C
-DataPoint
+Bindings
 , VTLObj
@@ -1879,17 +1879,16 @@
 ply(
-DataPoint
+Bindings
  dat

Use Bindings as parameter of the VTLExpression