• 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

93.33
/api/src/main/java/net/automatalib/graph/helper/SimpleNodeIDs.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.helper;
17

18
import java.util.ArrayList;
19
import java.util.HashMap;
20
import java.util.List;
21
import java.util.Map;
22

23
import net.automatalib.common.util.HashUtil;
24
import net.automatalib.graph.SimpleGraph;
25
import net.automatalib.graph.concept.NodeIDs;
26

27
public class SimpleNodeIDs<N> implements NodeIDs<N> {
28

29
    private final Map<N, Integer> nodeIds;
30
    private final List<N> nodes;
31

32
    public SimpleNodeIDs(SimpleGraph<N> graph) {
1✔
33
        this.nodes = new ArrayList<>(graph.getNodes());
1✔
34
        int numNodes = this.nodes.size();
1✔
35
        this.nodeIds = new HashMap<>(HashUtil.capacity(numNodes));
1✔
36

37
        for (int i = 0; i < numNodes; i++) {
1✔
38
            N node = this.nodes.get(i);
1✔
39
            nodeIds.put(node, i);
1✔
40
        }
41
    }
1✔
42

43
    @Override
44
    public int getNodeId(N node) {
45
        final Integer id = nodeIds.get(node);
1✔
46

47
        if (id == null) {
1✔
48
            throw new IllegalArgumentException();
×
49
        }
50

51
        return id;
1✔
52
    }
53

54
    @Override
55
    public N getNode(int id) {
56
        if (id < 0 || id >= nodes.size()) {
1✔
57
            throw new IllegalArgumentException();
1✔
58
        }
59
        return nodes.get(id);
1✔
60
    }
61
}
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