org.sfm.querydsl.getter.EnumTupleOrdinalIndexedGetter 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.querydsl.getter;
import com.mysema.query.Tuple;
import org.sfm.querydsl.TupleElementKey;
import org.sfm.reflect.EnumHelper;
import org.sfm.reflect.Getter;
public final class EnumTupleOrdinalIndexedGetter> implements Getter {
private final int index;
private final Class> type;
private final E[] values;
public EnumTupleOrdinalIndexedGetter(TupleElementKey key, final Class enumType) {
this.index = key.getIndex();
this.type = key.getExpression().getType();
this.values = EnumHelper.getValues(enumType);
}
@Override
public E get(final Tuple target) throws Exception {
Number number = (Number) target.get(index, type);
if (number != null) {
return values[number.intValue()];
} else {
return null;
}
}
}