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

com.github.skjolber.stcsv.projection.SetterValueProjection Maven / Gradle / Ivy

There is a newer version: 1.0.25
Show newest version
package com.github.skjolber.stcsv.projection;

import org.objectweb.asm.MethodVisitor;

import com.github.skjolber.stcsv.AbstractCsvMapper;
import com.github.skjolber.stcsv.builder.CsvBuilderException;

public abstract class SetterValueProjection implements ValueProjection {

	protected static final int currentOffsetIndex = AbstractCsvMapper.VAR_CURRENT_OFFSET;
	protected static final int currentArrayIndex = AbstractCsvMapper.VAR_CURRENT_ARRAY;
	protected static final int objectIndex = AbstractCsvMapper.VAR_OBJECT;
	protected static final int startIndex = AbstractCsvMapper.VAR_START;
	protected static final int rangeIndex = AbstractCsvMapper.VAR_RANGE;
	protected static final int intermediateIndex = AbstractCsvMapper.VAR_INTERMEDIATE_OBJECT;

	public static SetterValueProjection newInstance(Class setterClass, String setterName, String mappedClassInternalName) {
		if(setterClass == String.class) {
			return new ObjectSetterValueProjection(setterName, mappedClassInternalName, "java/lang/String");
		} else if(setterClass == int.class) {
			return new PrimitiveSetterValueProjection(setterName, mappedClassInternalName, "com/github/skjolber/stcsv/column/bi/IntCsvColumnValueConsumer", "parseInt", 'I');
		} else if(setterClass == long.class) {
			return new PrimitiveSetterValueProjection(setterName, mappedClassInternalName, "com/github/skjolber/stcsv/column/bi/LongCsvColumnValueConsumer", "parseLong", 'J');
		} else if(setterClass == boolean.class) {
			return new PrimitiveSetterValueProjection(setterName, mappedClassInternalName, "com/github/skjolber/stcsv/column/bi/BooleanCsvColumnValueConsumer", "parseBoolean", 'Z');
		} else if(setterClass == double.class) {
			return new PrimitiveSetterValueProjection(setterName, mappedClassInternalName, "com/github/skjolber/stcsv/column/bi/DoubleCsvColumnValueConsumer", "parseDouble", 'D');
		} else {
			throw new CsvBuilderException("No setter for type " + setterClass.getName());
		}
	}
	
	protected final String setterName;
	protected final String mappedClassInternalName;
	
	public SetterValueProjection(String setterName, String mappedClassInternalName) {
		this.setterName = setterName;
		this.mappedClassInternalName = mappedClassInternalName;
	}
	
	public abstract void write(MethodVisitor mv, String subClassInternalName, int endIndex);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy