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

org.nasdanika.persistence.Choice Maven / Gradle / Ivy

There is a newer version: 2024.9.0
Show newest version
package org.nasdanika.persistence;

import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.function.Function;

import org.eclipse.emf.common.util.URI;
import org.nasdanika.common.ProgressMonitor;

/**
 * Choice delegates to an object factory returned by the selector function which takes config as an argument.
 * @author Pavel
 *
 * @param 
 */
public class Choice extends Attribute {
	
	private Function> selector;
	
	public Choice(
			Object key, 
			Function> selector,
			boolean isDefault, 
			boolean isConstructor, 
			boolean required, 
			T defaultValue, 
			String description, 
			Object... exclusiveWith) {
		super(key, isDefault, isConstructor, required, defaultValue, description, exclusiveWith);
		this.selector = selector;
	}
	
	@Override
	public T create(
			ObjectLoader loader, 
			Object config, 
			URI base,
			BiConsumer> resolver, 
			Collection markers,
			ProgressMonitor progressMonitor) {
		return selector.apply(config).create(loader, config, base, resolver, markers, progressMonitor);
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy