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