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

org.simpleflatmapper.map.context.impl.KeyDefinitionBuilder 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.context.impl;

import org.simpleflatmapper.map.context.KeyAndPredicate;
import org.simpleflatmapper.map.context.KeyDefinition;
import org.simpleflatmapper.map.context.KeySourceGetter;

import java.lang.reflect.Array;
import java.util.List;

public class KeyDefinitionBuilder {
    private final KeySourceGetter keySourceGetter;
    private final List> keyAndPredicates;
    private final int index;

    public KeyDefinitionBuilder(List> keyAndPredicates, KeySourceGetter keySourceGetter, int index) {
        this.keyAndPredicates = keyAndPredicates;
        this.keySourceGetter = keySourceGetter;
        this.index = index;
    }


    public KeyDefinitionBuilder asChild(int currentIndex) {
        return new KeyDefinitionBuilder(keyAndPredicates,  keySourceGetter, currentIndex);
    }

    public static  KeyDefinition[] toKeyDefinitions(KeyDefinitionBuilder[] siblings) {
        KeyDefinition[] keyDefinitions = new KeyDefinition[siblings.length];
        for(KeyDefinitionBuilder builder : siblings) {
            KeyDefinition keyDefinition = new KeyDefinition(toArray(builder.keyAndPredicates), builder.keySourceGetter, builder.index);
            keyDefinitions[builder.index]= keyDefinition;
        }
        return keyDefinitions;
    }

    private static  K[] toArray(List keys) {
        if (keys.size() == 0) return null;
        else return keys.toArray((K[]) Array.newInstance(keys.get(0).getClass(), 0));
    }

    public List> getKeyAndPredicates() {
        return keyAndPredicates;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy