net.sixpointsix.carpo.common.extractor.method.DataElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carpo-common Show documentation
Show all versions of carpo-common Show documentation
Common until library for carpo
package net.sixpointsix.carpo.common.extractor.method;
import net.sixpointsix.carpo.common.extractor.PropertyExtractor;
import net.sixpointsix.carpo.common.model.PropertyHoldingEntity;
import java.util.function.Function;
/**
* A data element is a value to be pulled from a set of properties
*
*
* This class holds the header, property key and an extraction method to
* handle entities or lists
*
*
* @param Type of data being held
* @author Andrew Tarry
* @since 0.2.0
*/
public class DataElement {
private final String rowHeader;
private final String value;
private final Class propertyType;
private final Function extractor;
private final Integer index;
public DataElement(String rowHeader, String value) {
this(rowHeader, value, null, null, null);
}
public DataElement(String rowHeader, String value, Class propertyType, Function extractor, Integer index) {
this.rowHeader = rowHeader;
this.value = value;
this.propertyType = propertyType;
this.extractor = extractor;
this.index = index;
}
public String getRowHeader() {
return rowHeader;
}
/**
* Test if an extractor is string only
* @return true if the value is a primitive to be converted to a string
*/
public boolean isStringExtractor() {
return propertyType == null;
}
public String extract(PropertyHoldingEntity entity, PropertyExtractor propertyExtractor) {
if(isStringExtractor()) {
return propertyExtractor.getDatapoint(entity, value);
}
return propertyExtractor.getDatapoint(entity, value, propertyType, extractor, index);
}
}