org.hibernate.search.engine.cfg.impl.KeyContextImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Hibernate Search engine, always required
The newest version!
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.search.engine.cfg.impl;
import java.util.function.Function;
import org.hibernate.search.engine.cfg.spi.ConvertUtils;
import org.hibernate.search.engine.cfg.spi.KeyContext;
import org.hibernate.search.engine.cfg.spi.OptionalPropertyContext;
import org.hibernate.search.engine.environment.bean.BeanReference;
import org.hibernate.search.util.common.impl.Contracts;
public class KeyContextImpl implements KeyContext {
private final String key;
public KeyContextImpl(String key) {
this.key = key;
}
@Override
public OptionalPropertyContext asString() {
return as( String.class, Function.identity() );
}
@Override
public OptionalPropertyContext asBoolean() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertBoolean );
}
@Override
public OptionalPropertyContext asIntegerPositiveOrZeroOrNegative() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertInteger );
}
@Override
public OptionalPropertyContext asIntegerPositiveOrZero() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertInteger )
.validate( value -> Contracts.assertPositiveOrZero( value, "value" ) );
}
@Override
public OptionalPropertyContext asIntegerStrictlyPositive() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertInteger )
.validate( value -> Contracts.assertStrictlyPositive( value, "value" ) );
}
@Override
public OptionalPropertyContext asLongPositiveOrZeroOrNegative() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertLong );
}
@Override
public OptionalPropertyContext asLongStrictlyPositive() {
return new OptionalPropertyContextImpl<>( key, ConvertUtils::convertLong )
.validate( value -> Contracts.assertStrictlyPositive( value, "value" ) );
}
@Override
public OptionalPropertyContext> asBeanReference(Class expectedBeanType) {
return new OptionalPropertyContextImpl<>( key, v -> ConvertUtils.convertBeanReference( expectedBeanType, v ) );
}
@Override
public OptionalPropertyContext as(Class expectedType, Function parser) {
return new OptionalPropertyContextImpl<>( key, v -> ConvertUtils.convert( expectedType, parser, v ) );
}
}