org.simpleflatmapper.map.mapper.JoinMapperEnumerable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.map.mapper;
import org.simpleflatmapper.map.SourceFieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.util.Enumerable;
import org.simpleflatmapper.util.ErrorHelper;
public class JoinMapperEnumerable implements Enumerable {
private final SourceFieldMapper mapper;
private final MappingContext super S> mappingContext;
private final Enumerable sourceEnumerable;
private T currentValue;
private T nextValue;
public JoinMapperEnumerable(SourceFieldMapper mapper,
MappingContext super S> mappingContext,
Enumerable sourceEnumerable) {
this.mapper = mapper;
this.mappingContext = mappingContext;
this.sourceEnumerable = sourceEnumerable;
}
@Override
public boolean next() {
try {
currentValue = nextValue;
nextValue = null;
while (sourceEnumerable.next()) {
S source = sourceEnumerable.currentValue();
if (mappingContext.broke(source)) {
if (currentValue == null) {
currentValue = mapper.map(source, mappingContext);
} else {
nextValue = mapper.map(source, mappingContext);
return true;
}
} else {
mapper.mapTo(source, currentValue, mappingContext);
}
}
return currentValue != null;
} catch (Exception e) {
ErrorHelper.rethrow(e);
return false;
}
}
@Override
public T currentValue() {
return currentValue;
}
@Override
public String toString() {
return "JoinJdbcMapper{" +
"jdbcMapper=" + mapper +
'}';
}
}