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

LearnLib / automatalib / 6673214172

27 Oct 2023 11:30PM UTC coverage: 89.166% (-0.6%) from 89.796%
6673214172

push

github

mtf90
cleanup release configuration

15399 of 17270 relevant lines covered (89.17%)

1.67 hits per line

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

85.71
/adapters/brics/src/main/java/net/automatalib/brics/AbstractBricsAutomaton.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of AutomataLib, http://www.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.brics;
17

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

23
import dk.brics.automaton.Automaton;
24
import dk.brics.automaton.State;
25
import dk.brics.automaton.Transition;
26
import net.automatalib.automaton.fsa.FiniteStateAcceptor;
27
import net.automatalib.automaton.graph.AbstractAutomatonGraphView;
28
import net.automatalib.graph.UniversalGraph;
29
import net.automatalib.graph.concept.GraphViewable;
30
import net.automatalib.visualization.VisualizationHelper;
31

32
/**
33
 * Base class for Brics automata adapters.
34
 */
35
public abstract class AbstractBricsAutomaton implements FiniteStateAcceptor<State, Character>, GraphViewable {
36

37
    protected final Automaton automaton;
38

39
    /**
40
     * Constructor.
41
     *
42
     * @param automaton
43
     *         the Brics automaton to wrap.
44
     * @param totalize
45
     *         flag, indicating whether the automaton should have a total transition function.
46
     *
47
     * @see Automaton#totalize()
48
     */
49
    public AbstractBricsAutomaton(Automaton automaton, boolean totalize) {
2✔
50
        this.automaton = automaton;
2✔
51

52
        if (totalize) {
2✔
53
            State s = new State();
2✔
54
            s.addTransition(new Transition(Character.MIN_VALUE, Character.MAX_VALUE, s));
2✔
55
            for (State p : automaton.getStates()) {
2✔
56
                int maxi = Character.MIN_VALUE;
2✔
57
                for (Transition t : p.getSortedTransitions(false)) {
2✔
58
                    if (t.getMin() > maxi) {
2✔
59
                        p.addTransition(new Transition((char) maxi, (char) (t.getMin() - 1), s));
2✔
60
                    }
61
                    if (t.getMin() + 1 > maxi) {
2✔
62
                        maxi = t.getMax() + 1;
2✔
63
                    }
64
                }
2✔
65
                if (maxi <= Character.MAX_VALUE) {
2✔
66
                    p.addTransition(new Transition((char) maxi, Character.MAX_VALUE, s));
2✔
67
                }
68
            }
2✔
69
        }
70
    }
2✔
71

72
    /**
73
     * Retrieves the Brics automaton object.
74
     *
75
     * @return the brics automaton object
76
     */
77
    public Automaton getBricsAutomaton() {
78
        return automaton;
×
79
    }
80

81
    @Override
82
    public boolean isAccepting(State state) {
83
        return state.isAccept();
2✔
84
    }
85

86
    @Override
87
    public Collection<State> getTransitions(State state, Character input) {
88
        Collection<Transition> transitions = state.getSortedTransitions(false);
2✔
89

90
        Set<State> result = new HashSet<>();
2✔
91

92
        for (Transition t : transitions) {
2✔
93
            char min = t.getMin();
2✔
94
            if (input < min) {
2✔
95
                break;
2✔
96
            }
97
            char max = t.getMax();
2✔
98
            if (input > max) {
2✔
99
                continue;
2✔
100
            }
101
            result.add(t.getDest());
2✔
102
        }
2✔
103
        return result;
2✔
104
    }
105

106
    @Override
107
    public Set<State> getInitialStates() {
108
        return Collections.singleton(automaton.getInitialState());
×
109
    }
110

111
    @Override
112
    public Collection<State> getStates() {
113
        return automaton.getStates();
2✔
114
    }
115

116
    @Override
117
    public GraphView graphView() {
118
        return new GraphView();
2✔
119
    }
120

121
    public class GraphView extends AbstractAutomatonGraphView<State, AbstractBricsAutomaton, Transition>
122
            implements UniversalGraph<State, Transition, Boolean, BricsTransitionProperty> {
123

124
        public GraphView() {
2✔
125
            super(AbstractBricsAutomaton.this);
2✔
126
        }
2✔
127

128
        @Override
129
        public Collection<Transition> getOutgoingEdges(State node) {
130
            return node.getTransitions();
2✔
131
        }
132

133
        @Override
134
        public State getTarget(Transition edge) {
135
            return edge.getDest();
×
136
        }
137

138
        @Override
139
        public VisualizationHelper<State, Transition> getVisualizationHelper() {
140
            return new BricsVisualizationHelper(AbstractBricsAutomaton.this);
×
141
        }
142

143
        @Override
144
        public Boolean getNodeProperty(State node) {
145
            return node.isAccept();
×
146
        }
147

148
        @Override
149
        public BricsTransitionProperty getEdgeProperty(Transition edge) {
150
            return new BricsTransitionProperty(edge);
×
151
        }
152
    }
153

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