• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 159

21 Mar 2025 03:45PM UTC coverage: 71.297% (-2.9%) from 74.243%
159

push

circleci

leeonky
Update remark and exclamation api

12 of 13 new or added lines in 5 files covered. (92.31%)

8 existing lines in 2 files now uncovered.

6801 of 9539 relevant lines covered (71.3%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.23
/DAL-java/src/main/java/com/github/leeonky/dal/DAL.java
1
package com.github.leeonky.dal;
2

3
import com.github.leeonky.dal.ast.node.DALNode;
4
import com.github.leeonky.dal.compiler.Compiler;
5
import com.github.leeonky.dal.compiler.Notations;
6
import com.github.leeonky.dal.runtime.Data;
7
import com.github.leeonky.dal.runtime.Extension;
8
import com.github.leeonky.dal.runtime.RuntimeContextBuilder;
9
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
10
import com.github.leeonky.dal.type.InputCode;
11
import com.github.leeonky.dal.util.TextUtil;
12
import com.github.leeonky.interpreter.SourceCode;
13
import com.github.leeonky.interpreter.SyntaxException;
14
import com.github.leeonky.util.Classes;
15

16
import java.util.*;
17
import java.util.stream.Collectors;
18

19
import static com.github.leeonky.util.Classes.subTypesOf;
20
import static com.github.leeonky.util.function.Extension.not;
21
import static java.util.Arrays.asList;
22
import static java.util.Collections.emptyList;
23
import static java.util.stream.Stream.concat;
24

25
public class DAL {
26
    private final Compiler compiler = new Compiler();
1✔
27
    private final RuntimeContextBuilder runtimeContextBuilder = new RuntimeContextBuilder();
1✔
28
    private static final ThreadLocal<DAL> instance = new ThreadLocal<>();
1✔
29
    private static final ThreadLocal<Map<String, DAL>> instances = new ThreadLocal<>();
1✔
30
    private final String name;
31

32
    @Deprecated
33
    public DAL() {
1✔
34
        name = String.valueOf(hashCode());
1✔
35
    }
1✔
36

37
    @Deprecated
38
    public static synchronized DAL getInstance() {
39
        return dal();
1✔
40
    }
41

42
    @Deprecated
43
    public static DAL create(Class<?>... exceptExtensions) {
44
        Iterator<DALFactory> iterator = ServiceLoader.load(DALFactory.class).iterator();
1✔
45
        if (iterator.hasNext())
1✔
46
            return iterator.next().newInstance();
1✔
47
        return new DAL().extend(exceptExtensions);
1✔
48
    }
49

50
    public static DAL dal() {
51
        if (instance.get() == null)
1✔
52
            instance.set(create("Default"));
1✔
53
        return instance.get();
1✔
54
    }
55

56
    public DAL(String name) {
1✔
57
        this.name = name;
1✔
58
    }
1✔
59

60
    public String getName() {
UNCOV
61
        return name;
×
62
    }
63

64
    public static synchronized DAL dal(String name) {
65
        Map<String, DAL> dalMaps = instances.get();
1✔
66
        if (dalMaps == null) {
1✔
67
            dalMaps = new HashMap<>();
1✔
68
            instances.set(dalMaps);
1✔
69
        }
70
        return dalMaps.computeIfAbsent(name, DAL::create);
1✔
71
    }
72

73
    public static DAL create(String name, Class<?>... exceptExtensions) {
74
        Iterator<DALFactory> iterator = ServiceLoader.load(DALFactory.class).iterator();
1✔
75
        if (iterator.hasNext())
1✔
UNCOV
76
            return iterator.next().newInstance();
×
77
        return new DAL(name).extend(exceptExtensions);
1✔
78
    }
79

80
    public RuntimeContextBuilder getRuntimeContextBuilder() {
81
        return runtimeContextBuilder;
1✔
82
    }
83

84
    public <T> List<T> evaluateAll(Object input, String expressions) {
85
        return evaluateAll(() -> input, expressions);
1✔
86
    }
87

88
    @SuppressWarnings("unchecked")
89
    public <T> List<T> evaluateAll(InputCode<Object> input, String expressions) {
90
        DALRuntimeContext runtimeContext = runtimeContextBuilder.build(input);
1✔
91
        try {
92
            return compile(expressions, runtimeContext).stream()
1✔
93
                    .map(node -> (T) node.evaluate(runtimeContext))
1✔
94
                    .collect(Collectors.toList());
1✔
95
        } catch (Throwable e) {
1✔
96
            if (!runtimeContext.hookError(expressions, e))
1✔
UNCOV
97
                throw e;
×
98
            return emptyList();
1✔
99
        }
100
    }
101

102
    public <T> T evaluate(Object input, String expression) {
103
        return evaluate(() -> input, expression);
1✔
104
    }
105

106
    public <T> T evaluate(InputCode<Object> input, String expression) {
107
        return evaluate(input, expression, null);
1✔
108
    }
109

110
    @SuppressWarnings("unchecked")
111
    public <T> T evaluate(InputCode<Object> input, String expression, Class<?> rootSchema) {
112
        DALRuntimeContext runtimeContext = runtimeContextBuilder.build(input, rootSchema);
1✔
113
        try {
114
            return (T) compileSingle(expression, runtimeContext).evaluate(runtimeContext);
1✔
115
        } catch (Throwable e) {
1✔
116
            if (!runtimeContext.hookError(expression, e))
1✔
117
                throw e;
1✔
118
            return null;
1✔
119
        }
120
    }
121

122
    public Data evaluateData(Object input, String expression) {
UNCOV
123
        return evaluateData(() -> input, expression, null);
×
124
    }
125

126
    public Data evaluateData(InputCode<Object> input, String expression) {
UNCOV
127
        return evaluateData(input, expression, null);
×
128
    }
129

130
    public Data evaluateData(InputCode<Object> input, String expression, Class<?> rootSchema) {
UNCOV
131
        return compileSingle(expression, runtimeContextBuilder.build(input, rootSchema))
×
UNCOV
132
                .evaluateData(runtimeContextBuilder.build(input, rootSchema));
×
133
    }
134

135
    public DALNode compileSingle(String expression, DALRuntimeContext runtimeContext) {
136
        List<DALNode> nodes = compile(expression, runtimeContext);
1✔
137
        if (nodes.size() > 1)
1✔
138
            throw new SyntaxException("more than one expression", getOperandPosition(nodes.get(1)));
1✔
139
        return nodes.get(0);
1✔
140
    }
141

142
    public List<DALNode> compile(String expression, DALRuntimeContext runtimeContext) {
143
        return compiler.compile(new SourceCode(format(expression), Notations.LINE_COMMENTS),
1✔
144
                runtimeContext);
145
    }
146

147
    private int getOperandPosition(DALNode node) {
148
        return node.getPositionBegin() == 0 ? node.getOperandPosition() : node.getPositionBegin();
1✔
149
    }
150

151
    private String format(String expression) {
152
        return String.join("\n", TextUtil.lines(expression));
1✔
153
    }
154

155
    public DAL extend(Class<?>... excepts) {
156
        Set<Class<?>> exceptExtensions = new HashSet<>(asList(excepts));
1✔
157
        concat(subTypesOf(Extension.class, "com.github.leeonky.dal.extensions").stream(),
1✔
158
                subTypesOf(Extension.class, "com.github.leeonky.extensions.dal").stream())
1✔
159
                .filter(not(exceptExtensions::contains))
1✔
160
                .map(Classes::newInstance)
1✔
161
                .sorted(Comparator.comparing(Extension::order))
1✔
162
                .forEach(e -> e.extend(this));
1✔
163
        return this;
1✔
164
    }
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc