All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.engine.cfg.impl.KeyContextImpl Maven / Gradle / Ivy

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 ) );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy