Skip to content

Commit 5b86f63

Browse files
committed
fix issues flagged by code-analysis
1 parent c47d0e9 commit 5b86f63

File tree

45 files changed

+1464
-923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1464
-923
lines changed

algorithms/active/lstar/src/main/java/de/learnlib/algorithm/lstar/mmlt/ExtensibleLStarMMLT.java

Lines changed: 263 additions & 181 deletions
Large diffs are not rendered by default.

algorithms/active/lstar/src/main/java/de/learnlib/algorithm/lstar/mmlt/LocationTimerInfo.java

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
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+
*/
116
package de.learnlib.algorithm.lstar.mmlt;
217

3-
import net.automatalib.symbol.time.TimedInput;
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+
425
import net.automatalib.automaton.mmlt.TimerInfo;
26+
import net.automatalib.symbol.time.TimedInput;
527
import net.automatalib.word.Word;
6-
import org.checkerframework.checker.nullness.qual.NonNull;
728
import org.checkerframework.checker.nullness.qual.Nullable;
829
import org.slf4j.Logger;
930
import org.slf4j.LoggerFactory;
1031

11-
import java.io.Serializable;
12-
import java.util.*;
13-
1432
/**
1533
* Stores information about local timers of a location.
1634
*
17-
* @param <I> Input type for non-delaying inputs
18-
* @param <O> Output symbol type
35+
* @param <I>
36+
* input symbol type (of non-delaying inputs)
37+
* @param <O>
38+
* output symbol type
1939
*/
20-
public class LocationTimerInfo<I, O> implements Serializable {
40+
public class LocationTimerInfo<I, O> {
2141

22-
private static final Logger logger = LoggerFactory.getLogger(LocationTimerInfo.class);
42+
private static final Logger LOGGER = LoggerFactory.getLogger(LocationTimerInfo.class);
2343

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

@@ -43,6 +63,9 @@ public Word<TimedInput<I>> getPrefix() {
4363
/**
4464
* Adds a local timer to this location.
4565
*
66+
* @param timer
67+
* the timer to add
68+
*
4669
*/
4770
public void addTimer(TimerInfo<?, O> timer) {
4871
this.timers.put(timer.name(), timer);
@@ -51,42 +74,52 @@ public void addTimer(TimerInfo<?, O> timer) {
5174
}
5275

5376
public void removeTimer(String timerName) {
54-
if (!this.timers.containsKey(timerName)) {
55-
logger.warn("Attempted to remove an unknown timer.");
56-
return;
77+
final TimerInfo<?, O> removedTimer = this.timers.remove(timerName);
78+
if (removedTimer == null) {
79+
LOGGER.warn("Attempted to remove an unknown timer.");
80+
} else {
81+
this.sortedTimers.remove(removedTimer);
5782
}
58-
TimerInfo<?, O> removedTimer = this.timers.remove(timerName);
59-
this.sortedTimers.remove(removedTimer);
6083
}
6184

62-
@Nullable
63-
public TimerInfo<?, O> getTimerInfo(long initial) {
64-
Optional<TimerInfo<?, O>> timer = this.sortedTimers.stream().filter(t -> t.initial() == initial).findAny();
65-
return timer.orElse(null);
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) {
95+
if (t.initial() == initial) {
96+
return t;
97+
}
98+
}
99+
return null;
66100
}
67101

68-
69102
/**
70-
* Returns the timer with the highest initial value
103+
* Returns the timer with the highest initial value.
71104
*
72-
* @return Timer with maximum timeout. Null, if no timers defined.
105+
* @return the timer with maximum timeout, {@code null} if no timers defined
73106
*/
74-
@Nullable
75-
public TimerInfo<?, O> getLastTimer() {
107+
public @Nullable TimerInfo<?, O> getLastTimer() {
76108
if (this.timers.isEmpty()) {
77109
return null;
78110
}
79111
return sortedTimers.get(sortedTimers.size() - 1);
80112
}
81113

82114
/**
83-
* Sets the given timer to one-shot, ensuring that there is only one one-shot timer at a time.
84-
* This is preferred over setting the timer property.
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.
85117
*
86-
* @param name Name of the new one-shot timer
118+
* @param name
119+
* name of the new one-shot timer
87120
*/
88121
public void setOneShotTimer(String name) {
89-
var oneShotTimer = this.timers.get(name);
122+
TimerInfo<?, O> oneShotTimer = this.timers.get(name);
90123
if (oneShotTimer == null) {
91124
throw new IllegalArgumentException("Unknown one-shot timer name.");
92125
}
@@ -95,27 +128,25 @@ public void setOneShotTimer(String name) {
95128
}
96129

97130
// update references
98-
var newTimer = oneShotTimer.asOneShot();
131+
TimerInfo<?, O> newTimer = oneShotTimer.asOneShot();
99132
this.timers.put(name, newTimer);
100133
this.sortedTimers.set(sortedTimers.size() - 1, newTimer);
101134
}
102135

103136
/**
104137
* Returns a list of all timers defined in this location, sorted by their initial value.
105138
*
106-
* @return List of local timers. Empty, if none.
139+
* @return list of local timers, may be empty
107140
*/
108141
public List<TimerInfo<?, O>> getSortedTimers() {
109142
return Collections.unmodifiableList(sortedTimers);
110143
}
111144

112145
/**
113-
* Returns an unmodifiable view of the timers defined for this location.
114-
* Format: name -> info
146+
* Returns an unmodifiable view of the timers defined for this location. Format: name -> info
115147
*
116-
* @return Map of local timers. Empty, if none defined.
148+
* @return map of local timers, may be empty
117149
*/
118-
@NonNull
119150
public Map<String, TimerInfo<?, O>> getLocalTimers() {
120151
return Collections.unmodifiableMap(this.timers);
121152
}
Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
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+
*/
116
package de.learnlib.algorithm.lstar.mmlt;
217

3-
import de.learnlib.time.MMLTModelParams;
18+
import java.util.HashMap;
19+
import java.util.HashSet;
20+
import java.util.Map;
21+
import java.util.Set;
22+
423
import de.learnlib.datastructure.observationtable.Row;
24+
import de.learnlib.time.MMLTModelParams;
525
import net.automatalib.alphabet.Alphabet;
626
import net.automatalib.symbol.time.TimedInput;
727
import net.automatalib.symbol.time.TimedOutput;
828
import net.automatalib.word.Word;
929
import org.checkerframework.checker.nullness.qual.Nullable;
1030

11-
import java.util.HashMap;
12-
import java.util.HashSet;
13-
import java.util.Map;
14-
import java.util.Set;
15-
1631
/**
17-
* Stores various data used for describing the MMLT hypothesis.
18-
* This includes the OT, a list of local resets, and a list of outputs.
32+
* Stores various data used for describing the MMLT hypothesis. This includes the observation table, a list of local
33+
* resets, and a list of outputs.
1934
*
20-
* @param <I> Input type for non-delaying inputs
21-
* @param <O> Output symbol type
35+
* @param <I>
36+
* input symbol type (of non-delaying inputs)
37+
* @param <O>
38+
* output symbol type
2239
*/
2340
class MMLTHypDataContainer<I, O> {
41+
2442
private final Alphabet<TimedInput<I>> alphabet;
2543

2644
private final MMLTObservationTable<I, O> table;
@@ -29,7 +47,9 @@ class MMLTHypDataContainer<I, O> {
2947

3048
private final MMLTModelParams<O> modelParams;
3149

32-
public MMLTHypDataContainer(Alphabet<TimedInput<I>> alphabet, MMLTModelParams<O> modelParams, MMLTObservationTable<I, O> table) {
50+
MMLTHypDataContainer(Alphabet<TimedInput<I>> alphabet,
51+
MMLTModelParams<O> modelParams,
52+
MMLTObservationTable<I, O> table) {
3353
this.alphabet = alphabet;
3454
this.modelParams = modelParams;
3555
this.table = table;
@@ -38,35 +58,32 @@ public MMLTHypDataContainer(Alphabet<TimedInput<I>> alphabet, MMLTModelParams<O>
3858
this.transitionResetSet = new HashSet<>();
3959
}
4060

41-
@Nullable
42-
protected TimedOutput<O> getTransitionOutput(Row<TimedInput<I>> stateRow, int inputIdx) {
61+
@Nullable TimedOutput<O> getTransitionOutput(Row<TimedInput<I>> stateRow, int inputIdx) {
4362
Row<TimedInput<I>> transRow = stateRow.getSuccessor(inputIdx);
4463
if (transRow == null) {
4564
return null;
4665
}
4766

48-
return this.transitionOutputMap.getOrDefault(transRow.getLabel(), null);
67+
return this.transitionOutputMap.get(transRow.getLabel());
4968
}
5069

51-
52-
public MMLTModelParams<O> getModelParams() {
70+
MMLTModelParams<O> getModelParams() {
5371
return modelParams;
5472
}
5573

56-
public Alphabet<TimedInput<I>> getAlphabet() {
74+
Alphabet<TimedInput<I>> getAlphabet() {
5775
return alphabet;
5876
}
5977

60-
61-
public MMLTObservationTable<I, O> getTable() {
78+
MMLTObservationTable<I, O> getTable() {
6279
return table;
6380
}
6481

65-
public Map<Word<TimedInput<I>>, TimedOutput<O>> getTransitionOutputMap() {
82+
Map<Word<TimedInput<I>>, TimedOutput<O>> getTransitionOutputMap() {
6683
return transitionOutputMap;
6784
}
6885

69-
public Set<Word<TimedInput<I>>> getTransitionResetSet() {
86+
Set<Word<TimedInput<I>>> getTransitionResetSet() {
7087
return transitionResetSet;
7188
}
7289
}

algorithms/active/lstar/src/main/java/de/learnlib/algorithm/lstar/mmlt/MMLTHypothesis.java

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
*/
116
package de.learnlib.algorithm.lstar.mmlt;
217

318
import java.util.Map;
@@ -6,17 +21,16 @@
621
import net.automatalib.automaton.mmlt.State;
722
import net.automatalib.automaton.mmlt.SymbolCombiner;
823
import net.automatalib.automaton.mmlt.impl.CompactMMLT;
9-
import net.automatalib.symbol.time.TimeStepSequence;
1024
import net.automatalib.symbol.time.TimedInput;
1125
import net.automatalib.word.Word;
1226

1327
/**
1428
* An MMLT hypothesis that includes a prefix mapping. This mapping assigns a short prefix to each location.
1529
*
1630
* @param <I>
17-
* Input type for non-delaying inputs
31+
* input symbol type (of non-delaying inputs)
1832
* @param <O>
19-
* Output symbol type
33+
* output symbol type
2034
*/
2135
public class MMLTHypothesis<I, O> extends CompactMMLT<I, O> {
2236

@@ -42,16 +56,29 @@ public class MMLTHypothesis<I, O> extends CompactMMLT<I, O> {
4256
* @return Assigned prefix
4357
*/
4458
public Word<TimedInput<I>> getPrefix(State<Integer, O> configuration) {
45-
var locPrefix = getLocationPrefix(configuration);
59+
Word<TimedInput<I>> locPrefix = getLocationPrefix(configuration);
4660
if (configuration.isEntryConfig()) {
4761
return locPrefix; // entry distance = 0
4862
} else {
49-
return locPrefix.append(new TimeStepSequence<>(configuration.getEntryDistance()));
63+
return locPrefix.append(TimedInput.step(configuration.getEntryDistance()));
5064
}
5165
}
5266

67+
/**
68+
* Returns a prefix for the given location. This prefix is deterministic in the learner.
69+
*
70+
* @param location
71+
* Location
72+
*
73+
* @return Location prefix
74+
*/
75+
public Word<TimedInput<I>> getPrefix(Integer location) {
76+
return prefixMap.get(location);
77+
}
78+
5379
public Word<TimedInput<I>> getPrefix(Word<TimedInput<I>> prefix) {
54-
var resultingConfig = getSemantics().getState(prefix);
80+
State<Integer, O> resultingConfig = getSemantics().getState(prefix);
81+
assert resultingConfig != null;
5582
return getPrefix(resultingConfig);
5683
}
5784

@@ -64,20 +91,8 @@ public Word<TimedInput<I>> getPrefix(Word<TimedInput<I>> prefix) {
6491
* @return Assigned prefix
6592
*/
6693
public Word<TimedInput<I>> getLocationPrefix(State<Integer, O> configuration) {
67-
var locPrefix = this.prefixMap.get(configuration.getLocation());
68-
if (locPrefix == null) {throw new AssertionError();}
94+
Word<TimedInput<I>> locPrefix = this.prefixMap.get(configuration.getLocation());
95+
assert locPrefix != null;
6996
return locPrefix;
7097
}
71-
72-
/**
73-
* Returns a prefix for the given location. This prefix is deterministic in the RS learner.
74-
*
75-
* @param location
76-
* Location
77-
*
78-
* @return Location prefix
79-
*/
80-
public Word<TimedInput<I>> getPrefix(Integer location) {
81-
return prefixMap.get(location);
82-
}
8398
}

0 commit comments

Comments
 (0)