org.sfm.reflect.meta.TuplePropertyFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.reflect.meta;
import org.sfm.reflect.InstantiatorDefinition;
import org.sfm.reflect.Parameter;
import org.sfm.reflect.TypeHelper;
import java.util.List;
@SuppressWarnings({ "unchecked", "rawtypes" })
public class TuplePropertyFinder extends AbstractIndexPropertyFinder {
private final List instantiatorDefinitions;
public TuplePropertyFinder(TupleClassMeta tupleClassMeta) {
super(tupleClassMeta);
this.instantiatorDefinitions = tupleClassMeta.getInstantiatorDefinitions();
for(int i = 0; i < tupleClassMeta.getTupleSize(); i++) {
elements.add(newIndexedElement(tupleClassMeta, i));
}
}
private IndexedElement newIndexedElement(TupleClassMeta tupleClassMeta, int i) {
ConstructorPropertyMeta prop =
newConstructorPropertyMeta(tupleClassMeta, i);
ClassMeta classMeta = tupleClassMeta.getReflectionService().getClassMeta(prop.getType());
return new IndexedElement(prop, classMeta);
}
private ConstructorPropertyMeta newConstructorPropertyMeta(TupleClassMeta tupleClassMeta, int i) {
Class tClass = TypeHelper.toClass(tupleClassMeta.getType());
final Parameter parameter = instantiatorDefinitions.get(0).getParameters()[i];
return new ConstructorPropertyMeta(parameter.getName(), tupleClassMeta.getReflectionService(),
parameter, tClass);
}
@Override
protected boolean isValidIndex(IndexedColumn indexedColumn) {
return indexedColumn.getIndexValue() < elements.size();
}
@Override
protected IndexedElement getIndexedElement(IndexedColumn indexedColumn) {
return elements.get(indexedColumn.getIndexValue());
}
protected IndexedColumn extrapolateIndex(PropertyNameMatcher propertyNameMatcher) {
for(int i = 0; i < elements.size(); i++) {
IndexedElement element = elements.get(i);
if (element.getElementClassMeta() != null) {
PropertyFinder> pf = element.getPropertyFinder();
PropertyMeta, Object> property = pf.findProperty(propertyNameMatcher);
if (property != null) {
if (!element.hasProperty(property)) {
return new IndexedColumn(i , propertyNameMatcher);
}
}
}
}
return null;
}
@Override
public List getEligibleInstantiatorDefinitions() {
return instantiatorDefinitions;
}
@Override
public ConstructorPropertyMeta findConstructor(InstantiatorDefinition instantiatorDefinition) {
return null;
}
}