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

org.simpleflatmapper.reflect.BuilderInstantiatorDefinition Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.reflect;


import java.lang.reflect.Method;
import java.util.Map;

public final class BuilderInstantiatorDefinition implements InstantiatorDefinition {
	private final InstantiatorDefinition builderInstantiator;
	private final Map setters;
	private final Method buildMethod;

	public BuilderInstantiatorDefinition(InstantiatorDefinition builderInstantiator,
										 Map setters, Method buildMethod) {
		this.builderInstantiator = builderInstantiator;
		this.setters = setters;
		this.buildMethod = buildMethod;
	}


	@Override
	public Parameter[] getParameters() {

		Parameter[] parameters = new Parameter[setters.size()];

		int i = 0;
		for(Parameter p : setters.keySet()) {
			parameters[i++] = p;
		}
		return parameters;

	}

	public InstantiatorDefinition getBuilderInstantiator() {
		return builderInstantiator;
	}

	public Map getSetters() {
		return setters;
	}

	public Method getBuildMethod() {
		return buildMethod;
	}

	@Override
	public boolean hasParam(Parameter param) {
		return setters.containsKey(param);
	}

	@Override
	public Type getType() {
		return Type.BUILDER;
	}

	@Override
	public String getName() {
		return buildMethod.getDeclaringClass().getName();
	}

	public boolean isMutable() {
		for(Method m : setters.values()) {
			Class returnType = m.getReturnType();
			if (returnType != void.class && returnType != Void.class) {
				return false;
			}
		}
		return true;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy