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

LearnLib / automatalib / 13112058969

03 Feb 2025 11:04AM UTC coverage: 92.108%. Remained the same
13112058969

push

github

mtf90
cleanup generics of WordTests

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

60.0
/core/src/main/java/net/automatalib/graph/impl/SimpleMapGraph.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.graph.impl;
17

18
import java.util.Collection;
19
import java.util.Collections;
20
import java.util.HashMap;
21
import java.util.HashSet;
22
import java.util.Iterator;
23
import java.util.Map;
24
import java.util.Objects;
25
import java.util.Set;
26
import java.util.function.Supplier;
27

28
import net.automatalib.graph.MutableGraph;
29
import org.checkerframework.checker.nullness.qual.Nullable;
30

31
/**
32
 * A very simple graph realization, where nodes can be arbitrary Java objects. This graph does not support edge
33
 * properties.
34
 * <p>
35
 * This class provides maximum flexibility, but should only be used if performance is not a major concern.
36
 *
37
 * @param <N>
38
 *         node type
39
 */
40
public class SimpleMapGraph<@Nullable N> implements MutableGraph<N, N, N, Void> {
41

42
    private final Map<N, Collection<N>> structureMap;
43
    private final Supplier<? extends Collection<N>> adjCollSupplier;
44

45
    /**
46
     * Initializes a graph where the adjacency structure is stored using a {@link HashMap}, and adjacency information
47
     * for a single node is stored using {@link HashSet}s.
48
     */
49
    public SimpleMapGraph() {
50
        this(HashSet::new);
1✔
51
    }
1✔
52

53
    /**
54
     * Initializes a graph where the adjacency structure is stored using a {@link HashMap}, and adjacency information
55
     * for a single node is stored in data structures created via the provided supplier.
56
     *
57
     * @param adjCollSupplier
58
     *         the supplier for per-node adjacency collections
59
     */
60
    public SimpleMapGraph(Supplier<? extends Collection<N>> adjCollSupplier) {
61
        this(new HashMap<>(), adjCollSupplier);
1✔
62
    }
1✔
63

64
    /**
65
     * Initializes a graph using the given adjacency structure, and adjacency information for a single node is stored
66
     * using {@link HashSet}s.
67
     *
68
     * @param structureMap
69
     *         the map for the overall graph structure
70
     */
71
    public SimpleMapGraph(Map<N, Collection<N>> structureMap) {
72
        this(structureMap, HashSet::new);
×
73
    }
×
74

75
    /**
76
     * Initializes a graph using the given adjacency structure, and adjacency information for a single node is stored in
77
     * data structures created via the provided supplier.
78
     *
79
     * @param structureMap
80
     *         the map for the overall graph structure
81
     * @param adjCollSupplier
82
     *         the supplier for per-node adjacency collections
83
     */
84
    public SimpleMapGraph(Map<N, Collection<N>> structureMap, Supplier<? extends Collection<N>> adjCollSupplier) {
1✔
85
        this.structureMap = structureMap;
1✔
86
        this.adjCollSupplier = adjCollSupplier;
1✔
87
    }
1✔
88

89
    @Override
90
    public Collection<N> getAdjacentNodes(N node) {
91
        return getOutgoingEdges(node);
×
92
    }
93

94
    @Override
95
    public Iterator<N> getAdjacentNodesIterator(N node) {
96
        return getOutgoingEdgesIterator(node);
×
97
    }
98

99
    @Override
100
    public Collection<N> getOutgoingEdges(N node) {
101
        return Collections.unmodifiableCollection(structureMap.getOrDefault(node, Collections.emptySet()));
1✔
102
    }
103

104
    @Override
105
    public N getTarget(N edge) {
106
        return edge;
1✔
107
    }
108

109
    @Override
110
    public Set<N> getNodes() {
111
        return Collections.unmodifiableSet(structureMap.keySet());
1✔
112
    }
113

114
    @Override
115
    public N getNodeProperty(N node) {
116
        return node;
×
117
    }
118

119
    @Override
120
    public Void getEdgeProperty(N edge) {
121
        return null;
×
122
    }
123

124
    @Override
125
    public N addNode(@Nullable N property) {
126
        structureMap.putIfAbsent(property, adjCollSupplier.get());
1✔
127
        return property;
1✔
128
    }
129

130
    @SuppressWarnings("nullness") // connecting non-added nodes is a data-flow problem
131
    @Override
132
    public N connect(N source, N target, Void property) {
133
        structureMap.get(source).add(target);
1✔
134
        return target;
1✔
135
    }
136

137
    @Override
138
    @Deprecated
139
    public void setNodeProperty(N node, N property) {
140
        if (!Objects.equals(node, property)) {
×
141
            throw new IllegalArgumentException();
×
142
        }
143
    }
×
144

145
    @Override
146
    public void setEdgeProperty(N edge, Void property) {}
×
147

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

© 2026 Coveralls, Inc