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

LearnLib / learnlib / 6433387082

06 Oct 2023 03:10PM UTC coverage: 92.296% (-0.007%) from 92.303%
6433387082

push

github

mtf90
update Falk's developer id

11573 of 12539 relevant lines covered (92.3%)

1.67 hits per line

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

89.47
/commons/util/src/main/java/de/learnlib/util/moore/SymbolOracleWrapper.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.util.moore;
17

18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.List;
21

22
import de.learnlib.api.oracle.MembershipOracle;
23
import de.learnlib.api.query.Query;
24
import net.automatalib.words.Word;
25

26
/**
27
 * Word-to-Symbol-Oracle adapter.
28
 * <p>
29
 * Wraps an oracle which uses {@link Word}s as its output to an oracle which only yields the last symbol of each
30
 * output.
31
 *
32
 * @param <I>
33
 *         input symbol type
34
 * @param <O>
35
 *         output symbol type
36
 */
37
final class SymbolOracleWrapper<I, O> implements MembershipOracle<I, O> {
38

39
    private final MembershipOracle<I, Word<O>> wordOracle;
40

41
    /**
42
     * Constructor.
43
     *
44
     * @param wordOracle
45
     *         the {@link MembershipOracle} returning output words.
46
     */
47
    SymbolOracleWrapper(MembershipOracle<I, Word<O>> wordOracle) {
1✔
48
        this.wordOracle = wordOracle;
1✔
49
    }
1✔
50

51
    @Override
52
    public void processQueries(Collection<? extends Query<I, O>> queries) {
53
        List<LastSymbolQuery<I, O>> lsQueries = new ArrayList<>(queries.size());
1✔
54
        for (Query<I, O> qry : queries) {
1✔
55
            lsQueries.add(new LastSymbolQuery<>(qry));
1✔
56
        }
1✔
57

58
        wordOracle.processQueries(lsQueries);
1✔
59
    }
1✔
60

61
    private static final class LastSymbolQuery<I, O> extends Query<I, Word<O>> {
62

63
        private final Query<I, O> originalQuery;
64

65
        LastSymbolQuery(Query<I, O> originalQuery) {
1✔
66
            this.originalQuery = originalQuery;
1✔
67
        }
1✔
68

69
        @Override
70
        public void answer(Word<O> output) {
71
            if (output.isEmpty()) {
1✔
72
                throw new IllegalArgumentException("Query answer must not be empty");
×
73
            }
74
            originalQuery.answer(output.lastSymbol());
1✔
75
        }
1✔
76

77
        @Override
78
        public Word<I> getPrefix() {
79
            return originalQuery.getPrefix();
1✔
80
        }
81

82
        @Override
83
        public Word<I> getSuffix() {
84
            return originalQuery.getSuffix();
1✔
85
        }
86

87
        @Override
88
        public String toString() {
89
            return originalQuery.toString();
×
90
        }
91
    }
92
}
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