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

LearnLib / automatalib / 13100258666

02 Feb 2025 03:46PM UTC coverage: 92.108% (+0.1%) from 92.01%
13100258666

push

github

mtf90
provide some default methods for {Mutable,]ProbabilisticMealy

including tests

4 of 4 new or added lines in 2 files covered. (100.0%)

18 existing lines in 7 files now uncovered.

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

26.67
/commons/smartcollections/src/main/java/net/automatalib/common/smartcollection/AWUtil.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.smartcollection;
17

18
import java.util.Arrays;
19

20
/**
21
 * Utility class for writing containers to arrays.
22
 * <p>
23
 * It is generally preferable to use the static methods this class offers than using {@link
24
 * ArrayWritable#writeToArray(int, Object[], int, int)} directly.
25
 */
26
public final class AWUtil {
27

28
    private AWUtil() {
29
        // prevent instantiation
30
    }
31

32
    /**
33
     * Writes the complete container data to an array. This method ensures that the array's capacity is not exceeded.
34
     *
35
     * @param aw
36
     *         the container.
37
     * @param array
38
     *         the array
39
     * @param <T>
40
     *         the array type
41
     * @param <U>
42
     *         the container type
43
     *
44
     * @return the number of elements copied
45
     */
46
    public static <T, U extends T> int safeWrite(ArrayWritable<U> aw, T[] array) {
47
        int num = aw.size();
×
48
        if (num <= 0) {
×
49
            return 0;
×
50
        }
51
        if (num > array.length) {
×
52
            num = array.length;
×
53
        }
54
        aw.writeToArray(0, array, 0, num);
×
55
        return num;
×
56
    }
57

58
    /**
59
     * Writes a given maximum amount of data items from a container to an array. This method ensures that the array's
60
     * capacity is not exceeded.
61
     *
62
     * @param num
63
     *         the number of elements to copy
64
     * @param aw
65
     *         the container.
66
     * @param array
67
     *         the array
68
     * @param <T>
69
     *         the array type
70
     * @param <U>
71
     *         the container type
72
     *
73
     * @return the number of elements copied
74
     */
75
    public static <T, U extends T> int safeWrite(int num, ArrayWritable<U> aw, T[] array) {
76

77
        final int elementsToCopy = Math.min(num, Math.min(aw.size(), array.length));
×
78

79
        if (elementsToCopy <= 0) {
×
80
            return 0;
×
81
        }
82

83
        aw.writeToArray(0, array, 0, elementsToCopy);
×
84
        return elementsToCopy;
×
85
    }
86

87
    public static <T, U extends T> int safeWrite(int num, ArrayWritable<U> aw, int ofs, T[] array, int tgtOfs) {
88
        final int awBound = Math.min(num + ofs, aw.size());
1✔
89
        final int arrayBound = Math.min(num + tgtOfs, array.length);
1✔
90

91
        final int elementsToCopy = Math.min(awBound, arrayBound);
1✔
92

93
        if (elementsToCopy <= 0) {
1✔
94
            return 0;
1✔
95
        }
96

97
        aw.writeToArray(ofs, array, tgtOfs, elementsToCopy);
1✔
98
        return elementsToCopy;
1✔
99
    }
100

101
    public static <T, U extends T> int safeWrite(ArrayWritable<U> aw, T[] array, int tgtOfs) {
102
        return safeWrite(aw.size(), aw, 0, array, tgtOfs);
1✔
103
    }
104

105
    public static Object[] toArray(ArrayWritable<?> aw) {
UNCOV
106
        int num = aw.size();
×
107
        Object[] arr = new Object[num];
×
108
        aw.writeToArray(0, arr, 0, num);
×
109
        return arr;
×
110
    }
111

112
    public static <T> T[] toArray(ArrayWritable<?> aw, T[] arr) {
UNCOV
113
        final int num = aw.size();
×
114
        final T[] targetArray;
115

UNCOV
116
        if (arr.length < num) {
×
117
            targetArray = Arrays.copyOf(arr, num);
×
118
        } else {
UNCOV
119
            targetArray = arr;
×
120
        }
121

UNCOV
122
        aw.writeToArray(0, targetArray, 0, num);
×
123
        return targetArray;
×
124
    }
125
}
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