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

LearnLib / automatalib / 10248696670

05 Aug 2024 12:21PM UTC coverage: 90.741% (+0.7%) from 90.072%
10248696670

push

github

web-flow
Serialization Overhaul (#81)

* overhaul serizalition code

* unify access to Input(De)Serializers behind facades to leverage the default methods for various input/output channels
* drop implicit buffering/decompressing as this should be decided where the stream are constructed (user-land)
* remove/cleanup the (now) unused code

* taf cleanups

* fix wording

343 of 358 new or added lines in 33 files covered. (95.81%)

7 existing lines in 2 files now uncovered.

15994 of 17626 relevant lines covered (90.74%)

1.68 hits per line

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

90.63
/core/src/main/java/net/automatalib/automaton/transducer/impl/CompactMealy.java
1
/* Copyright (C) 2013-2024 TU Dortmund University
2
 * This file is part of AutomataLib, http://www.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.automaton.transducer.impl;
17

18
import java.util.Arrays;
19

20
import net.automatalib.alphabet.Alphabet;
21
import net.automatalib.automaton.AutomatonCreator;
22
import net.automatalib.automaton.base.AbstractCompact;
23
import net.automatalib.automaton.base.AbstractCompactDeterministic;
24
import net.automatalib.automaton.impl.CompactTransition;
25
import net.automatalib.automaton.transducer.MutableMealyMachine;
26
import net.automatalib.automaton.transducer.StateLocalInputMealyMachine;
27
import org.checkerframework.checker.nullness.qual.Nullable;
28

29
public class CompactMealy<I, O> extends AbstractCompactDeterministic<I, CompactTransition<O>, Void, O> implements
30
                                                                                                       MutableMealyMachine<Integer, I, CompactTransition<O>, O>,
31
                                                                                                       StateLocalInputMealyMachine<Integer, I, CompactTransition<O>, O> {
32

33
    private int[] transitions;
34
    private @Nullable Object[] outputs;
35

36
    public CompactMealy(Alphabet<I> alphabet, int stateCapacity, float resizeFactor) {
37
        super(alphabet, stateCapacity, resizeFactor);
2✔
38

39
        final int size = stateCapacity * numInputs();
2✔
40

41
        this.transitions = new int[size];
2✔
42
        this.outputs = new Object[size];
2✔
43

44
        Arrays.fill(transitions, AbstractCompact.INVALID_STATE);
2✔
45
    }
2✔
46

47
    public CompactMealy(Alphabet<I> alphabet, int stateCapacity) {
48
        this(alphabet, stateCapacity, DEFAULT_RESIZE_FACTOR);
2✔
49
    }
2✔
50

51
    public CompactMealy(Alphabet<I> alphabet) {
52
        this(alphabet, DEFAULT_INIT_CAPACITY, DEFAULT_RESIZE_FACTOR);
2✔
53
    }
2✔
54

55
    public CompactMealy(CompactMealy<I, O> other) {
56
        this(other.getInputAlphabet(), other);
1✔
57
    }
1✔
58

59
    protected CompactMealy(Alphabet<I> alphabet, CompactMealy<?, O> other) {
60
        super(alphabet, other);
1✔
61
        this.transitions = other.transitions.clone();
1✔
62
        this.outputs = other.outputs.clone();
1✔
63
    }
1✔
64

65
    public <I2> CompactMealy<I2, O> translate(Alphabet<I2> newAlphabet) {
66
        if (newAlphabet.size() != numInputs()) {
1✔
NEW
67
            throw new IllegalArgumentException(
×
NEW
68
                    "Alphabet sizes must match, but they do not (old/new): " + numInputs() + " vs. " +
×
NEW
69
                    newAlphabet.size());
×
70
        }
71
        return new CompactMealy<>(newAlphabet, this);
1✔
72
    }
73

74
    @Override
75
    protected void updateTransitionStorage(Payload payload) {
76
        this.transitions = updateTransitionStorage(this.transitions, AbstractCompact.INVALID_STATE, payload);
2✔
77
        this.outputs = updateTransitionStorage(this.outputs, null, payload);
2✔
78
    }
2✔
79

80
    @Override
81
    public O getTransitionOutput(CompactTransition<O> transition) {
82
        return transition.getProperty();
2✔
83
    }
84

85
    @Override
86
    public O getTransitionProperty(CompactTransition<O> transition) {
87
        return transition.getProperty();
2✔
88
    }
89

90
    @Override
91
    public void setTransitionProperty(CompactTransition<O> transition, O property) {
92
        transition.setProperty(property);
2✔
93

94
        if (transition.isAutomatonTransition()) {
2✔
95
            outputs[transition.getMemoryIdx()] = property;
×
96
        }
97
    }
2✔
98

99
    @Override
100
    public void setTransitionOutput(CompactTransition<O> transition, O output) {
101
        setTransitionProperty(transition, output);
×
102
    }
×
103

104
    @Override
105
    public void removeAllTransitions(Integer state) {
106
        final int lower = state * numInputs();
2✔
107
        final int upper = lower + numInputs();
2✔
108
        Arrays.fill(transitions, lower, upper, AbstractCompact.INVALID_STATE);
2✔
109
        Arrays.fill(outputs, lower, upper, null);
2✔
110
    }
2✔
111

112
    @Override
113
    public int getIntSuccessor(CompactTransition<O> transition) {
114
        return transition.getSuccId();
2✔
115
    }
116

117
    @Override
118
    public CompactTransition<O> createTransition(int succId, O property) {
119
        return new CompactTransition<>(succId, property);
2✔
120
    }
121

122
    @Override
123
    public void setStateProperty(int state, Void property) {}
2✔
124

125
    @Override
126
    public Void getStateProperty(int stateId) {
127
        return null;
2✔
128
    }
129

130
    @Override
131
    public void setTransition(int state, int input, @Nullable CompactTransition<O> transition) {
132
        if (transition == null) {
2✔
133
            setTransition(state, input, AbstractCompact.INVALID_STATE, null);
2✔
134
        } else {
135
            setTransition(state, input, transition.getSuccId(), transition.getProperty());
2✔
136
            transition.setMemoryIdx(toMemoryIndex(state, input));
2✔
137
        }
138
    }
2✔
139

140
    @Override
141
    public void setTransition(int state, int input, int successor, @Nullable O property) {
142
        final int idx = toMemoryIndex(state, input);
2✔
143
        transitions[idx] = successor;
2✔
144
        outputs[idx] = property;
2✔
145
    }
2✔
146

147
    @Override
148
    public void clear() {
149
        int endIdx = size() * numInputs();
2✔
150
        Arrays.fill(transitions, 0, endIdx, AbstractCompact.INVALID_STATE);
2✔
151
        Arrays.fill(outputs, 0, endIdx, null);
2✔
152

153
        super.clear();
2✔
154
    }
2✔
155

156
    @Override
157
    public @Nullable CompactTransition<O> getTransition(int state, int input) {
158
        final int idx = toMemoryIndex(state, input);
2✔
159
        final int succ = transitions[idx];
2✔
160

161
        if (succ == AbstractCompact.INVALID_STATE) {
2✔
162
            return null;
2✔
163
        }
164

165
        @SuppressWarnings("unchecked")
166
        final O output = (O) outputs[idx];
2✔
167

168
        return new CompactTransition<>(idx, succ, output);
2✔
169
    }
170

171
    public static final class Creator<I, O> implements AutomatonCreator<CompactMealy<I, O>, I> {
2✔
172

173
        @Override
174
        public CompactMealy<I, O> createAutomaton(Alphabet<I> alphabet, int sizeHint) {
175
            return new CompactMealy<>(alphabet, sizeHint);
2✔
176
        }
177

178
        @Override
179
        public CompactMealy<I, O> createAutomaton(Alphabet<I> alphabet) {
180
            return new CompactMealy<>(alphabet);
1✔
181
        }
182
    }
183

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

© 2026 Coveralls, Inc