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

LearnLib / learnlib / 20198569605

13 Dec 2025 10:10PM UTC coverage: 94.914% (+0.4%) from 94.471%
20198569605

Pull #153

github

web-flow
Merge 6a71fc929 into 879958926
Pull Request #153: Implementation for learning MMLTs, new model for collecting statistics

1823 of 1873 new or added lines in 77 files covered. (97.33%)

1 existing line in 1 file now uncovered.

14258 of 15022 relevant lines covered (94.91%)

1.73 hits per line

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

88.57
/algorithms/active/lstar/src/main/java/de/learnlib/algorithm/lstar/mmlt/LocationTimerInfo.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of LearnLib <https://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.algorithm.lstar.mmlt;
17

18
import java.util.ArrayList;
19
import java.util.Collections;
20
import java.util.Comparator;
21
import java.util.HashMap;
22
import java.util.List;
23
import java.util.Map;
24

25
import net.automatalib.automaton.mmlt.TimerInfo;
26
import net.automatalib.symbol.time.TimedInput;
27
import net.automatalib.word.Word;
28
import org.checkerframework.checker.nullness.qual.Nullable;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

32
/**
33
 * Stores information about local timers of a location.
34
 *
35
 * @param <I>
36
 *         input symbol type (of non-delaying inputs)
37
 * @param <O>
38
 *         output symbol type
39
 */
40
public class LocationTimerInfo<I, O> {
41

42
    private static final Logger LOGGER = LoggerFactory.getLogger(LocationTimerInfo.class);
2✔
43

44
    private final Map<String, TimerInfo<?, O>> timers; // name -> info
45

46
    // Keep a list of timers sorted by their initial value. This lets us avoid redundant sort operations.
47
    private final List<TimerInfo<?, O>> sortedTimers;
48

49
    private final Word<TimedInput<I>> prefix;
50

51
    public LocationTimerInfo(Word<TimedInput<I>> prefix) {
2✔
52
        this.prefix = prefix;
2✔
53
        this.timers = new HashMap<>();
2✔
54
        this.sortedTimers = new ArrayList<>();
2✔
55
    }
2✔
56

57
    public Word<TimedInput<I>> getPrefix() {
58
        return prefix;
2✔
59
    }
60

61
    // ====================
62

63
    /**
64
     * Adds a local timer to this location.
65
     *
66
     * @param timer
67
     *         the timer to add
68
     *
69
     */
70
    public void addTimer(TimerInfo<?, O> timer) {
71
        this.timers.put(timer.name(), timer);
2✔
72
        this.sortedTimers.add(timer);
2✔
73
        this.sortedTimers.sort(Comparator.comparingLong(TimerInfo::initial));
2✔
74
    }
2✔
75

76
    public void removeTimer(String timerName) {
77
        final TimerInfo<?, O> removedTimer = this.timers.remove(timerName);
2✔
78
        if (removedTimer == null) {
2✔
NEW
79
            LOGGER.warn("Attempted to remove an unknown timer.");
×
80
        } else {
81
            this.sortedTimers.remove(removedTimer);
2✔
82
        }
83
    }
2✔
84

85
    /**
86
     * Returns the timer with the given initial value.
87
     *
88
     * @param initial
89
     *         the queried initial value
90
     *
91
     * @return the timer with given timeout, {@code null} if no such timer exists
92
     */
93
    public @Nullable TimerInfo<?, O> getTimerInfo(long initial) {
94
        for (TimerInfo<?, O> t : this.sortedTimers) {
2✔
95
            if (t.initial() == initial) {
2✔
96
                return t;
2✔
97
            }
98
        }
2✔
NEW
99
        return null;
×
100
    }
101

102
    /**
103
     * Returns the timer with the highest initial value.
104
     *
105
     * @return the timer with maximum timeout, {@code null} if no timers defined
106
     */
107
    public @Nullable TimerInfo<?, O> getLastTimer() {
108
        if (this.timers.isEmpty()) {
2✔
109
            return null;
2✔
110
        }
111
        return sortedTimers.get(sortedTimers.size() - 1);
2✔
112
    }
113

114
    /**
115
     * Sets the given timer to one-shot, ensuring that there is only one one-shot timer at a time. This is preferred
116
     * over setting the timer property.
117
     *
118
     * @param name
119
     *         the name of the new one-shot timer
120
     */
121
    public void setOneShotTimer(String name) {
122
        TimerInfo<?, O> oneShotTimer = this.timers.get(name);
2✔
123
        if (oneShotTimer == null) {
2✔
NEW
124
            throw new IllegalArgumentException("Unknown one-shot timer name.");
×
125
        }
126
        if (!oneShotTimer.equals(sortedTimers.get(sortedTimers.size() - 1))) {
2✔
NEW
127
            throw new IllegalArgumentException("Only the timer with maximum timeout can be one-shot.");
×
128
        }
129

130
        // update references
131
        TimerInfo<?, O> newTimer = oneShotTimer.asOneShot();
2✔
132
        this.timers.put(name, newTimer);
2✔
133
        this.sortedTimers.set(sortedTimers.size() - 1, newTimer);
2✔
134
    }
2✔
135

136
    /**
137
     * Returns an unmodifiable list of all timers defined in this location, sorted by their initial value.
138
     *
139
     * @return list of local timers, may be empty
140
     */
141
    public List<TimerInfo<?, O>> getSortedTimers() {
142
        return Collections.unmodifiableList(sortedTimers);
2✔
143
    }
144

145
    /**
146
     * Returns an unmodifiable view of the timers defined for this location. Format: name -> info
147
     *
148
     * @return map of local timers, may be empty
149
     */
150
    public Map<String, TimerInfo<?, O>> getLocalTimers() {
151
        return Collections.unmodifiableMap(this.timers);
2✔
152
    }
153
}
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