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

org.simpleflatmapper.map.property.FieldMapperColumnDefinition 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.property;

import org.simpleflatmapper.map.mapper.ColumnDefinition;
import org.simpleflatmapper.map.FieldKey;
import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.reflect.getter.GetterFactory;
import org.simpleflatmapper.reflect.meta.PropertyMeta;
import org.simpleflatmapper.util.Function;
import org.simpleflatmapper.util.Predicate;

import java.lang.reflect.Type;

public class FieldMapperColumnDefinition> extends ColumnDefinition> {

    private static final FieldMapperColumnDefinition IDENTITY = new FieldMapperColumnDefinition(new Object[0]);

    public FieldMapperColumnDefinition(Object[] properties) {
        super(properties);
    }

    public static > Function> factory() {
        return new Function>() {
            @Override
            public ColumnDefinition apply(Object[] objects) {
                return FieldMapperColumnDefinition.of(objects);
            }
        };
    }

    public FieldMapper getCustomFieldMapper() {
        FieldMapperProperty prop = lookFor(FieldMapperProperty.class);
        if (prop != null) {
            return prop.getFieldMapper();
        }
        return null;
    }

    public FieldMapperColumnDefinition addGetter(Getter getter) {
        return add(new GetterProperty(getter));
    }
    public FieldMapperColumnDefinition addGetterFactory(GetterFactory getterFactory) {
        return add(new GetterFactoryProperty(getterFactory));

    }
    public FieldMapperColumnDefinition addFieldMapper(FieldMapper mapper){
        return add(new FieldMapperProperty(mapper));
    }

    @SuppressWarnings("unchecked")
    public static > FieldMapperColumnDefinition identity() {
        return IDENTITY;
    }

    public static > FieldMapperColumnDefinition compose(final FieldMapperColumnDefinition def1, final FieldMapperColumnDefinition def2) {
        return def1.compose(def2);
    }

    public static > FieldMapperColumnDefinition customFieldMapperDefinition(final FieldMapper mapper) {
        return FieldMapperColumnDefinition.identity().addFieldMapper(mapper);
    }

    public static > FieldMapperColumnDefinition customGetter(final Getter getter) {
        return FieldMapperColumnDefinition.identity().addGetter(getter);
    }

    public static > FieldMapperColumnDefinition customGetterFactory(final GetterFactory getterFactory) {
        return FieldMapperColumnDefinition.identity().addGetterFactory(getterFactory);
    }

    public static > FieldMapperColumnDefinition renameDefinition(final String name) {
        return FieldMapperColumnDefinition.identity().addRename(name);
    }

    public static > FieldMapperColumnDefinition ignoreDefinition() {
        return FieldMapperColumnDefinition.identity().addIgnore();
    }

    public static > FieldMapperColumnDefinition key() {
        return FieldMapperColumnDefinition.identity().addKey();
    }

    public static > FieldMapperColumnDefinition key(Predicate> predicate) {
        return FieldMapperColumnDefinition.identity().addKey(predicate);
    }

    @Override
    protected FieldMapperColumnDefinition newColumnDefinition(Object[] properties) {
        return FieldMapperColumnDefinition.of(properties);
    }

    @SuppressWarnings("unchecked")
    public static > FieldMapperColumnDefinition of(Object[] properties) {
        if (properties == null || properties.length == 0) {
            return IDENTITY;
        }
        return new FieldMapperColumnDefinition(properties);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy