• 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

81.82
/api/src/main/java/net/automatalib/word/LetterWord.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.word;
17

18
import java.util.Collections;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Objects;
22
import java.util.Spliterator;
23
import java.util.function.Function;
24

25
import net.automatalib.common.util.collection.IteratorUtil;
26
import org.checkerframework.checker.nullness.qual.Nullable;
27

28
/**
29
 * A word consisting of a single letter only.
30
 *
31
 * @param <I>
32
 *         symbol class
33
 *
34
 * @see Collections#singletonList(Object)
35
 */
36
final class LetterWord<I> extends Word<I> {
37

38
    private final I letter;
39

40
    /**
41
     * Constructor.
42
     *
43
     * @param letter
44
     *         the letter to represent as a word
45
     */
46
    LetterWord(I letter) {
2✔
47
        this.letter = letter;
2✔
48
    }
2✔
49

50
    @Override
51
    public int length() {
52
        return 1;
2✔
53
    }
54

55
    @Override
56
    public Iterator<I> iterator() {
57
        return IteratorUtil.singleton(letter);
2✔
58
    }
59

60
    @Override
61
    public Spliterator<I> spliterator() {
62
        return Collections.singleton(letter).spliterator();
×
63
    }
64

65
    @Override
66
    public Word<I> subWordInternal(int fromIndex, int toIndex) {
67
        if (fromIndex > 0 || toIndex == 0) {
2✔
68
            return Word.epsilon();
2✔
69
        }
70
        return this;
2✔
71
    }
72

73
    @Override
74
    public void writeToArray(int offset, @Nullable Object[] array, int tgtOffset, int length) {
75
        if (offset == 0 && length > 0) {
2✔
76
            array[tgtOffset] = letter;
2✔
77
        }
78
    }
2✔
79

80
    @Override
81
    public I getSymbol(int index) {
82
        if (index != 0) {
2✔
83
            throw new IndexOutOfBoundsException();
×
84
        }
85
        return letter;
2✔
86
    }
87

88
    @Override
89
    public List<I> asList() {
90
        return Collections.singletonList(letter);
2✔
91
    }
92

93
    @Override
94
    public I lastSymbol() {
95
        return letter;
2✔
96
    }
97

98
    @Override
99
    public Word<I> append(I symbol) {
100
        @Nullable Object[] array = {letter, symbol};
2✔
101
        return new SharedWord<>(array);
2✔
102
    }
103

104
    @Override
105
    public Word<I> prepend(I symbol) {
106
        @Nullable Object[] array = {symbol, letter};
2✔
107
        return new SharedWord<>(array);
2✔
108
    }
109

110
    @Override
111
    public boolean isPrefixOf(Word<?> other) {
112
        return !other.isEmpty() && Objects.equals(letter, other.getSymbol(0));
2✔
113
    }
114

115
    @Override
116
    public Word<I> longestCommonPrefix(Word<?> other) {
117
        if (isPrefixOf(other)) {
2✔
118
            return this;
2✔
119
        }
120
        return Word.epsilon();
2✔
121
    }
122

123
    @Override
124
    public boolean isSuffixOf(Word<?> other) {
125
        return !other.isEmpty() && Objects.equals(letter, other.lastSymbol());
2✔
126
    }
127

128
    @Override
129
    public Word<I> longestCommonSuffix(Word<?> other) {
130
        if (isSuffixOf(other)) {
2✔
131
            return this;
2✔
132
        }
133
        return Word.epsilon();
2✔
134
    }
135

136
    @Override
137
    public Word<I> flatten() {
138
        return this;
×
139
    }
140

141
    @Override
142
    public Word<I> trimmed() {
143
        return this;
×
144
    }
145

146
    @Override
147
    public <T> Word<T> transform(Function<? super I, ? extends T> transformer) {
148
        T transformed = transformer.apply(letter);
×
149
        return new LetterWord<>(transformed);
×
150
    }
151
}
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