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

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

There is a newer version: 8.0.0.Alpha1
Show 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.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

import org.hibernate.search.engine.cfg.ConfigurationPropertySource;
import org.hibernate.search.engine.cfg.spi.OptionalConfigurationProperty;

final class OptionalConfigurationPropertyImpl extends AbstractConfigurationProperty>
		implements OptionalConfigurationProperty {

	private final Function converter;

	OptionalConfigurationPropertyImpl(String key, Function converter) {
		super( key );
		this.converter = converter;
	}

	@Override
	public  Optional getAndMap(ConfigurationPropertySource source, Function transform) {
		return getAndTransform( source, optional -> optional.map( transform ) );
	}

	@Override
	public T getOrThrow(ConfigurationPropertySource source, Supplier exceptionSupplier) {
		return getAndTransform( source, optional -> optional.orElseThrow( exceptionSupplier ) );
	}

	@Override
	public  R getAndMapOrThrow(ConfigurationPropertySource source, Function transform,
			Supplier exceptionSupplier) {
		return getAndTransform( source, optional -> optional.map( transform ).orElseThrow( exceptionSupplier ) );
	}

	@Override
	 R convert(Optional rawValue, Function, R> transform) {
		return transform.apply( rawValue.map( converter ) );
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy