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

org.sfm.map.impl.AbstractColumnDefinitionProvider 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: 1.10.3
Show newest version
package org.sfm.map.impl;


import org.sfm.map.ColumnDefinition;
import org.sfm.map.ColumnDefinitionProvider;
import org.sfm.map.FieldKey;
import org.sfm.tuples.Tuple2;
import org.sfm.utils.Predicate;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractColumnDefinitionProvider, K extends FieldKey> implements ColumnDefinitionProvider {

    protected final List, C>> definitions;

    public AbstractColumnDefinitionProvider() {
        definitions = new ArrayList, C>>();
    }
    public AbstractColumnDefinitionProvider(List, C>> definitions) {
        this.definitions = definitions;
    }

    public void addColumnDefinition(Predicate predicate, C definition) {
        definitions.add(new Tuple2, C>(predicate, definition));
    }

    @Override
    public C getColumnDefinition(K key) {
        C definition = identity();

        for(Tuple2, C> def : definitions) {
            if (def.first().test(key)) {
                definition = compose(definition, def.second());
            }
        }

        return  definition;
    }

    protected abstract C compose(C definition, C second);
    protected abstract C identity();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy