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

LearnLib / automatalib / 13138848026

04 Feb 2025 02:53PM UTC coverage: 92.108% (+2.2%) from 89.877%
13138848026

push

github

mtf90
[maven-release-plugin] prepare release automatalib-0.12.0

16609 of 18032 relevant lines covered (92.11%)

1.7 hits per line

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

89.74
/util/src/main/java/net/automatalib/util/minimizer/State.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of AutomataLib <https://automatalib.net>.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.automatalib.util.minimizer;
17

18
import java.util.ArrayList;
19
import java.util.List;
20

21
import net.automatalib.common.smartcollection.AbstractBasicLinkedListEntry;
22
import net.automatalib.common.smartcollection.ElementReference;
23
import org.checkerframework.checker.nullness.qual.Nullable;
24

25
/**
26
 * State record. Represents a state in the automaton model the minimizer operates on, and also keeps various other
27
 * information that is relevant for the process.
28
 *
29
 * @param <S>
30
 *         original state class.
31
 * @param <L>
32
 *         original transition label class.
33
 */
34
final class State<S, L> extends AbstractBasicLinkedListEntry<State<S, L>, State<S, L>> {
35

36
    // The identifier of this state.
37
    private final int id;
38
    // The state in the original automaton.
39
    private final S originalState;
40
    // The list of incoming edges.
41
    private final List<Edge<S, L>> incoming = new ArrayList<>();
2✔
42
    // The list of outgoing edges.
43
    private final List<Edge<S, L>> outgoing = new ArrayList<>();
2✔
44

45
    // The block that contains this state.
46
    private Block<S, L> block;
47
    // A reference to this state in the block's collection.
48
    private ElementReference blockReference;
49

50
    // Signals whether this state is a split point, i.e.,
51
    // differs from the preceeding states in the final list.
52
    private boolean splitPoint;
53

54
    // The signature of the state, i.e., a sorted list of the (relevant)
55
    // outgoing edge labels.
56
    private List<TransitionLabel<S, L>> signature = new ArrayList<>();
2✔
57

58
    /**
59
     * Constructor.
60
     *
61
     * @param id
62
     *         the state id.
63
     * @param originalState
64
     *         the original state represented by this record.
65
     */
66
    State(int id, S originalState) {
2✔
67
        this.id = id;
2✔
68
        this.originalState = originalState;
2✔
69
    }
2✔
70

71
    /**
72
     * Retrieves the state id.
73
     *
74
     * @return the state id.
75
     */
76
    public int getId() {
77
        return id;
2✔
78
    }
79

80
    /**
81
     * Retrieves the original state represented by this record.
82
     *
83
     * @return the original state object.
84
     */
85
    public S getOriginalState() {
86
        return originalState;
2✔
87
    }
88

89
    /**
90
     * Retrieves the block which contains this state.
91
     *
92
     * @return the block containing this state.
93
     */
94
    public Block<S, L> getBlock() {
95
        return block;
2✔
96
    }
97

98
    /**
99
     * Sets the block which contains this state.
100
     *
101
     * @param block
102
     *         the new block containing this state.
103
     */
104
    public void setBlock(Block<S, L> block) {
105
        this.block = block;
2✔
106
    }
2✔
107

108
    /**
109
     * Retrieves the list of incoming edges.
110
     *
111
     * @return the incoming edges.
112
     */
113
    public List<Edge<S, L>> getIncoming() {
114
        return incoming;
2✔
115
    }
116

117
    /**
118
     * Retrieves the list of outgoing edges.
119
     *
120
     * @return the outgoing edges.
121
     */
122
    public List<Edge<S, L>> getOutgoing() {
123
        return outgoing;
×
124
    }
125

126
    /**
127
     * Adds a new incoming edge.
128
     *
129
     * @param edge
130
     *         the incoming edge.
131
     */
132
    public void addIncomingEdge(Edge<S, L> edge) {
133
        incoming.add(edge);
2✔
134
    }
2✔
135

136
    /**
137
     * Adds a new outgoing edge.
138
     *
139
     * @param edge
140
     *         the outgoing edge.
141
     */
142
    public void addOutgoingEdge(Edge<S, L> edge) {
143
        outgoing.add(edge);
2✔
144
    }
2✔
145

146
    /**
147
     * Retrieves the split point property of this state.
148
     *
149
     * @return {@code true} iff this state is a split point, {@code false} otherwise.
150
     */
151
    public boolean isSplitPoint() {
152
        return splitPoint;
2✔
153
    }
154

155
    /**
156
     * Sets the split point property of this state.
157
     *
158
     * @param splitPoint
159
     *         whether this state is a split point.
160
     */
161
    public void setSplitPoint(boolean splitPoint) {
162
        this.splitPoint = splitPoint;
2✔
163
    }
2✔
164

165
    /**
166
     * Resets the information needed for a single split step associated with this state, i.e., the split point property
167
     * and the signature.
168
     */
169
    public void reset() {
170
        splitPoint = false;
2✔
171
        if (signature == null) {
2✔
172
            signature = new ArrayList<>();
×
173
        } else {
174
            signature.clear();
2✔
175
        }
176
    }
2✔
177

178
    /**
179
     * Adds a transition label (letter) to this state's signature.
180
     *
181
     * @param letter
182
     *         the letter to add.
183
     *
184
     * @return {@code true} iff this was the first letter to be added to the signature, {@code false} otherwise.
185
     */
186
    public boolean addToSignature(TransitionLabel<S, L> letter) {
187
        boolean first = signature.isEmpty();
2✔
188
        signature.add(letter);
2✔
189
        return first;
2✔
190
    }
191

192
    /**
193
     * Retrieves the letter from the signature with the given index. If there is no such index (because the signature is
194
     * shorter), {@code null} is returned.
195
     *
196
     * @param index
197
     *         the signature index.
198
     *
199
     * @return the respective letter of the signature, or {@code null}.
200
     */
201
    public @Nullable TransitionLabel<S, L> getSignatureLetter(int index) {
202
        if (index < signature.size()) {
2✔
203
            return signature.get(index);
2✔
204
        }
205
        return null;
2✔
206
    }
207

208
    /**
209
     * Retrieves the block reference.
210
     *
211
     * @return the reference.
212
     */
213
    public ElementReference getBlockReference() {
214
        return blockReference;
2✔
215
    }
216

217
    /**
218
     * Sets the reference referencing this state in its block's collection.
219
     *
220
     * @param ref
221
     *         the reference.
222
     */
223
    public void setBlockReference(ElementReference ref) {
224
        this.blockReference = ref;
2✔
225
    }
2✔
226

227
    /**
228
     * Retrieves the signature of this state.
229
     *
230
     * @return the signature.
231
     */
232
    public List<TransitionLabel<S, L>> getSignature() {
233
        return signature;
×
234
    }
235

236
    /**
237
     * Retrieves whether the block containing this state is a singleton, i.e., contains <i>only</i> this state.
238
     *
239
     * @return {@code true} if the containing block is a singleton, {@code false} otherwise.
240
     */
241
    public boolean isSingletonBlock() {
242
        return block.size() == 1;
2✔
243
    }
244

245
    @Override
246
    public String toString() {
247
        return String.valueOf(originalState);
×
248
    }
249

250
    @Override
251
    public State<S, L> getElement() {
252
        return this;
2✔
253
    }
254
}
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

© 2025 Coveralls, Inc