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

LearnLib / automatalib / 13815628111

12 Mar 2025 03:46PM CUT coverage: 92.058% (-0.001%) from 92.059%
13815628111

push

github

mtf90
cleanup redundant type variable definitions

1 of 1 new or added line in 1 file covered. (100.0%)

16599 of 18031 relevant lines covered (92.06%)

1.7 hits per line

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

0.0
/commons/util/src/main/java/net/automatalib/common/util/mapping/StringIndexMapping.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.common.util.mapping;
17

18
import org.checkerframework.checker.index.qual.NonNegative;
19

20
/**
21
 * Class for transforming integer index values into string values (using latin characters, therefore effectively
22
 * realizing a radix-26 representation of numbers).
23
 */
24
public final class StringIndexMapping {
25

26
    private static final int ALPHABET_SIZE = 26;
27

28
    private static final char BASE = 'a';
29

30
    private StringIndexMapping() {}
31

32
    public static long stringToIndex(String sidx) {
33
        long idx = 0;
×
34
        long value = 1;
×
35

36
        for (int i = 0; i < sidx.length(); i++) {
×
37
            char c = sidx.charAt(i);
×
38
            idx += value * getInteger(c);
×
39
            value *= ALPHABET_SIZE;
×
40
        }
41

42
        return idx;
×
43
    }
44

45
    public static String indexToString(@NonNegative long idx) {
46
        final StringBuilder sb = new StringBuilder();
×
47

48
        long idxIter = idx;
×
49
        do {
50
            sb.append(getChar((int) idxIter % ALPHABET_SIZE));
×
51
            idxIter /= ALPHABET_SIZE;
×
52
        } while (idxIter > 0);
×
53

54
        return sb.toString();
×
55
    }
56

57
    private static int getInteger(char c) {
58
        return Character.toLowerCase(c) - BASE;
×
59
    }
60

61
    private static char getChar(int idx) {
62
        return (char) (BASE + idx);
×
63
    }
64

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