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

LearnLib / automatalib / 12651580329

07 Jan 2025 12:29PM UTC coverage: 91.569% (+0.03%) from 91.542%
12651580329

push

github

web-flow
Update dependencies (#85)

* bump basic dependency versions

* bump checkstyle + cleanups

* bump spotbugs + cleanups

* bump pmd + cleanups

* bump checkerframework + cleanups

* some more cleanups

* ExceptionUtil: support nulls

* improve comments

* cleanup naming + formatting

* formatting

* formatting

* do not fail on javadoc warnings

completness of documentation is now checked by checkstyle and we would have to disable failing anyways when moving on to JDK 17

192 of 217 new or added lines in 63 files covered. (88.48%)

4 existing lines in 4 files now uncovered.

16573 of 18099 relevant lines covered (91.57%)

1.69 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/function/FunctionsUtil.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.common.util.function;
17

18
import java.util.function.Function;
19
import java.util.function.IntFunction;
20
import java.util.function.Predicate;
21

22
import org.checkerframework.checker.nullness.qual.Nullable;
23

24
/**
25
 * This class provides utility methods for Java 8 {@link Function} objects (and for the corresponding primitive
26
 * specializations).
27
 */
28
public final class FunctionsUtil {
29

30
    private FunctionsUtil() {
31
        // prevent instantiation
32
    }
33

34
    /**
35
     * Returns a default function if the argument is {@code null}. The default function's {@code Function#apply(Object)
36
     * apply} method will always return {@code null}. If a non-{@code null} function is passed to this method, it is
37
     * returned as-is.
38
     *
39
     * @param func
40
     *         the function reference (may be {@code null})
41
     * @param <D>
42
     *         domain type
43
     * @param <R>
44
     *         range type
45
     *
46
     * @return a non-{@code null} object identical to the passed function, if it is non-{@code null}, or a function
47
     * object always returning {@code null} otherwise
48
     */
49
    public static <D, R> Function<D, ? extends @Nullable R> safeDefault(@Nullable Function<D, R> func) {
50
        if (func == null) {
×
NEW
51
            return x -> null;
×
52
        }
53
        return func;
×
54
    }
55

56
    /**
57
     * Returns a default function if the argument is {@code null}. The default function's {@link IntFunction#apply(int)
58
     * apply} method will always return {@code null}. If a non-{@code null} function is passed to this method, it is
59
     * returned as-is.
60
     *
61
     * @param func
62
     *         the function reference (may be {@code null})
63
     * @param <R>
64
     *         range type
65
     *
66
     * @return a non-{@code null} object identical to the passed function, if it is non-{@code null}, or a function
67
     * object always returning {@code null} otherwise
68
     */
69
    public static <R> IntFunction<? extends @Nullable R> safeDefault(@Nullable IntFunction<R> func) {
70
        if (func == null) {
×
NEW
71
            return i -> null;
×
72
        }
73
        return func;
×
74
    }
75

76
    /**
77
     * Returns a default function if the argument is {@code null}. The default function's {@link
78
     * BiIntFunction#apply(int, int) apply} method will always return {@code null}. If a non-{@code null} function is
79
     * passed to this method, it is returned as-is.
80
     *
81
     * @param func
82
     *         the function reference (may be {@code null})
83
     * @param <R>
84
     *         range type
85
     *
86
     * @return a non-{@code null} object identical to the passed function, if it is non-{@code null}, or a function
87
     * object always returning {@code null} otherwise
88
     */
89
    public static <R> BiIntFunction<? extends @Nullable R> safeDefault(@Nullable BiIntFunction<R> func) {
90
        if (func == null) {
×
91
            return (i1, i2) -> null;
×
92
        }
93
        return func;
×
94
    }
95

96
    public static <T> Predicate<T> safeToTrue(@Nullable Predicate<T> func) {
97
        if (func == null) {
×
NEW
98
            return x -> true;
×
99
        }
100
        return func;
×
101
    }
102

103
    public static <T> Predicate<T> safeToFalse(@Nullable Predicate<T> func) {
104
        if (func == null) {
×
NEW
105
            return x -> false;
×
106
        }
107
        return func;
×
108
    }
109

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