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

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 hits per line

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

0.0
/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;
×
26

27
    public LazyExpression(int id, IOperator op, IVariable[] input, ILazyExpressionValueCache valueCache) {
×
28
        this.id = id;
×
29
        this.op = op;
×
30
        this.input = input;
×
31
        this.valueCache = valueCache;
×
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);
×
36
    }
×
37

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

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

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

61
    @Override
62
    public V getValue() throws EvaluationException {
63
        IValue value;
64
        try {
65
            value = evaluate();
×
66
        } catch (EvaluationException e) {
×
67
            errored = true;
×
68
            throw e;
×
69
        }
×
70
        try {
71
            return (V) value;
×
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);
×
86
        super.invalidate();
×
87
        for (IVariable inputVariable : input) {
×
88
            inputVariable.removeInvalidationListener(this);
×
89
        }
90
    }
×
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