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

jaskell.sql.Coalesce Maven / Gradle / Ivy

Go to download

This is a utils library for java 8 project. It include parsec combinators and sql generators library.

There is a newer version: 2.9.2
Show newest version
package jaskell.sql;

import jaskell.script.Directive;
import jaskell.script.Parameter;

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

public class Coalesce implements Directive {
    List _args = new ArrayList<>();

    Coalesce(){
    }

    Coalesce(String names){
        _args.addAll(Arrays.stream(names.split(","))
                .map(String::trim)
                .map(Name::new)
                .collect(Collectors.toList()));
    }

    Coalesce(String... names){
        _args.addAll(Arrays.stream(names).map(Name::new).collect(Collectors.toList()));
    }

    Coalesce(Directive... directives){
        _args.addAll(Arrays.asList(directives));
    }

    public Coalesce coalesce(String names){
        _args.addAll(Arrays.stream(names.split(","))
                .map(String::trim)
                .map(Name::new)
                .collect(Collectors.toList()));
        return this;
    }

    public Coalesce coalesce(String ... names){
        _args.addAll(Arrays.stream(names).map(Name::new).collect(Collectors.toList()));
        return this;
    }

    public Coalesce coalesce(Directive ... directives){
        _args.addAll(Arrays.asList(directives));
        return this;
    }

    @Override
    public String script() {
        return String.format("COALESCE(%s)",
                _args.stream().map(Directive::script).collect(Collectors.joining(", ")));
    }

    @Override
    public List> parameters() {
        List> re = new ArrayList>();
        _args.forEach(p->re.addAll(p.parameters()));
        return re;
    }

    public Coalesce arg(Directive a){
        _args.add(a);
        return this;
    }

    public Coalesce args(Directive ... as){
        _args.addAll(Arrays.asList(as));
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy