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

LearnLib / learnlib / 6412002873

04 Oct 2023 10:05PM UTC coverage: 92.303% (+0.02%) from 92.282%
6412002873

push

github

mtf90
further tweak versions

* downgrade maven-javadoc-plugin version because it (for whatever reason) doesn't work on Java 11+
* update previously missed doc skin version

11573 of 12538 relevant lines covered (92.3%)

1.67 hits per line

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

93.33
/oracles/filters/cache/src/main/java/de/learnlib/filter/cache/sul/AbstractSULCache.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.cache.sul;
17

18
import de.learnlib.api.Resumable;
19
import de.learnlib.api.SUL;
20
import de.learnlib.api.oracle.EquivalenceOracle.MealyEquivalenceOracle;
21
import de.learnlib.filter.cache.LearningCache.MealyLearningCache;
22
import de.learnlib.filter.cache.mealy.MealyCacheConsistencyTest;
23
import de.learnlib.filter.cache.sul.AbstractSULCache.SULCacheState;
24
import net.automatalib.SupportsGrowingAlphabet;
25
import net.automatalib.incremental.mealy.IncrementalMealyBuilder;
26
import net.automatalib.ts.output.MealyTransitionSystem;
27
import net.automatalib.words.WordBuilder;
28
import org.checkerframework.checker.nullness.qual.Nullable;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

32
abstract class AbstractSULCache<I, O, C extends SULCacheState<I, O>>
33
        implements SUL<I, O>, MealyLearningCache<I, O>, SupportsGrowingAlphabet<I>, Resumable<C> {
34

35
    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSULCache.class);
2✔
36

37
    private final AbstractSULCacheImpl<?, I, ?, O, C> impl;
38

39
    <S, T> AbstractSULCache(AbstractSULCacheImpl<S, I, T, O, C> cacheImpl) {
2✔
40
        this.impl = cacheImpl;
2✔
41
    }
2✔
42

43
    @Override
44
    public void pre() {
45
        impl.pre();
2✔
46
    }
2✔
47

48
    @Override
49
    public void post() {
50
        impl.post();
2✔
51
    }
2✔
52

53
    @Override
54
    public O step(I in) {
55
        return impl.step(in);
2✔
56
    }
57

58
    @Override
59
    public boolean canFork() {
60
        return impl.canFork();
1✔
61
    }
62

63
    @Override
64
    public SUL<I, O> fork() {
65
        return impl.fork();
1✔
66
    }
67

68
    @Override
69
    public MealyEquivalenceOracle<I, O> createCacheConsistencyTest() {
70
        return impl.createCacheConsistencyTest();
2✔
71
    }
72

73
    @Override
74
    public void addAlphabetSymbol(I symbol) {
75
        impl.addAlphabetSymbol(symbol);
×
76
    }
×
77

78
    @Override
79
    public C suspend() {
80
        return impl.suspend();
2✔
81
    }
82

83
    @Override
84
    public void resume(C state) {
85
        this.impl.resume(state);
2✔
86
    }
2✔
87

88
    public int size() {
89
        return impl.incMealy.asGraph().size();
2✔
90
    }
91

92
    /**
93
     * Implementation class; we need this to bind the {@code T} and {@code S} type parameters of the transition system
94
     * returned by {@link IncrementalMealyBuilder#asTransitionSystem()}.
95
     *
96
     * @param <S>
97
     *         transition system state type
98
     * @param <I>
99
     *         input symbol type
100
     * @param <T>
101
     *         transition system transition type
102
     * @param <O>
103
     *         output symbol type
104
     * @param <C>
105
     *         cache type
106
     *
107
     * @author Malte Isberner
108
     */
109
    abstract static class AbstractSULCacheImpl<S, I, T, O, C extends SULCacheState<I, O>>
