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

org.hibernate.search.engine.environment.bean.CompositeBeanHolder 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.environment.bean;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.search.util.common.impl.Closer;
import org.hibernate.search.util.common.impl.CollectionHelper;

final class CompositeBeanHolder implements BeanHolder> {

	private final List> dependencies;
	private final List instances;

	CompositeBeanHolder(List> dependencies) {
		this.dependencies = dependencies;
		List tmp = new ArrayList<>( dependencies.size() );
		for ( BeanHolder delegate : dependencies ) {
			tmp.add( delegate.get() );
		}
		this.instances = CollectionHelper.toImmutableList( tmp );
	}

	@Override
	public String toString() {
		return getClass().getSimpleName() + "["
				+ "instances=" + instances
				+ ", dependencies=" + dependencies
				+ "]";
	}

	@Override
	public List get() {
		return instances;
	}

	@Override
	public void close() {
		try ( Closer closer = new Closer<>() ) {
			closer.pushAll( BeanHolder::close, dependencies );
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy