/
KeyContextImpl.java
52 lines (41 loc) · 1.61 KB
/
KeyContextImpl.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
52
/*
* 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.function.Function;
import org.hibernate.search.engine.cfg.spi.KeyContext;
import org.hibernate.search.engine.cfg.spi.OptionalPropertyContext;
import org.hibernate.search.engine.environment.bean.BeanReference;
public class KeyContextImpl implements KeyContext {
private final String key;
public KeyContextImpl(String key) {
this.key = key;
}
@Override
public OptionalPropertyContext<String> asString() {
return as( String.class, Function.identity() );
}
@Override
public OptionalPropertyContext<Boolean> asBoolean() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertBoolean );
}
@Override
public OptionalPropertyContext<Integer> asInteger() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertInteger );
}
@Override
public OptionalPropertyContext<Long> asLong() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertLong );
}
@Override
public OptionalPropertyContext<BeanReference> asBeanReference(Class<?> expectedType) {
return new OptionalPropertyContextImpl<>( key, v -> ConvertUtils.convertBeanReference( expectedType, v ) );
}
@Override
public <T> OptionalPropertyContext<T> as(Class<T> expectedType, Function<String, T> parser) {
return new OptionalPropertyContextImpl<>( key, v -> ConvertUtils.convert( expectedType, parser, v ) );
}
}