-
Notifications
You must be signed in to change notification settings - Fork 242
/
OptionalPropertyContextImpl.java
51 lines (42 loc) · 1.63 KB
/
OptionalPropertyContextImpl.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.engine.cfg.impl;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import org.hibernate.search.engine.cfg.spi.DefaultedPropertyContext;
import org.hibernate.search.engine.cfg.spi.OptionalConfigurationProperty;
import org.hibernate.search.engine.cfg.spi.OptionalPropertyContext;
final class OptionalPropertyContextImpl<T> implements OptionalPropertyContext<T> {
private final String key;
private final Function<Object, Optional<T>> converter;
OptionalPropertyContextImpl(String key, Function<Object, Optional<T>> converter) {
this.key = key;
this.converter = converter;
}
@Override
public OptionalPropertyContext<List<T>> multivalued(Pattern separatorPattern) {
return new OptionalPropertyContextImpl<>(
key,
v -> ConvertUtils.convertMultiValue( separatorPattern, converter, v )
);
}
@Override
public DefaultedPropertyContext<T> withDefault(T defaultValue) {
return new DefaultedPropertyContextImpl<>( key, converter, () -> defaultValue );
}
@Override
public DefaultedPropertyContext<T> withDefault(Supplier<T> defaultValueSupplier) {
return new DefaultedPropertyContextImpl<>( key, converter, defaultValueSupplier );
}
@Override
public OptionalConfigurationProperty<T> build() {
return new OptionalConfigurationPropertyImpl<>( key, converter );
}
}