• 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

92.59
/api/src/main/java/net/automatalib/automaton/MutableAutomaton.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;
17

18
import java.util.Collection;
19
import java.util.Collections;
20
import java.util.HashSet;
21
import java.util.Set;
22

23
import org.checkerframework.checker.nullness.qual.Nullable;
24

25
/**
26
 * A mutable automaton. This interface adds support for non-destructive modifications, i.e., adding and modifying states
27
 * and transitions. If also removal of states and single transitions (from the set of outgoing transitions) should be
28
 * removed, then {@link ShrinkableAutomaton} is the adequate interface.
29
 *
30
 * @param <S>
31
 *         state class.
32
 * @param <I>
33
 *         input symbol class.
34
 * @param <T>
35
 *         transition class.
36
 * @param <SP>
37
 *         state property.
38
 * @param <TP>
39
 *         transition property.
40
 */
41
public interface MutableAutomaton<S, I, T, SP, TP> extends UniversalAutomaton<S, I, T, SP, TP> {
42

43
    /**
44
     * Removes all states and transitions.
45
     */
46
    void clear();
47

48
    /**
49
     * Adds a new state (with an empty property) to the automaton.
50
     *
51
     * @return the newly created state
52
     */
53
    default S addState() {
54
        return addState(null);
1✔
55
    }
56

57
    /**
58
     * Adds a new state with the given property to the automaton.
59
     *
60
     * @param property
61
     *         the property of the new state
62
     *
63
     * @return the newly created state
64
     */
65
    S addState(@Nullable SP property);
66

67
    /**
68
     * Adds an initial state (with an empty property) to the automaton.
69
     *
70
     * @return the newly created state
71
     */
72
    default S addInitialState() {
73
        return addInitialState(null);
1✔
74
    }
75

76
    /**
77
     * Adds an initial state with the given property to the automaton.
78
     *
79
     * @param property
80
     *         the property of the new state
81
     *
82
     * @return the newly created state
83
     */
84
    default S addInitialState(@Nullable SP property) {
85
        S state = addState(property);
1✔
86
        setInitial(state, true);
1✔
87
        return state;
1✔
88
    }
89

90
    void setInitial(S state, boolean initial);
91

92
    void setStateProperty(S state, SP property);
93

94
    void setTransitionProperty(T transition, TP property);
95

96
    default void addTransitions(S state, I input, Collection<? extends T> transitions) {
97
        Set<T> newTransitions = new HashSet<>(getTransitions(state, input));
1✔
98
        if (!newTransitions.addAll(transitions)) {
1✔
99
            return;
1✔
100
        }
101
        setTransitions(state, input, newTransitions);
1✔
102
    }
1✔
103

104
    void setTransitions(S state, I input, Collection<? extends T> transitions);
105

106
    default void removeTransition(S state, I input, T transition) {
107
        Set<T> transitions = new HashSet<>(getTransitions(state, input));
1✔
108
        if (!transitions.remove(transition)) {
1✔
109
            return;
×
110
        }
111
        setTransitions(state, input, transitions);
1✔
112
    }
1✔
113

114
    default void removeAllTransitions(S state, I input) {
115
        setTransitions(state, input, Collections.emptySet());
1✔
116
    }
1✔
117

118
    void removeAllTransitions(S state);
119

120
    default T addTransition(S state, I input, S successor, TP properties) {
121
        T trans = createTransition(successor, properties);
1✔
122
        addTransition(state, input, trans);
1✔
123
        return trans;
1✔
124
    }
125

126
    default void addTransition(S state, I input, T transition) {
127
        Set<T> transitions = new HashSet<>(getTransitions(state, input));
1✔
128
        if (!transitions.add(transition)) {
1✔
129
            return;
×
130
        }
131
        setTransitions(state, input, transitions);
1✔
132
    }
1✔
133

134
    T createTransition(S successor, TP properties);
135

136
    default T copyTransition(T trans, S succ) {
137
        TP property = getTransitionProperty(trans);
1✔
138
        return createTransition(succ, property);
1✔
139
    }
140
}
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