• 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

95.45
/oracles/filters/cache/src/main/java/de/learnlib/filter/cache/mealy/MasterQuery.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.mealy;
17

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

21
import de.learnlib.api.query.AbstractQuery;
22
import de.learnlib.api.query.Query;
23
import net.automatalib.commons.util.mappings.Mapping;
24
import net.automatalib.words.Word;
25
import net.automatalib.words.WordBuilder;
26
import org.checkerframework.checker.nullness.qual.Nullable;
27

28
/**
29
 * A "master" query. This query corresponds to a maximal input word in the batch, and all queries that constitute
30
 * prefixes of this input word are slaves of this query. Upon answering the master query, all slave queries are also
31
 * answered.
32
 *
33
 * @param <I>
34
 *         input symbol type
35
 * @param <O>
36
 *         output symbol type
37
 */
38
final class MasterQuery<I, O> extends AbstractQuery<I, Word<O>> {
2✔
39

40
    private final @Nullable Mapping<? super O, ? extends O> errorSyms;
41
    private final @Nullable List<Query<I, Word<O>>> slaves;
42
    private Word<O> answer;
43

44
    MasterQuery(Word<I> word) {
45
        this(word, (Mapping<? super O, ? extends O>) null);
2✔
46
    }
2✔
47

48
    MasterQuery(Word<I> word, @Nullable Mapping<? super O, ? extends O> errorSyms) {
49
        super(word);
2✔
50
        this.errorSyms = errorSyms;
2✔
51
        this.slaves = new ArrayList<>();
2✔
52
    }
2✔
53

54
    MasterQuery(Word<I> word, Word<O> output) {
55
        super(word);
2✔
56
        this.answer = output;
2✔
57
        this.errorSyms = null;
2✔
58
        this.slaves = null;
2✔
59
    }
2✔
60

61
    public Word<O> getAnswer() {
62
        return answer;
2✔
63
    }
64

65
    public boolean isAnswered() {
66
        return answer != null;
2✔
67
    }
68

69
    @Override
70
    public void answer(Word<O> output) {
71
        assert slaves != null;
2✔
72
        this.answer = truncateOutput(output);
2✔
73
        for (Query<I, Word<O>> slave : slaves) {
2✔
74
            answerSlave(slave);
2✔
75
        }
2✔
76
    }
2✔
77

78
    private Word<O> truncateOutput(Word<O> output) {
79
        if (errorSyms == null) {
2✔
80
            return output;
2✔
81
        }
82

83
        int maxLen = output.length() - 1;
2✔
84
        int i = 0;
2✔
85
        O repSym = null;
2✔
86

87
        while (i < maxLen && repSym == null) {
2✔
88
            O sym = output.getSymbol(i++);
2✔
89
            repSym = errorSyms.get(sym);
2✔
90
        }
2✔
91

92
        if (repSym == null) {
2✔
93
            return output;
×
94
        }
95

96
        WordBuilder<O> wb = new WordBuilder<>(maxLen + 1);
2✔
97
        wb.append(output.prefix(i));
2✔
98
        wb.repeatAppend(1 + maxLen - i, repSym);
2✔
99

100
        return wb.toWord();
2✔
101
    }
102

103
    private void answerSlave(Query<I, Word<O>> slave) {
104
        int start = slave.getPrefix().length();
2✔
105
        int end = start + slave.getSuffix().length();
2✔
106
        slave.answer(answer.subWord(start, end));
2✔
107
    }
2✔
108

109
    /**
110
     * @see AbstractQuery#toStringWithAnswer(Object)
111
     */
112
    @Override
113
    public String toString() {
114
        return toStringWithAnswer(answer);
×
115
    }
116

117
    public void addSlave(Query<I, Word<O>> slave) {
118
        if (slaves == null) {
2✔
119
            answerSlave(slave);
2✔
120
        } else {
121
            slaves.add(slave);
2✔
122
        }
123
    }
2✔
124

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