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

com.github.nill14.utils.init.impl.ChainingPropertyResolver Maven / Gradle / Ivy

package com.github.nill14.utils.init.impl;

import com.github.nill14.utils.init.api.IParameterType;
import com.github.nill14.utils.init.api.IPropertyResolver;
import com.google.common.collect.ImmutableList;

@SuppressWarnings("serial")
public class ChainingPropertyResolver implements IPropertyResolver {
	
	private final ImmutableList items;
	
	public ChainingPropertyResolver(IPropertyResolver... resolvers) {
		items = ImmutableList.copyOf(resolvers);
	}
	
	public ChainingPropertyResolver(ImmutableList resolvers) {
		items = resolvers;
	}
	
	public ChainingPropertyResolver with(IPropertyResolver extraResolver) {
		ImmutableList.Builder builder = ImmutableList.builder();
		return new ChainingPropertyResolver(builder.add(extraResolver).addAll(items).build());
	}
	
	
	@Override
	public Object resolve(Object pojo, IParameterType type) {
		for (IPropertyResolver resolver : items) {
			Object result = resolver.resolve(pojo, type);
			if (result != null) {
				return result;
			}
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy