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

CyclopsMC / IntegratedDynamics / 18427741591

11 Oct 2025 09:40AM UTC coverage: 53.024% (+0.001%) from 53.023%
18427741591

push

github

rubensworks
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21

2869 of 8770 branches covered (32.71%)

Branch coverage included in aggregate %.

17332 of 29328 relevant lines covered (59.1%)

3.07 hits per line

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

79.07
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/expression/LazyExpression.java
1
package org.cyclops.integrateddynamics.core.evaluate.expression;
2

3
import net.minecraft.network.chat.Component;
4
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
5
import org.cyclops.integrateddynamics.api.evaluate.expression.IExpression;
6
import org.cyclops.integrateddynamics.api.evaluate.expression.ILazyExpressionValueCache;
7
import org.cyclops.integrateddynamics.api.evaluate.expression.VariableAdapter;
8
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
9
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
10
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
11
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable;
12
import org.cyclops.integrateddynamics.core.helper.L10NValues;
13

14
/**
15
 * A generic expression with arbitrarily nested binary operations.
16
 * This is evaluated in a lazy manner.
17
 * @author rubensworks
18
 */
19
public class LazyExpression<V extends IValue> extends VariableAdapter<V> implements IExpression<V> {
20

21
    private final int id;
22
    private final IOperator op;
23
    private final IVariable[] input;
24
    private final ILazyExpressionValueCache valueCache;
25
    private boolean errored = false;
3✔
26

27
    public LazyExpression(int id, IOperator op, IVariable[] input, ILazyExpressionValueCache valueCache) {
2✔
28
        this.id = id;
3✔
29
        this.op = op;
3✔
30
        this.input = input;
3✔
31
        this.valueCache = valueCache;
3✔
32

33
        // Make sure that any previous values become un-cached,
34
        // so that the first evaluation of this expression is guaranteed to happen.
35
        valueCache.removeValue(id);
3✔
36
    }
1✔
37

38
    @Override
39
    public IValue evaluate() throws EvaluationException {
40
        if(valueCache.hasValue(id)) {
6✔
41
            return valueCache.getValue(id);
6✔
42
        }
43
        IValue value = op.evaluate(input);
6✔
44
        for (IVariable inputVariable : input) {
17✔
45
            inputVariable.addInvalidationListener(this);
3✔
46
        }
47
        valueCache.setValue(id, value);
6✔
48
        return value;
2✔
49
    }
50

51
    @Override
52
    public boolean hasErrored() {
53
        return errored;
3✔
54
    }
55

56
    @Override
57
    public IValueType<V> getType() {
58
        return op.getConditionalOutputType(input);
6✔
59
    }
60

61
    @Override
62
    public V getValue() throws EvaluationException {
63
        IValue value;
64
        try {
65
            value = evaluate();
3✔
66
        } catch (EvaluationException e) {
1✔
67
            errored = true;
3✔
68
            throw e;
2✔
69
        }
1✔
70
        try {
71
            return (V) value;
2✔
72
        } catch (ClassCastException e) {
×
73
            errored = true;
×
74
            EvaluationException e2 = new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_WRONGTYPEOUTPUT,
×
75
                    op,
76
                    Component.translatable(value.getType().getTranslationKey()),
×
77
                    Component.translatable(op.getOutputType().getTranslationKey())));
×
78
            e2.addResolutionListeners(this::invalidate);
×
79
            throw e2;
×
80
        }
81
    }
82

83
    @Override
84
    public void invalidate() {
85
        valueCache.removeValue(id);
5✔
86
        super.invalidate();
2✔
87
        for (IVariable inputVariable : input) {
17✔
88
            inputVariable.removeInvalidationListener(this);
3✔
89
        }
90
    }
1✔
91

92
    public IOperator getOperator() {
93
        return op;
×
94
    }
95

96
    public IVariable[] getInput() {
97
        return input;
×
98
    }
99
}
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