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

org.simpleflatmapper.map.mapper.UnorderedJoinMapper Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.map.mapper;

import org.simpleflatmapper.map.ConsumerErrorHandler;
import org.simpleflatmapper.map.ContextualSourceFieldMapper;
import org.simpleflatmapper.map.ContextualSourceMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.context.MappingContextFactory;
import org.simpleflatmapper.map.context.impl.BreakDetector;
import org.simpleflatmapper.map.context.impl.BreakDetectorMappingContext;
import org.simpleflatmapper.util.Enumerable;
import org.simpleflatmapper.util.UnaryFactory;

public class UnorderedJoinMapper extends AbstractEnumerableDelegateMapper {

    private final ContextualSourceFieldMapper mapper;
    private final MappingContextFactory mappingContextFactory;
    private final UnaryFactory> factory;

    public UnorderedJoinMapper(ContextualSourceFieldMapper mapper, ConsumerErrorHandler errorHandler, MappingContextFactory mappingContextFactory, UnaryFactory> factory) {
        super(errorHandler);
        this.mapper = mapper;
        this.mappingContextFactory = mappingContextFactory;
        this.factory = factory;
    }


    @Override
    protected final ContextualSourceMapper getMapper(ROW source) {
        return mapper;
    }

    @Override
    public final Enumerable enumerate(ROWS source) throws EX {
        BreakDetectorMappingContext mappingContext = (BreakDetectorMappingContext) mappingContextFactory.newContext();
        BreakDetector rootDetector = mappingContext.getRootDetector();
        if (!rootDetector.hasKeyDefinition()) {
            throw new IllegalStateException("No key definitions");
        }
        return new UnorderedJoinMapperEnumerable(mapper, mappingContext, enumerateRows(source), rootDetector);
    }

    private Enumerable enumerateRows(ROWS source) {
        return factory.newInstance(source);
    }

    protected MappingContextFactory getMappingContextFactory() {
        return mappingContextFactory;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy