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

CyclopsMC / IntegratedDynamics / 22037263793

15 Feb 2026 02:22PM UTC coverage: 45.155% (+0.04%) from 45.112%
22037263793

push

github

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

2639 of 8620 branches covered (30.61%)

Branch coverage included in aggregate %.

11938 of 23662 relevant lines covered (50.45%)

2.4 hits per line

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

76.6
/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.apache.logging.log4j.Level;
5
import org.cyclops.integrateddynamics.GeneralConfig;
6
import org.cyclops.integrateddynamics.IntegratedDynamics;
7
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
8
import org.cyclops.integrateddynamics.api.evaluate.expression.IExpression;
9
import org.cyclops.integrateddynamics.api.evaluate.expression.ILazyExpressionValueCache;
10
import org.cyclops.integrateddynamics.api.evaluate.expression.VariableAdapter;
11
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
12
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
13
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
14
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable;
15
import org.cyclops.integrateddynamics.core.helper.L10NValues;
16

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

24
    private final int id;
25
    private final IOperator op;
26
    private final IVariable[] input;
27
    private final ILazyExpressionValueCache valueCache;
28
    private boolean errored = false;
3✔
29

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

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

41
    @Override
42
    public IValue evaluate() throws EvaluationException {
43
        if(valueCache.hasValue(id)) {
6✔
44
            return valueCache.getValue(id);
6✔
45
        }
46
        if (GeneralConfig.logCardEvaluation) {
2!
47
            IntegratedDynamics.clog(Level.INFO, "Evaluating variable card with ID: " + id);
×
48
        }
49
        IValue value = op.evaluate(input);
6✔
50
        for (IVariable inputVariable : input) {
17✔
51
            inputVariable.addInvalidationListener(this);
3✔
52
        }
53
        valueCache.setValue(id, value);
6✔
54
        return value;
2✔
55
    }
56

57
    @Override
58
    public boolean hasErrored() {
59
        return errored;
3✔
60
    }
61

62
    @Override
63
    public IValueType<V> getType() {
64
        return op.getConditionalOutputType(input);
6✔
65
    }
66

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

89
    @Override
90
    public void invalidate() {
91
        valueCache.removeValue(id);
5✔
92
        super.invalidate();
2✔
93
        for (IVariable inputVariable : input) {
17✔
94
            inputVariable.removeInvalidationListener(this);
3✔
95
        }
96
    }
1✔
97

98
    public IOperator getOperator() {
99
        return op;
×
100
    }
101

102
    public IVariable[] getInput() {
103
        return input;
×
104
    }
105
}
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