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

com.github.randyp.jdbj.ListBindingsBuilder Maven / Gradle / Ivy

There is a newer version: 0.1.9
Show newest version
package com.github.randyp.jdbj;

import com.github.randyp.jdbj.lambda.Binding;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public interface ListBindingsBuilder extends DefaultValueBindingsBuilder {

    E bindList(String name, List bindings);

    default E bindLongs(String name, long... xs){
        if (xs == null) {
            throw new IllegalArgumentException("xs cannot be null - consider using bindArray");
        }
        final List bindings = new ArrayList<>();
        for (final long x : xs) {
            bindings.add(pc -> pc.setLong(x));
        }

        return bindList(name, bindings);
    }

    default E bindStrings(String name, List xs){
        if (xs == null) {
            throw new IllegalArgumentException("xs cannot be null - consider using bindArray");
        }
        final Function createBinding = x -> (Binding) preparedColumn -> preparedColumn.setString(x);
        final List bindings = xs.stream().map(createBinding).collect(Collectors.toList());
        return bindList(name, bindings);
    }

    default E bindStrings(String name, String... xs){
        if (xs == null) {
            throw new IllegalArgumentException("xs cannot be null - consider using bindArray");
        }
        return bindStrings(name, Arrays.asList(xs));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy