• 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/api/ingredient/IIngredientComponentStorageObservable.java
1
package org.cyclops.integrateddynamics.api.ingredient;
2

3
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
4
import org.cyclops.cyclopscore.ingredient.collection.IIngredientCollection;
5
import org.cyclops.cyclopscore.ingredient.collection.diff.IngredientCollectionDiff;
6
import org.cyclops.integrateddynamics.api.part.PartPos;
7
import org.cyclops.integrateddynamics.api.part.PrioritizedPartPos;
8

9
/**
10
 * An observable ingredient component storage.
11
 * @param <T> The instance type.
12
 * @param <M> The matching condition parameter, may be Void. Instances MUST properly implement the equals method.
13
 * @author rubensworks
14
 */
15
public interface IIngredientComponentStorageObservable<T, M> {
16

17
    /**
18
     * @return The ingredient component type this storage applies to.
19
     */
20
    public IngredientComponent<T, M> getComponent();
21

22
    /**
23
     * Add an observer for listing to index change events.
24
     * @param observer An index change observer.
25
     */
26
    public void addObserver(IIndexChangeObserver<T, M> observer);
27

28
    /**
29
     * Remove the given index change observer.
30
     * This will silently fail if the given observer was not registered.
31
     * @param observer An index change observer.
32
     */
33
    public void removeObserver(IIndexChangeObserver<T, M> observer);
34

35
    /**
36
     * Indicate that this network should observe starting somewhere in the future.
37
     *
38
     * This should be called when observer diffs are needed,
39
     * but are not urgent.
40
     *
41
     * This is a more efficient variant of
42
     * {@link IIngredientComponentStorageObservable#scheduleObservationForced(int, PartPos)}.
43
     *
44
     * This should be called each time that observations are needed,
45
     * as this observable will reset the internal flag after each observation.
46
     */
47
    public void scheduleObservation();
48

49
    /**
50
     * Indicate that this network should observe starting in the next tick.
51
     *
52
     * This is a stricter variant of {@link IIngredientComponentStorageObservable#scheduleObservation()},
53
     * and can only be done for a single position and channel.
54
     *
55
     * This should be called when observer diffs are needed in the next tick for the given position.
56
     * @param channel The channel to force an observation in.
57
     * @param pos The position to force an observation for.
58
     */
59
    public void scheduleObservationForced(int channel, PartPos pos);
60

61
    /**
62
     * @return If an observation should happen.
63
     */
64
    public boolean shouldObserve();
65

66
    /**
67
     * @param channel The channel to check for a forced observation in.
68
     * @return If the given channel contains a forced observation scheduling that has not been processed yet.
69
     */
70
    public boolean isObservationForcedPending(int channel);
71

72
    /**
73
     * Manually run observer synchronously (even if async is allowed), if it should observe.
74
     */
75
    public void runObserverSync();
76

77
    /**
78
     * Get the last indexed storage at the given channel.
79
     * @param channel A channel id.
80
     * @return A channel index.
81
     */
82
    public IIngredientPositionsIndex<T, M> getChannelIndex(int channel);
83

84
    /**
85
     * An observer for listening to storage changes.
86
     * @param <T> The instance type.
87
     * @param <M> The match condition type.
88
     */
89
    public static interface IIndexChangeObserver<T, M> {
90
        /**
91
         * Called when a change event is emitted.
92
         * @param event A storage change event.
93
         */
94
        public void onChange(StorageChangeEvent<T, M> event);
95
    }
96

97
    /**
98
     * A storage change event.
99
     * This is thrown for either additions or deletions,
100
     * as identified by the change type.
101
     * @param <T> The instance type.
102
     * @param <M> The match condition type.
103
     */
104
    public static class StorageChangeEvent<T, M> {
105
        private final int channel;
106
        private final PrioritizedPartPos pos;
107
        private final Change changeType;
108
        private final boolean completeChange;
109
        private final IIngredientCollection<T, M> instances;
110
        private final boolean initialChange;
111

112
        public StorageChangeEvent(int channel, PrioritizedPartPos pos,
113
                                  Change changeType, boolean completeChange, IIngredientCollection<T, M> instances,
114
                                  boolean initialChange) {
×
115
            this.channel = channel;
×
116
            this.pos = pos;
×
117
            this.changeType = changeType;
×
118
            this.completeChange = completeChange;
×
119
            this.instances = instances;
×
120
            this.initialChange = initialChange;
×
121
        }
×
122

123
        public int getChannel() {
124
            return channel;
×
125
        }
126

127
        public PrioritizedPartPos getPos() {
128
            return pos;
×
129
        }
130

131
        /**
132
         * @return The type of change.
133
         */
134
        public Change getChangeType() {
135
            return changeType;
×
136
        }
137

138
        /**
139
         * @return If the change is complete.
140
         *         In the case of additions, this means that the storage became completely full.
141
         *         In the case of deletions, this means that the storage became completely empty.
142
         */
143
        public boolean isCompleteChange() {
144
            return completeChange;
×
145
        }
146

147
        /**
148
         * @return The instances that were added or removed.
149
         */
150
        public IIngredientCollection<T, M> getInstances() {
151
            return instances;
×
152
        }
153

154
        /**
155
         * @return If this change occurred during initialization of the observer.
156
         */
157
        public boolean isInitialChange() {
158
            return initialChange;
×
159
        }
160

161
        @Override
162
        public String toString() {
163
            return String.format("[%s at %s(%s): %s]", getChangeType().name(), getPos(), getChannel(), getInstances());
×
164
        }
165

166
        /**
167
         * @return Get the collection diff from this event.
168
         */
169
        public IngredientCollectionDiff<T, M> getDiff() {
170
            return new IngredientCollectionDiff<>(
×
171
                    changeType == IIngredientComponentStorageObservable.Change.ADDITION ? getInstances() : null,
×
172
                    changeType == IIngredientComponentStorageObservable.Change.DELETION ? getInstances() : null,
×
173
                    false);
174
        }
175
    }
176

177
    /**
178
     * A type of change.
179
     */
180
    public static enum Change {
×
181
        ADDITION,
×
182
        DELETION
×
183
    }
184

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