• 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

96.67
/core/src/main/java/net/automatalib/automaton/base/AbstractFastMutable.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.automaton.base;
17

18
import java.util.Collection;
19

20
import net.automatalib.alphabet.Alphabet;
21
import net.automatalib.alphabet.SupportsGrowingAlphabet;
22
import net.automatalib.automaton.ShrinkableAutomaton;
23
import net.automatalib.automaton.UniversalFiniteAlphabetAutomaton;
24
import net.automatalib.automaton.concept.StateIDs;
25
import net.automatalib.automaton.concept.StateLocalInput;
26
import net.automatalib.common.util.mapping.ArrayMapping;
27
import net.automatalib.common.util.mapping.MutableMapping;
28
import net.automatalib.common.util.nid.DynamicList;
29
import net.automatalib.common.util.nid.IDChangeNotifier;
30
import org.checkerframework.checker.nullness.qual.Nullable;
31

32
/**
33
 * Shared functionality for (non-) deterministic mutable automata.
34
 */
35
public abstract class AbstractFastMutable<S extends AbstractFastState<?>, I, T, SP, TP>
36
        implements ShrinkableAutomaton<S, I, T, SP, TP>,
37
                   UniversalFiniteAlphabetAutomaton<S, I, T, SP, TP>,
38
                   StateIDs<S>,
39
                   SupportsGrowingAlphabet<I>,
40
                   StateLocalInput<S, I> {
41

42
    protected final Alphabet<I> inputAlphabet;
43
    private final DynamicList<S> states = new DynamicList<>();
2✔
44
    private final IDChangeNotifier<S> tracker = new IDChangeNotifier<>();
2✔
45

46
    public AbstractFastMutable(Alphabet<I> inputAlphabet) {
2✔
47
        this.inputAlphabet = inputAlphabet;
2✔
48
    }
2✔
49

50
    @Override
51
    public int getStateId(S state) {
52
        return state.getId();
2✔
53
    }
54

55
    @Override
56
    public S getState(int id) {
57
        return states.get(id);
2✔
58
    }
59

60
    @Override
61
    public S addState(@Nullable SP property) {
62
        S newState = createState(property);
2✔
63
        states.add(newState);
2✔
64
        return newState;
2✔
65
    }
66

67
    @Override
68
    public void removeAllTransitions(S state) {
69
        state.clearTransitionObjects();
2✔
70
    }
2✔
71

72
    protected abstract S createState(@Nullable SP property);
73

74
    @Override
75
    public void removeState(S state, @Nullable S replacement) {
76
        ShrinkableAutomaton.unlinkState(this, state, replacement, inputAlphabet);
2✔
77
        states.remove(state, tracker);
2✔
78
    }
2✔
79

80
    @Override
81
    public void clear() {
82
        states.clear();
2✔
83
    }
2✔
84

85
    @Override
86
    public Alphabet<I> getInputAlphabet() {
87
        return inputAlphabet;
2✔
88
    }
89

90
    @Override
91
    public <V> MutableMapping<S, V> createDynamicStateMapping() {
92
        final ArrayMapping<S, V> mapping = new ArrayMapping<>(size());
2✔
93
        tracker.addListener(mapping, true);
2✔
94
        return mapping;
2✔
95
    }
96

97
    @Override
98
    public void addAlphabetSymbol(I symbol) {
99

100
        if (!this.inputAlphabet.containsSymbol(symbol)) {
2✔
101
            this.inputAlphabet.asGrowingAlphabetOrThrowException().addSymbol(symbol);
×
102
        }
103

104
        // even if the symbol was already in the alphabet, we need to make sure to be able to store the new symbol
105
        final int newAlphabetSize = this.inputAlphabet.size();
2✔
106

107
        for (S s : this.getStates()) {
2✔
108
            s.ensureInputCapacity(newAlphabetSize);
2✔
109
        }
2✔
110
    }
2✔
111

112
    @Override
113
    public Collection<S> getStates() {
114
        return states;
2✔
115
    }
116

117
    @Override
118
    public StateIDs<S> stateIDs() {
119
        return this;
2✔
120
    }
121

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