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

CyclopsMC / IntegratedDynamics / 22186773560

19 Feb 2026 02:52PM UTC coverage: 52.603% (+0.2%) from 52.363%
22186773560

push

github

web-flow
Remove Lombok dependency (#1604)

2911 of 8664 branches covered (33.6%)

Branch coverage included in aggregate %.

17683 of 30486 relevant lines covered (58.0%)

3.01 hits per line

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

76.7
/src/main/java/org/cyclops/integrateddynamics/core/network/PositionedAddonsNetwork.java
1
package org.cyclops.integrateddynamics.core.network;
2

3
import com.google.common.collect.Maps;
4
import com.google.common.collect.Sets;
5
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
6
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
7
import org.apache.commons.lang3.tuple.Pair;
8
import org.cyclops.cyclopscore.datastructure.Wrapper;
9
import org.cyclops.integrateddynamics.api.network.INetwork;
10
import org.cyclops.integrateddynamics.api.network.IPartPosIteratorHandler;
11
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
12
import org.cyclops.integrateddynamics.api.part.PartPos;
13
import org.cyclops.integrateddynamics.api.part.PrioritizedPartPos;
14

15
import javax.annotation.Nullable;
16
import java.util.Collection;
17
import java.util.Collections;
18
import java.util.Iterator;
19
import java.util.Map;
20
import java.util.Set;
21
import java.util.TreeSet;
22

23
/**
24
 * A network that can hold prioritized positions.
25
 * @author rubensworks
26
 */
27
public abstract class PositionedAddonsNetwork implements IPositionedAddonsNetwork {
2✔
28

29
    private INetwork network;
30
    private final Set<PrioritizedPartPos> allPositions = Sets.newTreeSet();
3✔
31

32
    public INetwork getNetwork() {
33
        return network;
×
34
    }
35

36
    public void setNetwork(INetwork network) {
37
        this.network = network;
×
38
    }
×
39
    private final Int2ObjectMap<Set<PrioritizedPartPos>> positions = new Int2ObjectOpenHashMap<>();
5✔
40
    private final Map<PartPos, Integer> positionChannels = Maps.newHashMap();
3✔
41
    // We store the thread id together with the disabled position.
42
    // This is to make sure that different threads can safely iterate over positions in parallel
43
    // without clashing with each other, as this could lead to problems such as in #194.
44
    // This for example applies to the ingredient observer and in-world ingredient movement.
45
    private final Set<Pair<Long, PartPos>> disabledPositions = Sets.newHashSet();
3✔
46

47
    private IPartPosIteratorHandler partPosIteratorHandler = null;
4✔
48

49
    @Override
50
    public int[] getChannels() {
51
        return positions.keySet().toIntArray();
5✔
52
    }
53

54
    @Override
55
    public boolean hasPositions() {
56
        return !positions.isEmpty();
×
57
    }
58

59
    @Override
60
    public Collection<PrioritizedPartPos> getPrioritizedPositions(int channel) {
61
        if (channel == WILDCARD_CHANNEL) {
3✔
62
            return getPrioritizedPositions();
3✔
63
        }
64
        Set<PrioritizedPartPos> positions = this.positions.get(channel);
6✔
65
        Set<PrioritizedPartPos> wildcardPositions = this.positions.get(WILDCARD_CHANNEL);
6✔
66
        if (positions == null) {
2!
67
            if (wildcardPositions != null) {
×
68
                return wildcardPositions;
×
69
            }
70
            positions = Collections.emptySet();
×
71
        }
72
        if (wildcardPositions == null) {
2!
73
            return positions;
2✔
74
        }
75
        TreeSet<PrioritizedPartPos> merged = Sets.newTreeSet();
×
76
        merged.addAll(positions);
×
77
        merged.addAll(wildcardPositions);
×
78
        return merged;
×
79
    }
80

81
    @Override
82
    public Collection<PrioritizedPartPos> getPrioritizedPositions() {
83
        return this.allPositions;
3✔
84
    }
85

86
    @Override
87
    public int getPositionChannel(PartPos pos) {
88
        return this.positionChannels.getOrDefault(pos, -1);
×
89
    }
90

91
    protected void invalidateIterators() {
92
        setPartPosIteratorHandler(null);
3✔
93
    }
1✔
94

95
    @Override
96
    public void setPartPosIteratorHandler(@Nullable IPartPosIteratorHandler iteratorHandler) {
97
        this.partPosIteratorHandler = iteratorHandler;
3✔
98
    }
1✔
99

100
    @Nullable
101
    @Override
102
    public IPartPosIteratorHandler getPartPosIteratorHandler() {
103
        if (partPosIteratorHandler != null) {
3✔
104
            return partPosIteratorHandler;
3✔
105
        }
106
        return null;
2✔
107
    }
108

109
    @Override
110
    public boolean addPosition(PartPos pos, int priority, int channel) {
111
        invalidateIterators();
2✔
112

113
        PrioritizedPartPos prioritizedPosition = PrioritizedPartPos.of(pos, priority);
4✔
114
        if (allPositions.add(prioritizedPosition)) {
5!
115
            Set<PrioritizedPartPos> positions = this.positions.get(channel);
6✔
116
            if (positions == null) {
2✔
117
                positions = Sets.newTreeSet();
2✔
118
                this.positions.put(channel, positions);
6✔
119
            }
120
            positions.add(prioritizedPosition);
4✔
121
            this.positionChannels.put(pos, channel);
7✔
122
            this.onPositionAdded(channel, prioritizedPosition);
4✔
123
            return true;
2✔
124
        }
125
        return false;
×
126
    }
127

128
    protected void onPositionAdded(int channel, PrioritizedPartPos pos) {
129

130
    }
1✔
131

132
    @Override
133
    public void removePosition(PartPos pos) {
134
        invalidateIterators();
2✔
135

136
        Wrapper<Integer> removedChannel = new Wrapper<>(-2);
6✔
137
        Wrapper<PrioritizedPartPos> removedPos = new Wrapper<>(null);
5✔
138
        for (Int2ObjectMap.Entry<Set<PrioritizedPartPos>> entry : this.positions.int2ObjectEntrySet()) {
12✔
139
            int channel = entry.getIntKey();
3✔
140
            Set<PrioritizedPartPos> positions = entry.getValue();
4✔
141
            Iterator<PrioritizedPartPos> it = positions.iterator();
3✔
142
            while (it.hasNext()) {
3!
143
                PrioritizedPartPos prioritizedPartPos = it.next();
4✔
144
                if (prioritizedPartPos.getPartPos().equals(pos)) {
5!
145
                    it.remove();
2✔
146
                    allPositions.remove(prioritizedPartPos);
5✔
147
                    removedPos.set(prioritizedPartPos);
3✔
148
                    removedChannel.set(channel);
4✔
149
                    break;
1✔
150
                }
151
            }
×
152
        }
1✔
153
        int channel = removedChannel.get();
5✔
154
        if (channel != -2) {
3!
155
            this.onPositionRemoved(channel, removedPos.get());
6✔
156
            if (positions.get(channel).isEmpty()) {
7✔
157
                this.positions.remove(channel);
5✔
158
            }
159
        }
160
        positionChannels.remove(pos);
5✔
161
    }
1✔
162

163
    protected void onPositionRemoved(int channel, PrioritizedPartPos pos) {
164

165
    }
1✔
166

167
    @Override
168
    public boolean isPositionDisabled(PartPos pos) {
169
        return disabledPositions.contains(Pair.of(Thread.currentThread().getId(), pos));
9✔
170
    }
171

172
    @Override
173
    public void disablePosition(PartPos pos) {
174
        disabledPositions.add(Pair.of(Thread.currentThread().getId(), pos));
9✔
175
    }
1✔
176

177
    @Override
178
    public void enablePosition(PartPos pos) {
179
        disabledPositions.remove(Pair.of(Thread.currentThread().getId(), pos));
9✔
180
    }
1✔
181

182
}
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