2✔
110
            implements SUL<I, O>, MealyLearningCache<I, O>, SupportsGrowingAlphabet<I>, Resumable<C> {
111

112
        protected IncrementalMealyBuilder<I, O> incMealy;
113
        protected MealyTransitionSystem<S, I, T, O> mealyTs;
114
        protected final SUL<I, O> delegate;
115

116
        private final WordBuilder<I> inputWord = new WordBuilder<>();
2✔
117
        private final WordBuilder<O> outputWord = new WordBuilder<>();
2✔
118

119
        private boolean delegatePreCalled;
120
        protected @Nullable S current;
121

122
        AbstractSULCacheImpl(IncrementalMealyBuilder<I, O> incMealy,
123
                             MealyTransitionSystem<S, I, T, O> mealyTs,
124
                             SUL<I, O> sul) {
2✔
125
            this.incMealy = incMealy;
2✔
126
            this.mealyTs = mealyTs;
2✔
127
            this.delegate = sul;
2✔
128
        }
2✔
129

130
        @Override
131
        public void pre() {
132
            this.current = mealyTs.getInitialState();
2✔
133
        }
2✔
134

135
        @Override
136
        public O step(I in) {
137
            O out = null;
2✔
138

139
            if (current != null) {
2✔
140
                T trans = mealyTs.getTransition(current, in);
2✔
141

142
                if (trans != null) {
2✔
143
                    out = mealyTs.getTransitionOutput(trans);
2✔
144
                    current = mealyTs.getSuccessor(trans);
2✔
145
                    assert current != null;
2✔
146
                } else {
147
                    requiredInitializedDelegate();
2✔
148
                    current = null;
2✔
149
                    for (I prevSym : inputWord) {
2✔
150
                        outputWord.append(delegate.step(prevSym));
2✔
151
                    }
2✔
152
                }
153
            }
154

155
            inputWord.append(in);
2✔
156

157
            if (current == null) {
2✔
158
                out = delegate.step(in);
2✔
159
                postNewStepHook();
2✔
160
                outputWord.add(out);
2✔
161
            }
162

163
            return out;
2✔
164
        }
165

166
        // TODO: The SUL interface might need a cleanup() method which, by contract,
167
        // is to be called regardless of whether preceding step()s threw unrecoverable
168
        // errors!
169
        @Override
170
        public void post() {
171
            updateCache(inputWord, outputWord);
2✔
172

173
            if (delegatePreCalled) {
2✔
174
                delegate.post();
2✔
175
                delegatePreCalled = false;
2✔
176
            }
177
            inputWord.clear();
2✔
178
            outputWord.clear();
2✔
179
            current = null;
2✔
180
        }
2✔
181

182
        @Override
183
        public MealyEquivalenceOracle<I, O> createCacheConsistencyTest() {
184
            return new MealyCacheConsistencyTest<>(incMealy);
2✔
185
        }
186

187
        @Override
188
        public void addAlphabetSymbol(I symbol) {
189
            incMealy.addAlphabetSymbol(symbol);
×
190
        }
×
191

192
        @Override
193
        @SuppressWarnings("unchecked")
194
        public void resume(C state) {
195
            final Class<?> thisClass = this.incMealy.getClass();
2✔
196
            final Class<?> stateClass = state.builder.getClass();
2✔
197

198
            if (!thisClass.equals(stateClass)) {
2✔
199
                LOGGER.warn(
×
200
                        "You currently plan to use a '{}', but the state contained a '{}'. This may yield unexpected behavior.",
201
                        thisClass,
202
                        stateClass);
203
            }
204

205
            this.incMealy = state.builder;
2✔
206
            this.mealyTs = (MealyTransitionSystem<S, I, T, O>) this.incMealy.asTransitionSystem();
2✔
207
        }
2✔
208

209
        protected void requiredInitializedDelegate() {
210
            if (!delegatePreCalled) {
2✔
211
                delegate.pre();
2✔
212
            }
213
            delegatePreCalled = true;
2✔
214
        }
2✔
215

216
        protected void postNewStepHook() {}
2✔
217

218
        protected void updateCache(WordBuilder<I> inputBuilder, WordBuilder<O> outputBuilder) {
219
            if (!outputBuilder.isEmpty()) {
2✔
220
                incMealy.insert(inputBuilder.toWord(), outputBuilder.toWord());
2✔
221
            }
222
        }
2✔
223
    }
224

225
    public static class SULCacheState<I, O> {
226

227
        final IncrementalMealyBuilder<I, O> builder;
228

229
        SULCacheState(IncrementalMealyBuilder<I, O> builder) {
2✔
230
            this.builder = builder;
2✔
231
        }
2✔
232
    }
233
}
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