• 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

81.25
/drivers/mapper/src/main/java/de/learnlib/mapper/api/SULMapper.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.mapper.api;
17

18
import java.util.Optional;
19

20
import de.learnlib.api.Mapper;
21
import de.learnlib.api.Mapper.SynchronousMapper;
22
import de.learnlib.api.SUL;
23
import de.learnlib.api.exception.SULException;
24
import de.learnlib.mapper.SULMappers;
25
import org.checkerframework.checker.nullness.qual.Nullable;
26

27
/**
28
 * An extension of the {@link Mapper} interface specifically for {@link SUL}s.
29
 * <p>
30
 * The class {@link SULMappers} provides static utility functions for manipulating mappers.
31
 * <p>
32
 * SULMappers, like {@link SUL}s, may be {@link SUL#fork() forkable}. The requirements and semantics of {@link #fork()}
33
 * are basically the same as set forth for {@link SUL#fork()}. Stateless mappers (e.g., with empty {@link #pre()} and
34
 * {@link #post()} implementations), should always be forkable, and {@link #fork()} may just return {@code this}.
35
 * Stateful mappers may require more sophisticated fork logic, but in general it should be possible to fork them as
36
 * well.
37
 * <p>
38
 * Note: despite the above recommendation that mappers should almost always be forkable, the default implementations of
39
 * {@link #canFork()} and {@link #fork()} indicate non-forkability for backwards compatibility reasons.
40
 *
41
 * @param <AI>
42
 *         abstract input symbol type.
43
 * @param <AO>
44
 *         abstract output symbol type.
45
 * @param <CI>
46
 *         concrete input symbol type.
47
 * @param <CO>
48
 *         concrete output symbol type.
49
 */
50
public interface SULMapper<AI, AO, CI, CO> extends SynchronousMapper<AI, AO, CI, CO> {
51

52
    /**
53
     * Checks whether it is possible to {@link #fork() fork} this mapper.
54
     *
55
     * @return {@code true} if this mapper can be forked, {@code false} otherwise.
56
     */
57
    default boolean canFork() {
58
        return false;
2✔
59
    }
60

61
    /**
62
     * Forks this mapper, i.e., returns a mapper that behaves in exactly the same way as this mapper, but allows for
63
     * being used independently of this mapper.
64
     * <p>
65
     * If {@link #canFork()} returned {@code false}, this method must throw an {@link UnsupportedOperationException}.
66
     * Otherwise, it must return a non-{@code null} object representing the fork of this mapper.
67
     *
68
     * @return a fork of this mapper (for stateless mappers, generally {@code this} should be returned)
69
     *
70
     * @throws UnsupportedOperationException
71
     *         if this mapper is not forkable
72
     */
73
    default SULMapper<AI, AO, CI, CO> fork() {
74
        throw new UnsupportedOperationException();
2✔
75
    }
76

77
    /**
78
     * Maps a wrapped {@link SULException} to an abstract output symbol, or rethrows it if it is unmappable.
79
     *
80
     * @param exception
81
     *         the wrapped exception that was thrown
82
     *
83
     * @return the concrete output symbol the exception was mapped to, if applicable
84
     *
85
     * @throws SULException
86
     *         if the exception cannot be mapped, or if a new exception occurs while trying to map the given exception
87
     */
88
    default MappedException<? extends AO> mapWrappedException(SULException exception) {
89
        return mapUnwrappedException(exception);
1✔
90
    }
91

92
    /**
93
     * Maps an unwrapped {@link RuntimeException} to an abstract output symbol, or rethrows it if it is unmappable.
94
     *
95
     * @param exception
96
     *         the runtime exception that was thrown
97
     *
98
     * @return the concrete output symbol the exception was mapped to, if applicable
99
     *
100
     * @throws SULException
101
     *         if a new exception occurs while trying to map the given exception
102
     * @throws RuntimeException
103
     *         if the given exception cannot be mapped, or if a new exception occurs while trying to map the given
104
     *         exception
105
     */
106
    default MappedException<? extends AO> mapUnwrappedException(RuntimeException exception) {
107
        throw exception;
×
108
    }
109

110
    final class MappedException<AO> {
111

112
        private final AO thisStepOutput;
113
        private final Optional<AO> subsequentStepsOutput;
114

115
        private MappedException(AO output) {
116
            this(output, null);
2✔
117
        }
2✔
118

119
        private MappedException(AO thisStepOutput, @Nullable AO subsequentStepsOutput) {
2✔
120
            this.thisStepOutput = thisStepOutput;
2✔
121
            this.subsequentStepsOutput = Optional.ofNullable(subsequentStepsOutput);
2✔
122
        }
2✔
123

124
        public static <AO> MappedException<AO> ignoreAndContinue(AO output) {
125
            return new MappedException<>(output);
2✔
126
        }
127

128
        public static <AO> MappedException<AO> repeatOutput(AO output) {
129
            return repeatOutput(output, output);
×
130
        }
131

132
        public static <AO> MappedException<AO> repeatOutput(AO thisStepOutput, AO subsequentOutput) {
133
            return new MappedException<>(thisStepOutput, subsequentOutput);
2✔
134
        }
135

136
        public static <AO> MappedException<AO> pass(SULException exception) {
137
            throw exception;
×
138
        }
139

140
        public AO getThisStepOutput() {
141
            return thisStepOutput;
2✔
142
        }
143

144
        public Optional<AO> getSubsequentStepsOutput() {
145
            return subsequentStepsOutput;
2✔
146
        }
147
    }
148
}
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