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

jaskell.sql.Func 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 Func extends Literal {
    List _args = new ArrayList<>();

    public Func(String name, Directive ... parameters){
        super(name);
        _args.addAll(Arrays.asList(parameters));
    }

    @Override
    public String script() {
        return String.format("%s(%s)",
                super.script(),
                _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 Func arg(Directive a){
        _args.add(a);
        return this;
    }

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

    public static Func max(Directive argument){
        return new Func("MAX", argument);
    }

    public static Func min(Directive argument){
        return new Func("MIN", argument);
    }

    public static Func avg(Directive argument){
        return new Func("AVGs", argument);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy