Skip to content

Commit 764fdfe

Browse files
committed
Add a function class to the model
1 parent b20d9e0 commit 764fdfe

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package no.ssb.vtl.model;
2+
3+
/*-
4+
* ========================LICENSE_START=================================
5+
* Java VTL
6+
* %%
7+
* Copyright (C) 2016 - 2017 Hadrien Kohl
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =========================LICENSE_END==================================
21+
*/
22+
23+
import com.google.common.collect.ImmutableMap;
24+
25+
import java.util.Map;
26+
27+
/**
28+
* Represents a VTL Function.
29+
*/
30+
public abstract class VTLFunction extends VTLExpression {
31+
32+
private final Map<String, VTLExpression> context;
33+
34+
protected VTLFunction(Map<String, VTLExpression> context) {
35+
this.context = context;
36+
}
37+
38+
public static Builder create(Class<? extends VTLObject> returnType) {
39+
return new Builder(returnType);
40+
}
41+
42+
@Override
43+
public Class<? extends VTLObject> getType() {
44+
return null;
45+
}
46+
47+
@FunctionalInterface
48+
interface Body {
49+
VTLObject execute();
50+
}
51+
52+
/**
53+
* Builder for VTLFunction.
54+
*/
55+
private static class Builder {
56+
57+
private final Class<? extends VTLObject> type;
58+
ImmutableMap.Builder<String, Class<? extends VTLObject>> signature;
59+
ImmutableMap.Builder<String, VTLObject> defaultValues;
60+
61+
private Builder(Class<? extends VTLObject> type) {
62+
this.type = type;
63+
}
64+
65+
public Builder withArgument(String name, Class<? extends VTLObject> type) {
66+
signature.put(name, type);
67+
return this;
68+
}
69+
70+
public Builder withArgument(String name, VTLObject defaultValue) {
71+
defaultValues.put(name, defaultValue);
72+
return withArgument(name, defaultValue.getClass());
73+
}
74+
75+
public VTLFunction build(Map<String, VTLExpression> context) {
76+
throw new UnsupportedOperationException("TODO");
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)