• 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

95.24
/util/src/main/java/net/automatalib/util/graph/traversal/BreadthFirstIterator.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.graph.traversal;
17

18
import java.util.ArrayDeque;
19
import java.util.Collection;
20
import java.util.Iterator;
21
import java.util.NoSuchElementException;
22
import java.util.Queue;
23

24
import net.automatalib.common.util.mapping.MutableMapping;
25
import net.automatalib.graph.IndefiniteGraph;
26
import net.automatalib.util.traversal.VisitedState;
27

28
final class BreadthFirstIterator<N, E> implements Iterator<N> {
29

30
    private final Queue<N> bfsQueue = new ArrayDeque<>();
2✔
31
    private final MutableMapping<N, VisitedState> visited;
32
    private final IndefiniteGraph<N, E> graph;
33

34
    BreadthFirstIterator(IndefiniteGraph<N, E> graph, Collection<? extends N> start) {
2✔
35
        this.graph = graph;
2✔
36
        this.visited = graph.createStaticNodeMapping();
2✔
37
        bfsQueue.addAll(start);
2✔
38
        for (N node : start) {
2✔
39
            visited.put(node, VisitedState.VISITED);
2✔
40
        }
2✔
41
    }
2✔
42

43
    @Override
44
    public boolean hasNext() {
45
        return !bfsQueue.isEmpty();
2✔
46
    }
47

48
    @Override
49
    public N next() {
50
        N result = bfsQueue.poll();
2✔
51
        if (result == null) {
2✔
52
            throw new NoSuchElementException();
×
53
        }
54

55
        final Iterator<E> edgeIter = graph.getOutgoingEdgesIterator(result);
2✔
56
        while (edgeIter.hasNext()) {
2✔
57
            E edge = edgeIter.next();
2✔
58
            N tgt = graph.getTarget(edge);
2✔
59
            if (visited.put(tgt, VisitedState.VISITED) != VisitedState.VISITED) {
2✔
60
                bfsQueue.add(tgt);
2✔
61
            }
62
        }
2✔
63

64
        return result;
2✔
65
    }
66

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