-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlankValueSource.java
More file actions
38 lines (31 loc) · 1.22 KB
/
BlankValueSource.java
File metadata and controls
38 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package it.aboutbits.springboot.testing.validation.source;
import it.aboutbits.springboot.testing.validation.core.ValueSource;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
@NullMarked
public class BlankValueSource implements ValueSource {
private static final Map<Class<?>, Function<Object[], Stream<?>>> TYPE_SOURCES = new HashMap<>();
static {
TYPE_SOURCES.put(
String.class,
(Object[] args) -> Stream.of("", " ", " ", "\t", "\r", "\n", "\r\n")
);
}
@SuppressWarnings("unused")
public static void registerType(Class<?> type, Function<Object[], Stream<?>> source) {
TYPE_SOURCES.put(type, source);
}
@Override
@SuppressWarnings("unchecked")
public <T> Stream<@Nullable T> values(Class<T> propertyClass, Object... args) {
var sourceFunction = TYPE_SOURCES.get(propertyClass);
if (sourceFunction != null) {
return (Stream<@Nullable T>) sourceFunction.apply(args);
}
throw new IllegalArgumentException("Property class not supported!");
}
}