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

LearnLib / automatalib / 13138848026

04 Feb 2025 02:53PM UTC coverage: 92.108% (+2.2%) from 89.877%
13138848026

push

github

mtf90
[maven-release-plugin] prepare release automatalib-0.12.0

16609 of 18032 relevant lines covered (92.11%)

1.7 hits per line

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

95.92
/util/src/main/java/net/automatalib/util/automaton/copy/AbstractLowLevelAutomatonCopier.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of AutomataLib <https://automatalib.net>.
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 net.automatalib.util.automaton.copy;
17

18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.Iterator;
21
import java.util.List;
22
import java.util.function.Function;
23
import java.util.function.Predicate;
24

25
import net.automatalib.automaton.MutableAutomaton;
26
import net.automatalib.common.util.mapping.Mapping;
27
import net.automatalib.common.util.mapping.MutableMapping;
28
import net.automatalib.ts.TransitionPredicate;
29
import net.automatalib.ts.TransitionSystem;
30
import org.checkerframework.checker.nullness.qual.Nullable;
31

32
public abstract class AbstractLowLevelAutomatonCopier<S1, I1, T1, S2, I2, T2, SP2, TP2, TS1 extends TransitionSystem<S1, ? super I1, T1>>
33
        implements LowLevelAutomatonCopier<S1, S2> {
34

35
    protected final TS1 in;
36
    protected final Collection<? extends I1> inputs;
37
    protected final MutableAutomaton<S2, I2, T2, ? super SP2, ? super TP2> out;
38
    protected final MutableMapping<S1, S2> stateMapping;
39
    protected final Function<? super I1, ? extends I2> inputsMapping;
40
    protected final Function<? super S1, ? extends SP2> spMapping;
41
    protected final Function<? super T1, ? extends TP2> tpMapping;
42
    protected final Predicate<? super S1> stateFilter;
43
    protected final TransitionPredicate<? super S1, ? super I1, ? super T1> transFilter;
44

45
    public AbstractLowLevelAutomatonCopier(TS1 in,
46
                                           Collection<? extends I1> inputs,
47
                                           MutableAutomaton<S2, I2, T2, ? super SP2, ? super TP2> out,
48
                                           Function<? super I1, ? extends I2> inputsMapping,
49
                                           Function<? super S1, ? extends SP2> spMapping,
50
                                           Function<? super T1, ? extends TP2> tpMapping,
51
                                           Predicate<? super S1> stateFilter,
52
                                           TransitionPredicate<? super S1, ? super I1, ? super T1> transFilter) {
2✔
53
        this.in = in;
2✔
54
        this.inputs = inputs;
2✔
55
        this.out = out;
2✔
56
        this.stateMapping = in.createStaticStateMapping();
2✔
57
        this.inputsMapping = inputsMapping;
2✔
58
        this.spMapping = spMapping;
2✔
59
        this.tpMapping = tpMapping;
2✔
60
        this.stateFilter = stateFilter;
2✔
61
        this.transFilter = transFilter;
2✔
62
    }
2✔
63

64
    protected S2 copyInitialState(S1 s1) {
65
        SP2 prop = spMapping.apply(s1);
2✔
66
        S2 s2 = out.addInitialState(prop);
2✔
67
        stateMapping.put(s1, s2);
2✔
68
        return s2;
2✔
69
    }
70

71
    protected void copyTransitions(S2 src2, I2 input2, Iterator<? extends T1> transitions1It) {
72
        List<T2> transitions2 = new ArrayList<>();
2✔
73

74
        while (transitions1It.hasNext()) {
2✔
75
            T1 trans1 = transitions1It.next();
2✔
76
            S1 succ1 = in.getSuccessor(trans1);
2✔
77
            S2 succ2 = stateMapping.get(succ1);
2✔
78

79
            // do not create transitions with undefined successor
80
            if (succ2 == null) {
2✔
81
                continue;
×
82
            }
83

84
            TP2 prop = tpMapping.apply(trans1);
2✔
85
            T2 trans2 = out.createTransition(succ2, prop);
2✔
86
            transitions2.add(trans2);
2✔
87
        }
2✔
88

89
        out.addTransitions(src2, input2, transitions2);
2✔
90
    }
2✔
91

92
    protected @Nullable S2 copyTransitionChecked(S2 src2, I2 input2, T1 trans1, S1 succ1) {
93
        TP2 prop = tpMapping.apply(trans1);
2✔
94

95
        S2 succ2 = stateMapping.get(succ1);
2✔
96
        S2 freshSucc = null;
2✔
97
        if (succ2 == null) {
2✔
98
            succ2 = copyState(succ1);
2✔
99
            freshSucc = succ2;
2✔
100
        }
101

102
        T2 trans2 = out.createTransition(succ2, prop);
2✔
103
        out.addTransition(src2, input2, trans2);
2✔
104
        return freshSucc;
2✔
105
    }
106

107
    protected S2 copyState(S1 s1) {
108
        SP2 prop = spMapping.apply(s1);
2✔
109
        S2 s2 = out.addState(prop);
2✔
110
        stateMapping.put(s1, s2);
2✔
111
        return s2;
2✔
112
    }
113

114
    @Override
115
    public abstract void doCopy();
116

117
    @Override
118
    public Mapping<S1, S2> getStateMapping() {
119
        return stateMapping;
2✔
120
    }
121

122
    protected final void updateInitials() {
123
        for (S1 init1 : in.getInitialStates()) {
2✔
124
            S2 init2 = stateMapping.get(init1);
2✔
125
            if (init2 == null) {
2✔
126
                continue;
×
127
            }
128
            out.setInitial(init2, true);
2✔
129
        }
2✔
130
    }
2✔
131
}
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