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

LearnLib / learnlib / 6673301747

27 Oct 2023 11:46PM UTC coverage: 91.986% (-1.3%) from 93.327%
6673301747

push

github

mtf90
merge the release and sign-artifacts profiles

10984 of 11941 relevant lines covered (91.99%)

1.72 hits per line

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

85.19
/filters/reuse/src/main/java/de/learnlib/filter/reuse/tree/ReuseNode.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
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 de.learnlib.filter.reuse.tree;
17

18
import java.util.Arrays;
19
import java.util.Collection;
20
import java.util.Iterator;
21

22
import de.learnlib.filter.reuse.tree.BoundedDeque.AccessPolicy;
23
import de.learnlib.filter.reuse.tree.BoundedDeque.EvictPolicy;
24
import org.checkerframework.checker.nullness.qual.Nullable;
25

26
/**
27
 * A {@link ReuseNode} is a vertex in the {@link ReuseTree} that contains (a possible empty) set of outgoing {@link
28
 * ReuseEdge}s. Each {@link ReuseNode} may contain a system state holding relevant information (e.g. database
29
 * identifiers or an object) that belongs to the system state that 'represents' the system state after executing a
30
 * membership query.
31
 *
32
 * @param <S>
33
 *         system state class
34
 * @param <I>
35
 *         input symbol class
36
 * @param <O>
37
 *         output symbol class
38
 */
39
public class ReuseNode<S, I, O> {
40

41
    private final @Nullable ReuseEdge<S, I, O>[] edges;
42
    private final BoundedDeque<S> systemStates;
43
    private final int id;
44

45
    @SuppressWarnings("unchecked")
46
    public ReuseNode(int id,
47
                     int alphabetSize,
48
                     int maxSystemStates,
49
                     AccessPolicy accessPolicy,
50
                     EvictPolicy evictPolicy) {
2✔
51
        this.edges = new ReuseEdge[alphabetSize];
2✔
52
        this.id = id;
2✔
53
        this.systemStates = new BoundedDeque<>(maxSystemStates, accessPolicy, evictPolicy);
2✔
54
    }
2✔
55

56
    /**
57
     * The system state, may be {@code null}.
58
     */
59
    public S fetchSystemState(boolean remove) {
60
        if (remove) {
2✔
61
            return systemStates.retrieve();
2✔
62
        }
63
        return systemStates.peek();
×
64
    }
65

66
    public @Nullable S addSystemState(S state) {
67
        return systemStates.insert(state);
2✔
68
    }
69

70
    public Iterator<S> systemStatesIterator() {
71
        return systemStates.iterator();
×
72
    }
73

74
    public boolean hasSystemStates() {
75
        return !systemStates.isEmpty();
2✔
76
    }
77

78
    public void clearSystemStates() {
79
        systemStates.clear();
×
80
    }
×
81

82
    /**
83
     * Returns all outgoing {@link ReuseEdge}s from this {@link ReuseNode}. If there are none the returned {@link
84
     * java.util.Collection} will be empty (but never {@code null}).
85
     */
86
    public Collection<@Nullable ReuseEdge<S, I, O>> getEdges() {
87
        return Arrays.asList(edges);
2✔
88
    }
89

90
    /**
91
     * Adds an outgoing {@link ReuseEdge} to this {@link ReuseNode}.
92
     */
93
    public void addEdge(int index, ReuseEdge<S, I, O> edge) {
94
        this.edges[index] = edge;
2✔
95
    }
2✔
96

97
    public @Nullable ReuseNode<S, I, O> getTargetNodeForInput(int index) {
98
        ReuseEdge<S, I, O> edge = this.getEdgeWithInput(index);
2✔
99
        if (edge == null) {
2✔
100
            return null;
2✔
101
        }
102
        return edge.getTarget();
2✔
103
    }
104

105
    /**
106
     * May be {@code null}.
107
     */
108
    public @Nullable ReuseEdge<S, I, O> getEdgeWithInput(int index) {
109
        return this.edges[index];
2✔
110
    }
111

112
    public int getId() {
113
        return this.id;
2✔
114
    }
115

116
    public static final class NodeResult<S, I, O> {
117

118
        public final ReuseNode<S, I, O> reuseNode;
119
        public final S systemState;
120
        /**
121
         * The prefix length for a membership query that leads to the {@link ReuseNode} in the reuse tree.
122
         */
123
        public final int prefixLength;
124

125
        public NodeResult(ReuseNode<S, I, O> reuseNode, S systemState, int prefixLength) {
2✔
126
            this.reuseNode = reuseNode;
2✔
127
            this.systemState = systemState;
2✔
128
            this.prefixLength = prefixLength;
2✔
129
        }
2✔
130
    }
131

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